我正在IntelliJ上使用spring boot和thymeleaf编写一个简短的Web表单应用程序,但似乎在html文件中,模型中的所有字段都无法解析.这是我的代码:
控制器类:
@Controller
public class IndexController{
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index(){
return "index";
}
@RequestMapping(value="/", method = RequestMethod.POST)
public String addNewPost(@Valid Post post, BindingResult bindingResult, Model model){
if(bindingResult.hasErrors()){
return "index";
}
model.addAttribute("title",post.getTitle());
model.addAttribute("content",post.getContent());
return "hello";
}
}
Run Code Online (Sandbox Code Playgroud)
型号类:
public class Post {
@Size(min=4, max=35)
private String title;
@Size(min=30, max=1000)
private String content;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
} …Run Code Online (Sandbox Code Playgroud)