Thymeleaf既没有BindingResult,也没有用于bean名称的普通目标对象

huangapple go评论103阅读模式
英文:

Thymeleaf Neither BindingResult nor plain target object for bean name

问题

以下是翻译好的部分:

  1. 我在index.html中点击按钮切换视图到**new.html**时遇到了这个错误:
  2. 2020-07-27 00:42:15.813 ERROR 5616 --- [nio-8080-exec-2] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8080-exec-2] 处理模板时出现异常 "new": 在模板解析期间发生错误 (模板: "class path resource [templates/new.html]")
  3. org.thymeleaf.exceptions.TemplateInputException: 在模板解析期间发生错误 (模板: "class path resource [templates/new.html]")
  4. at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  5. ...
  6. Caused by: org.thymeleaf.exceptions.TemplateProcessingException: 在模板解析期间发生错误 (模板: "class path resource [templates/new.html]")
  7. at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:117) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  8. ...
  9. Caused by: java.lang.IllegalStateException: 请求属性中既没有BindingResult,也没有名为'bankDetailDto'的纯目标对象
  10. at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:153) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  11. ...
  12. 2020-07-27 00:42:15.816 ERROR 5616 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : 在没有请求属性'bankDetailDto'可用的情况下,Servlet [dispatcherServlet] 的服务() 在路径为[]的上下文中抛出异常 [请求处理失败;嵌套异常是 org.thymeleaf.exceptions.TemplateInputException: 在模板解析期间发生错误 (模板: "class path resource [templates/new.html]")]
  13. java.lang.IllegalStateException: 在没有请求属性'bankDetailDto'可用的情况下
  14. at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:153) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  15. ...

index.html

  1. <!DOCTYPE html>
  2. <html lang="en" xmlns:th="http://www.thymeleaf.org">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport"
  6. content="width=device-width, initial-scale=1, shrink-to-fit=no">
  7. <title>Data</title>
  8. <!--Bootstrap 4-->
  9. <link rel="stylesheet"
  10. href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
  11. </head>
  12. <body>
  13. <div class="container py-5">
  14. <div class="row">
  15. <div class="col-6 mx-auto">
  16. <h1>Upload CSV</h1>
  17. <form method="POST" th:action="@{/upload}"
  18. enctype="multipart/form-data">
  19. <!-- 表单内容 -->
  20. </form>
  21. </div>
  22. </div>
  23. </div>
  24. </body>
  25. </html>
英文:

