无法使用 th:field of thymeleaf [英] Not able to use th:field of thymeleaf
问题描述
我正在尝试使用 spring boot 开发一个项目,员工将使用它来申请休假或休假,我也在使用 crud 操作作为 Rest Web 服务,但是我遇到了问题:产生错误的百里香叶字段:org.thymeleaf.exceptions.TemplateProcessingException:在执行处理器 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' 期间出错(模板:admin/home"-第 81 行,第 54 列)下面是控制器的代码和html
I'm trying to develop a project with spring boot which will be used by employees to applicate for day off or vacations, i am also using crud operations as Rest web services, but i'm having a problem with the th:field of thymeleaf which generates the error: org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "admin/home" - line 81, col 54) Below you find the code of the controller and the 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>
推荐答案
使用此应用程序类.当字段无法从 thymeleaf 访问时,会发生此异常,要么它们不是公共的,要么没有公共访问权限(getter/setter).
Use this application class. This exception occurs when the fields are not accessible from thymeleaf, either they are not public or do not have public access (getters / setters).
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;
}
}
这篇关于无法使用 th:field of thymeleaf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!