Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "index" – line 93, col 69)

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

Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "index" - line 93, col 69)

问题

以下是您提供的内容的翻译:

我在主页上有一个注册表单,但当我试图加载主页时出现错误。

在处理器 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (模板:"index" - 第93行,第69列) 执行期间发生错误。

以下是我的表单。

<form method="post" th:action="@{/register}" th:object="${registerRequestModel}">
    <div class="md-form">
        <i class="fas fa-user prefix white-text active"></i>
        <input type="text" id="form3" name="name" th:field="*{name}" class="white-text form-control">
        <label for="form3" class="active">Your name</label>
    </div>
    <div class="md-form">
        <i class="fas fa-envelope prefix white-text active"></i>
        <input type="email" id="form2" name="email" th:field="*{email}" class="white-text form-control">
        <label for="form2" class="active">Your email</label>
    </div>
    <div class="md-form">
        <i class="fas fa-lock prefix white-text active"></i>
        <input type="password" id="form4" name="password" th:field="*{password}" class="white-text form-control">
        <label for="form4">Your password</label>
    </div>
    <div class="text-center mt-4">
        <button type="submit" class="btn btn-indigo">Sign up</button>
    </div>
</form>

我的控制器。

@RestController
public class RequestHandler {
	
	private AbstractRepository service;
	
	@Autowired
	public RequestHandler(AbstractRepository service) {
		this.service=service;
	}
	
	@GetMapping("/")
	public ModelAndView home(ModelAndView mv) {
		mv.addObject("registerRequestModel", new RegisterRequestModel());
		mv.setViewName("index");
		return mv;
	}

	@PostMapping("/register")
	public String registerUser(RegisterRequestModel registerRequestModel) {
		service.registerCollaborators(registerRequestModel);
		return "User Registered";
	}
}

当我在 localhost:8080 上运行此应用程序时,会出现上述错误。当我移除 th:field="*{name}" 后,它正常工作。

以下是我的模型类。我几乎尝试了所有方法,但它不起作用。

public class RegisterRequestModel {
	
	private String name;
	private String email;
	private String password;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Override
	public String toString() {
		return "RegisterRequestModel [name=" + name + ", email=" + email + ", password=" + password + "]";
	}

}

以下是所请求的完整堆栈跟踪。

org.thymeleaf.exceptions.TemplateProcessingException: 在处理器 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (模板:"index" - 第93行,第69列) 执行期间发生错误。
    at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:117) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    ...
