我正在尝试开发一个带有Spring Boot的项目,该项目将被员工用于休假或休假,我也将crud操作用作Rest Web服务,但是我遇到了一个问题:产生错误的百里香的字段: org.thymeleaf.exceptions.TemplateProcessingException:执行处理器“ org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor”时出错(模板:“ admin / home”-第81行,col 54) 在下面,您可以找到控制器的代码和html
@GetMapping("/application")
public String applicationForm(Model model) {
model.addAttribute("application", new Application());
return "home";
}
@RequestMapping(value="/application", method=RequestMethod.POST)
public String applicationSubmit(@ModelAttribute Application application, Model model, BindingResult bindingResult, MultipartHttpServletRequest request) throws IOException {
if (bindingResult.hasErrors())
return "home";
model.addAttribute("application", application);
return "result";
}
<form action="#" th:action="@{'createApplication'}" th:object="${application}" method="post">
Description: <input type="text" id="description" th:field="*{description}"/>
From Date: <input type="text" id="from" th:field="*{fromDate}" />
To Date: <input type="text" id="to" th:field="*{toDate}"/>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
答案 0 :(得分:0)
使用此应用程序类。当无法从百里香访问这些字段,它们不是公共字段或没有公共访问权限(获取程序/设置程序)时,将发生此异常。
public class Application {
private String description;
private String fromDate;
private String toDate;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getFromDate() {
return fromDate;
}
public void setFromDate(String fromDate) {
this.fromDate = fromDate;
}
public String getToDate() {
return toDate;
}
public void setToDate(String toDate) {
this.toDate = toDate;
}
}