I'm getting this error when I click a button in index.html to change the view to new.html

  1. . ____ _ __ _ _
  2. /\\ / ___&#39;_ __ _ _(_)_ __ __ _ \ \ \ \
  3. ( ( )\___ | &#39;_ | &#39;_| | &#39;_ \/ _` | \ \ \ \
  4. \\/ ___)| |_)| | | | | || (_| | ) ) ) )
  5. &#39; |____| .__|_| |_|_| |_\__, | / / / /
  6. =========|_|==============|___/=/_/_/_/
  7. :: Spring Boot :: (v2.3.1.RELEASE)
  8. 2020-07-27 00:41:57.902 INFO 5616 --- [ restartedMain] c.i.maxoptra.app.Example1Application : Starting Example1Application on SneakyRicki with PID 5616 (C:\Users\Ric\Desktop\wks-maxoptra\maxoptra-project\Example1\target\classes started by Ric in C:\Users\Ric\Desktop\wks-maxoptra\maxoptra-project\Example1)
  9. 2020-07-27 00:41:57.905 INFO 5616 --- [ restartedMain] c.i.maxoptra.app.Example1Application : No active profile set, falling back to default profiles: default
  10. 2020-07-27 00:41:57.955 INFO 5616 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set &#39;spring.devtools.add-properties&#39; to &#39;false&#39; to disable
  11. 2020-07-27 00:41:57.955 INFO 5616 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the &#39;logging.level.web&#39; property to &#39;DEBUG&#39;
  12. 2020-07-27 00:41:59.418 INFO 5616 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
  13. 2020-07-27 00:41:59.426 INFO 5616 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
  14. 2020-07-27 00:41:59.426 INFO 5616 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.36]
  15. 2020-07-27 00:41:59.493 INFO 5616 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
  16. 2020-07-27 00:41:59.494 INFO 5616 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1539 ms
  17. 2020-07-27 00:41:59.656 INFO 5616 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService &#39;applicationTaskExecutor&#39;
  18. 2020-07-27 00:41:59.730 INFO 5616 --- [ restartedMain] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page template: index
  19. 2020-07-27 00:41:59.843 INFO 5616 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
  20. 2020-07-27 00:41:59.878 INFO 5616 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path &#39;&#39;
  21. 2020-07-27 00:41:59.888 INFO 5616 --- [ restartedMain] c.i.maxoptra.app.Example1Application : Started Example1Application in 2.307 seconds (JVM running for 3.723)
  22. 2020-07-27 00:42:10.518 INFO 5616 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet &#39;dispatcherServlet&#39;
  23. 2020-07-27 00:42:10.518 INFO 5616 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet &#39;dispatcherServlet&#39;
  24. 2020-07-27 00:42:10.526 INFO 5616 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 7 ms
  25. 2020-07-27 00:42:15.813 ERROR 5616 --- [nio-8080-exec-2] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8080-exec-2] Exception processing template &quot;new&quot;: An error happened during template parsing (template: &quot;class path resource [templates/new.html]&quot;)
  26. org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: &quot;class path resource [templates/new.html]&quot;)
  27. at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  28. at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  29. at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:666) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  30. at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  31. at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  32. at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:362) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  33. at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:189) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  34. at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1373) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  35. at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1118) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  36. at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1057) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  37. at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  38. at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  39. at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  40. at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  41. at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  42. at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  43. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  44. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  45. at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.36.jar:9.0.36]
  46. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  47. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  48. at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  49. at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  50. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  51. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  52. at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  53. at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  54. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  55. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  56. at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  57. at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  58. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  59. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  60. at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  61. at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  62. at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  63. at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  64. at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  65. at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  66. at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  67. at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  68. at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  69. at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  70. at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  71. at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  72. at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
  73. at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
  74. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  75. at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
  76. Caused by: org.attoparser.ParseException: Error during execution of processor &#39;org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor&#39; (template: &quot;new&quot; - line 30, col 26)
  77. at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
  78. at org.attoparser.MarkupParser.parse(MarkupParser.java:257) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
  79. at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  80. ... 48 common frames omitted
  81. Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor &#39;org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor&#39; (template: &quot;new&quot; - line 30, col 26)
  82. at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:117) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  83. at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  84. at org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  85. at org.thymeleaf.engine.ProcessorTemplateHandler.handleStandaloneElement(ProcessorTemplateHandler.java:918) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  86. at org.thymeleaf.engine.TemplateHandlerAdapterMarkupHandler.handleStandaloneElementEnd(TemplateHandlerAdapterMarkupHandler.java:260) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  87. at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler$InlineMarkupAdapterPreProcessorHandler.handleStandaloneElementEnd(InlinedOutputExpressionMarkupHandler.java:256) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  88. at org.thymeleaf.standard.inline.OutputExpressionInlinePreProcessorHandler.handleStandaloneElementEnd(OutputExpressionInlinePreProcessorHandler.java:169) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  89. at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler.handleStandaloneElementEnd(InlinedOutputExpressionMarkupHandler.java:104) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  90. at org.attoparser.HtmlVoidElement.handleOpenElementEnd(HtmlVoidElement.java:92) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
  91. at org.attoparser.HtmlMarkupHandler.handleOpenElementEnd(HtmlMarkupHandler.java:297) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
  92. at org.attoparser.MarkupEventProcessorHandler.handleOpenElementEnd(MarkupEventProcessorHandler.java:402) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
  93. at org.attoparser.ParsingElementMarkupUtil.parseOpenElement(ParsingElementMarkupUtil.java:159) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
  94. at org.attoparser.MarkupParser.parseBuffer(MarkupParser.java:710) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
  95. at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:301) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
  96. ... 50 common frames omitted
  97. Caused by: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name &#39;bankDetailDto&#39; available as request attribute
  98. at org.springframework.web.servlet.support.BindStatus.&lt;init&gt;(BindStatus.java:153) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  99. at org.springframework.web.servlet.support.RequestContext.getBindStatus(RequestContext.java:903) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  100. at org.thymeleaf.spring5.context.webmvc.SpringWebMvcThymeleafRequestContext.getBindStatus(SpringWebMvcThymeleafRequestContext.java:227) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  101. at org.thymeleaf.spring5.util.FieldUtils.getBindStatusFromParsedExpression(FieldUtils.java:306) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  102. at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:253) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  103. at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:227) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  104. at org.thymeleaf.spring5.processor.AbstractSpringFieldTagProcessor.doProcess(AbstractSpringFieldTagProcessor.java:174) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  105. at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  106. ... 63 common frames omitted
  107. 2020-07-27 00:42:15.816 ERROR 5616 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: &quot;class path resource [templates/new.html]&quot;)] with root cause
  108. java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name &#39;bankDetailDto&#39; available as request attribute
  109. at org.springframework.web.servlet.support.BindStatus.&lt;init&gt;(BindStatus.java:153) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  110. at org.springframework.web.servlet.support.RequestContext.getBindStatus(RequestContext.java:903) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  111. at org.thymeleaf.spring5.context.webmvc.SpringWebMvcThymeleafRequestContext.getBindStatus(SpringWebMvcThymeleafRequestContext.java:227) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  112. at org.thymeleaf.spring5.util.FieldUtils.getBindStatusFromParsedExpression(FieldUtils.java:306) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  113. at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:253) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  114. at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:227) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  115. at org.thymeleaf.spring5.processor.AbstractSpringFieldTagProcessor.doProcess(AbstractSpringFieldTagProcessor.java:174) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  116. at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  117. at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  118. at org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  119. at org.thymeleaf.engine.ProcessorTemplateHandler.handleStandaloneElement(ProcessorTemplateHandler.java:918) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  120. at org.thymeleaf.engine.TemplateHandlerAdapterMarkupHandler.handleStandaloneElementEnd(TemplateHandlerAdapterMarkupHandler.java:260) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  121. at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler$InlineMarkupAdapterPreProcessorHandler.handleStandaloneElementEnd(InlinedOutputExpressionMarkupHandler.java:256) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  122. at org.thymeleaf.standard.inline.OutputExpressionInlinePreProcessorHandler.handleStandaloneElementEnd(OutputExpressionInlinePreProcessorHandler.java:169) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  123. at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler.handleStandaloneElementEnd(InlinedOutputExpressionMarkupHandler.java:104) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  124. at org.attoparser.HtmlVoidElement.handleOpenElementEnd(HtmlVoidElement.java:92) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
  125. at org.attoparser.HtmlMarkupHandler.handleOpenElementEnd(HtmlMarkupHandler.java:297) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
  126. at org.attoparser.MarkupEventProcessorHandler.handleOpenElementEnd(MarkupEventProcessorHandler.java:402) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
  127. at org.attoparser.ParsingElementMarkupUtil.parseOpenElement(ParsingElementMarkupUtil.java:159) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
  128. at org.attoparser.MarkupParser.parseBuffer(MarkupParser.java:710) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
  129. at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:301) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
  130. at org.attoparser.MarkupParser.parse(MarkupParser.java:257) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
  131. at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  132. at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  133. at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:666) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  134. at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  135. at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  136. at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:362) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  137. at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:189) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
  138. at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1373) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  139. at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1118) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  140. at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1057) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  141. at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  142. at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  143. at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  144. at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  145. at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
  146. at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  147. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  148. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  149. at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.36.jar:9.0.36]
  150. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  151. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
  152. at