Caused by: java.lang.IllegalStateException: 既没有绑定结果,也没有用作请求属性的纯目标对象,用作 bean 名称 'registerRequestModel'
    at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:153) ~[spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    ...
英文:

I have a register form on homepage and when I am trying to load up the home page I get the error.

Error during execution of processor &#39;org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor&#39; (template: &quot;index&quot; - line 93, col 69)

Here is my form.

&lt;form method=&quot;post&quot; th:action=&quot;@{/register}&quot; th:object=&quot;${registerRequestModel}&quot;&gt;
                        &lt;div class=&quot;md-form&quot;&gt;
                          &lt;i class=&quot;fas fa-user prefix white-text active&quot;&gt;&lt;/i&gt;
                          &lt;input type=&quot;text&quot; id=&quot;form3&quot; name=&quot;name&quot; th:field=&quot;*{name}&quot; class=&quot;white-text form-control&quot;&gt;
                          &lt;label for=&quot;form3&quot; class=&quot;active&quot;&gt;Your name&lt;/label&gt;
                        &lt;/div&gt;
                        &lt;div class=&quot;md-form&quot;&gt;
                          &lt;i class=&quot;fas fa-envelope prefix white-text active&quot;&gt;&lt;/i&gt;
                          &lt;input type=&quot;email&quot; id=&quot;form2&quot; name=&quot;email&quot; th:field=&quot;*{email}&quot; class=&quot;white-text form-control&quot;&gt;
                          &lt;label for=&quot;form2&quot; class=&quot;active&quot;&gt;Your email&lt;/label&gt;
                        &lt;/div&gt;
                        &lt;div class=&quot;md-form&quot;&gt;
                          &lt;i class=&quot;fas fa-lock prefix white-text active&quot;&gt;&lt;/i&gt;
                          &lt;input type=&quot;password&quot; id=&quot;form4&quot; name=&quot;password&quot; th:field=&quot;*{password}&quot; class=&quot;white-text form-control&quot;&gt;
                          &lt;label for=&quot;form4&quot;&gt;Your password&lt;/label&gt;
                        &lt;/div&gt;
                        &lt;div class=&quot;text-center mt-4&quot;&gt;
                          &lt;button type=&quot;submit&quot; class=&quot;btn btn-indigo&quot;&gt;Sign up&lt;/button&gt;
                      &lt;/form&gt; 

My Controller.

@RestController
public class RequestHandler {
	
	private AbstractRepository service;
	
	@Autowired
	public RequestHandler(AbstractRepository service) {
		this.service=service;
	}
	
	@GetMapping(&quot;/&quot;)
	public ModelAndView home(ModelAndView mv) {
		mv.addObject(&quot;registerRequestModel&quot;, new RegisterRequestModel());
		mv.setViewName(&quot;index&quot;);
		return mv;
	}

	@PostMapping(&quot;/register&quot;)
	public String registerUser(RegisterRequestModel registerRequestModel) {
		service.registerCollaborators(registerRequestModel);
		return &quot;User Registered&quot;;
	}
}

When I run this application on localhost:8080 Then it gives the above error. When I remove th:field=&quot;*{name}&quot; then it works perfectly

Here is my model class. I have almost tried everything but it doesn't work

public class RegisterRequestModel {
	
	private String name;
	private String email;
	private String password;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Override
	public String toString() {
		return &quot;RegisterRequestModel [name=&quot; + name + &quot;, email=&quot; + email + &quot;, password=&quot; + password + &quot;]&quot;;
	}

}

Here is the full stack trace as requested.

org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor &#39;org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor&#39; (template: &quot;index&quot; - line 93, col 69)
at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:117) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.engine.ProcessorTemplateHandler.handleStandaloneElement(ProcessorTemplateHandler.java:918) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.engine.StandaloneElementTag.beHandled(StandaloneElementTag.java:228) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.engine.TemplateModel.process(TemplateModel.java:136) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:661) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:362) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:189) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1373) [spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1118) [spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1057) [spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) [spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) [spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) [spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) [spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-embed-websocket-9.0.33.jar:9.0.33]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) [spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) [spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) [spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1594) [tomcat-embed-core-9.0.33.jar:9.0.33]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.33.jar:9.0.33]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_181]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_181]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.33.jar:9.0.33]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_181]
Caused by: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name &#39;registerRequestModel&#39; available as request attribute
at org.springframework.web.servlet.support.BindStatus.&lt;init&gt;(BindStatus.java:153) ~[spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.web.servlet.support.RequestContext.getBindStatus(RequestContext.java:903) ~[spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.thymeleaf.spring5.context.webmvc.SpringWebMvcThymeleafRequestContext.getBindStatus(SpringWebMvcThymeleafRequestContext.java:227) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.spring5.util.FieldUtils.getBindStatusFromParsedExpression(FieldUtils.java:306) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:253) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:227) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.spring5.processor.AbstractSpringFieldTagProcessor.doProcess(AbstractSpringFieldTagProcessor.java:174) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
... 52 more

答案1

得分: 1

你忘记了@ModelAttribute注解。将你的@PostMapping方法修改为以下形式:

@PostMapping("/register")
public String registerUser(@ModelAttribute RegisterRequestModel registerRequestModel) {
    //   service.registerCollaborators(registerRequestModel); 这段代码是做什么的?
    return view; // 在这里你应该返回一个模板的名称。
}
英文:

You forgot the @ModelAttribute annotation. Make your @PostMapping method read like this:

@PostMapping(&quot;/register&quot;)
public String registerUser(@ModelAttribute RegisterRequestModel registerRequestModel) {
//   service.registerCollaborators(registerRequestModel); what does this do?
return view; // you should return the name of a template here.
}

答案2

得分: -1

从您的代码中的这一行开始:

<input type="text" id="form3" name="name" th:field="*{name}" class="white-text form-control">

特别是 th:field="*{name}" 部分是导致错误的原因。我曾遇到类似的问题,将其中的 th 删除后问题得到解决。

英文:

From this line of your code:

                      &lt;input type=&quot;text&quot; id=&quot;form3&quot; name=&quot;name&quot; th:field=&quot;*{name}&quot; class=&quot;white-text form-control&quot;&gt;

specifically the th:field=&quot;*{name}&quot;is what is causing the error. I had a similar problem and i remove the thfrom it and it worked.

huangapple
  • 本文由 发表于 2020年4月5日 15:50:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/61039575.html
匿名

发表评论

匿名网友

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

确定