Home > Back-end >  SpringBoot Thymeleaf problems
SpringBoot Thymeleaf problems

Time:09-23

The front desk code
(XXX. HTML)


<meta charset="utf-8" & gt;
Insert the title here

<body>





The background code
Package com. Example. The demo;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

The import com. Example. Bean. The user;

@ Controller
Public class Test {

@ RequestMapping ("/test ")
Public String login Model (Model) {
Return "XXX".

}
@ RequestMapping ("/list ")
Public String user (@ ModelAttribute (value="https://bbs.csdn.net/topics/user") the user u, Model Model, it the req) {
String name=u.g etName ();
Name=the req. GetAttribute (" name "). The toString ();
Model. The addAttribute (" name ", name);
Return "login";

}
}
The data binding beans
Package com. Example. Bean;

The import javax.mail. Validation. Constraints. NotEmpty;

Public class user {

@ NotEmpty (message="user name cannot be empty")
private String name;


Public String getPwd () {
Return the PWD.
}

Public void setPwd (String PWD) {
Enclosing the PWD=PWD;
}

Public String getName () {
return name;
}

Public void elegantly-named setName (String name) {
This. Name=name;
}

@ NotEmpty (message="password cannot be empty")
Private String PWD.

}
Error message
Org. Thymeleaf. Exceptions. TemplateInputException: An error happened during the template parsing (template: "class path resource/templates/XXX. HTML")
Org. Attoparser. ParseException: Error during the execution of processor '. Org. Thymeleaf spring5. Processor. SpringInputGeneralFieldTagProcessor '(template: "XXX" - the line 10, 20) col
Org. Thymeleaf. Exceptions. TemplateProcessingException: Error during the execution of processor '. Org. Thymeleaf spring5. Processor. SpringInputGeneralFieldTagProcessor '(template: "XXX" - the line 10, 20) col
Java. Lang. An IllegalStateException: Neither BindingResult nor plain target object for bean name 'user' available as request attribute
Neither BindingResult nor plain target object for bean name 'user' available as request attribute
ERROR 4672 - O.A.C.C.C. [nio - 8080 - exec - 1]. [[. [/] [dispatcherServlet] : Servlet. The service () for the Servlet [dispatcherServlet] in context with the path [] threw the exception [Request processing failed; nested exception is org. Thymeleaf. Exceptions. TemplateInputException: An ERROR happened during the template parsing (template: "class path resource/templates/XXX. HTML")] with root cause

I'm through
http://localhost:8080/test to XXX. There is a form form inside the HTML of the XXX I had meant to be submitted through the form data to the background, but now as long as into the XXX. HTML error problem seems to be in & lt; Input type="text" th: field="* {name}"/& gt; In th: field="* {name}" I found a lot of information on the Internet but most of them were not aimed at me for the status of the trouble bosses guide younger brother thank you very much

CodePudding user response:

Values should be like this when ${user. The name}

CodePudding user response:

You put th: object="${user}" the form form to pick out individual set a div will you input wrapped up, or in accordance with the above figure, give it a try

CodePudding user response:

reference 1/f, distant miss reply:
value should be like this when ${user. The name}

I am not the values I am binding and the background

CodePudding user response:

refer to the second floor William_Wei007 response:
you put th: object="${user}" the form form to pick out individual set a div will you input wrapped up, or in accordance with the above figure, try

So can't and backend bean binding

CodePudding user response:

Mistake is to tell you, I can't find you want to take the value of the thymeleaf, so I cannot resolve this page, please check whether to accept the correct thymeleaf parameters

CodePudding user response:

To @ RestController

CodePudding user response:

Your user USES the controller is @ ModelAttribute (value="https://bbs.csdn.net/topics/user") the user u user object, and pass in your form form is * {name}, try using ${user. The name}

CodePudding user response:

! The ${name}

CodePudding user response:

The controller to change the:
@ RequestMapping ("/test ")
Public String login Model (Model) {
Model. The addAttribute (" user ", the new user ());
Return "XXX".

}

CodePudding user response:

Your page XXX, but there is no assignment model of execution of the test method, so the ${user} is null

CodePudding user response:


///
(the template: "XXX" - the line 10, 20) col
///
This has been pointed out that the wrong location.nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related