Index.html

  1. &lt;!DOCTYPE html&gt;
  2. &lt;html lang=&quot;en&quot; xmlns:th=&quot;http://www.thymeleaf.org&quot;&gt;
  3. &lt;head&gt;
  4. &lt;meta charset=&quot;UTF-8&quot;&gt;
  5. &lt;meta name=&quot;viewport&quot;
  6. content=&quot;width=device-width, initial-scale=1, shrink-to-fit=no&quot;&gt;
  7. &lt;title&gt;Data&lt;/title&gt;
  8. &lt;!--Bootstrap 4--&gt;
  9. &lt;link rel=&quot;stylesheet&quot;
  10. href=&quot;https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css&quot;&gt;
  11. &lt;/head&gt;
  12. &lt;body&gt;
  13. &lt;div class=&quot;container py-5&quot;&gt;
  14. &lt;div class=&quot;row&quot;&gt;
  15. &lt;div class=&quot;col-6 mx-auto&quot;&gt;
  16. &lt;h1&gt;Upload CSV&lt;/h1&gt;
  17. &lt;form method=&quot;POST&quot; th:action=&quot;@{/upload}&quot;
  18. enctype=&quot;multipart/form-data&quot;&gt;
  19. &lt;div class=&quot;form-group mt-3&quot;&gt;
  20. &lt;label for=&quot;file&quot;&gt;Select a CSV file&lt;/label&gt; &lt;input type=&quot;file&quot;
  21. name=&quot;file&quot; class=&quot;form-control-file&quot; id=&quot;file&quot; accept=&quot;.csv&quot;&gt;
  22. &lt;/div&gt;
  23. &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;
  24. th:disabled=&quot;${disable eq 0}&quot;&gt;Import Data&lt;/button&gt;
  25. &lt;/form&gt;
  26. &lt;/div&gt;
  27. &lt;/div&gt;
  28. &lt;/div&gt;
  29. &lt;div class=&quot;col-6 mx-auto&quot;&gt;
  30. &lt;h2&gt;Add Details&lt;/h2&gt;
  31. &lt;a href=&quot;/addForm&quot; class=&quot;btn btn-primary&quot;&gt; Add Student&lt;/a&gt;
  32. &lt;div class=&quot;container py-5&quot;&gt;
  33. &lt;div class=&quot;row&quot;&gt;
  34. &lt;div class=&quot;col-10 mx-auto&quot;&gt;
  35. &lt;h1&gt;Table With Data&lt;/h1&gt;
  36. &lt;!--display error if any--&gt;
  37. &lt;!--display users list--&gt;
  38. &lt;table class=&quot;table table-striped&quot;&gt;
  39. &lt;thead&gt;
  40. &lt;tr&gt;
  41. &lt;th scope=&quot;col&quot;&gt;#&lt;/th&gt;
  42. &lt;th scope=&quot;col&quot;&gt;Fo&lt;/th&gt;
  43. &lt;th scope=&quot;col&quot;&gt;Fo1&lt;/th&gt;
  44. &lt;th scope=&quot;col&quot;&gt;fo2&lt;/th&gt;
  45. &lt;/tr&gt;
  46. &lt;/thead&gt;
  47. &lt;tbody&gt;
  48. &lt;tr th:each=&quot;dataDto, i : ${details}&quot;&gt;
  49. &lt;th scope=&quot;row&quot; th:text=&quot;${i.index + 1}&quot;&gt;&lt;/th&gt;
  50. &lt;td th:text=&quot;${dataDto.fo}&quot;&gt;&lt;/td&gt;
  51. &lt;td th:text=&quot;${dataDto.fo1}&quot;&gt;&lt;/td&gt;
  52. &lt;td th:text=&quot;${dataDto.fo2}&quot;&gt;&lt;/td&gt;
  53. &lt;/tr&gt;
  54. &lt;/tbody&gt;
  55. &lt;/table&gt;
  56. &lt;/div&gt;
  57. &lt;/div&gt;
  58. &lt;/div&gt;
  59. &lt;/div&gt;
  60. &lt;/body&gt;
  61. &lt;/html&gt;

