Thymeleaf处理URL中的外键,用于PUT请求的操作

时间:2018-06-12 18:00:25

标签: spring-boot java-ee thymeleaf

我正在使用thymeleaf作为引擎视图运行Springboot项目

我在控制器中为@ModelAttribute命令的PUT请求的参数传递外键时遇到问题:

<form th:action="@{/order/{clientid}/(clientid=${order.client.clientid}"th:method="put" action="put" th:object="${order}">

这里是我关注的链接:https://www.thymeleaf.org/doc/articles/standardurlsyntax.html

错误显示:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/order.html]")
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
    org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:883)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:651)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.servlet.resource.ResourceUrlEncodingFilter.doFilterInternal(ResourceUrlEncodingFilter.java:53)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:86)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:74)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
root cause
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/order.html]")
    org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241)
    org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100)
    org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:667)
    org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1087)
    org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1061)
    org.thymeleaf.spring4.view.ThymeleafView.renderFragment(ThymeleafView.java:335)
    org.thymeleaf.spring4.view.ThymeleafView.render(ThymeleafView.java:189)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1257)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:883)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:651)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.servlet.resource.ResourceUrlEncodingFilter.doFilterInternal(ResourceUrlEncodingFilter.java:53)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:86)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:74)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
root cause
org.attoparser.ParseException: Exception evaluating SpringEL expression: "order.client.clientid" (template: "order" - line 21, col 32)
    org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393)
    org.attoparser.MarkupParser.parse(MarkupParser.java:257)
    org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230)
    org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100)
    org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:667)
    org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1087)
    org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1061)
    org.thymeleaf.spring4.view.ThymeleafView.renderFragment(ThymeleafView.java:335)
    org.thymeleaf.spring4.view.ThymeleafView.render(ThymeleafView.java:189)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1257)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:883)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:651)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.servlet.resource.ResourceUrlEncodingFilter.doFilterInternal(ResourceUrlEncodingFilter.java:53)

1 个答案:

答案 0 :(得分:0)

尝试添加)}

<form th:action="@{/order/{clientid}/(clientid=${order.client.clientid})}" th:method="put" action="put" th:object="${order}">

您的表单标记不包含相同数量的(){}也是如此。