the error occurs when I change the view by clicking on

  1. &lt;h2&gt;Add Details&lt;/h2&gt;
  2. &lt;a href=&quot;/addForm&quot; class=&quot;btn btn-primary&quot;&gt; Add &lt;/a&gt;

I'm sure this is not the problem because of the tests I've been running.

Controller

  1. @GetMapping(&quot;/addForm&quot;)
  2. public String showAddUpForm() {
  3. return &quot;new&quot;;
  4. }

all i do is return the view of the new.html

New.html

  1. &lt;!DOCTYPE html&gt;
  2. &lt;html xmlns:th=&quot;http://www.thymeleaf.org&quot;&gt;
  3. &lt;head&gt;
  4. &lt;meta charset=&quot;utf-8&quot;&gt;
  5. &lt;meta http-equiv=&quot;x-ua-compatible&quot; content=&quot;ie=edge&quot;&gt;
  6. &lt;title&gt;Add User&lt;/title&gt;
  7. &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
  8. &lt;/head&gt;
  9. &lt;body&gt;
  10. &lt;h3&gt;Add&lt;/h3&gt;
  11. &lt;div class=&quot;card&quot;&gt;
  12. &lt;div class=&quot;card-body&quot;&gt;
  13. &lt;div class=&quot;col-md-10&quot;&gt;
  14. &lt;form action=&quot;#&quot; method=&quot;post&quot; th:object=&quot;${dataDto}&quot;
  15. th:action=&quot;@{/save}&quot;&gt;
  16. &lt;div class=&quot;row&quot;&gt;
  17. &lt;input type=&quot;text&quot; th:field=&quot;*{fo}&quot; class=&quot;form-control&quot;&gt;
  18. &lt;input type=&quot;text&quot; th:field=&quot;*{fo1}&quot; class=&quot;form-control&quot;&gt;
  19. &lt;input type=&quot;text&quot; th:field=&quot;*{fo2}&quot; class=&quot;form-control&quot;&gt;
  20. &lt;/div&gt;
  21. &lt;/form&gt;
  22. &lt;/div&gt;
  23. &lt;/div&gt;
  24. &lt;/div&gt;
  25. &lt;/body&gt;
  26. &lt;/html&gt;

is just a simple form to insert data
im gessing here is the problem but i dont know where this is the method that controls the form

New Controller

  1. @RequestMapping(value = &quot;/save&quot;, method = RequestMethod.POST)
  2. public String save(DataDto dataDto , Model model, BindingResult bindingResult) {
  3. if (bindingResult.hasErrors()) {
  4. return &quot;new&quot;;
  5. }
  6. model.addAttribute(&quot;dataDto &quot;, dataDto );
  7. return &quot;redirect:index&quot;;
  8. }

Pojo

  1. public class DataDto {
  2. private String fo;
  3. private String fo1;
  4. private String fo2;
  5. public DataDto () {
  6. }

I've tried this article but it seems to be a old version of Thymeleaf

Neither BindingResult nor plain target object available as request attribute

thanks for any suggestions

答案1

得分: 1

Sure, here's the translated code snippet:

  1. @GetMapping("/addForm")
  2. public String showAddUpForm() {
  3. model.addAttribute("dataDto", new DataDto());
  4. return "new";
  5. }
英文:

In /addForm controller send dataDto as model object

  1. @GetMapping(&quot;/addForm&quot;)
  2. public String showAddUpForm() {
  3. model.addAttribute(&quot;dataDto&quot;, new DataDto())
  4. return &quot;new&quot;;
  5. }

huangapple
  • 本文由 发表于 2020年7月27日 08:29:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/63107196.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定