SpringBoot集成thymeleaf做开发遇到的错误
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field ‘name’ cannot be found on null
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates//admin/types-input.html]")
Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "name" (template: "/admin/types-input" - line 59, col 72)
at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.attoparser.MarkupParser.parse(MarkupParser.java:257) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
... 53 common frames omitted
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "name" (template: "/admin/types-input" - line 59, col 72)
at
org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'name' cannot be found on null
at
-
在yml配置文件添加:
mybatis:
configuration:
call-setters-on-nulls: true #设置返回字段不为空,前端不报错
-
后台controller层,再跳转页面时带一个空对象过去就行。例如:
@GetMapping("types/input")
public String typesInput(Model model) {
model.addAttribute("type", new Type());
return "/admin/types-input";
}
<!--表单提交-->
<form action="#" method="post" th:action="@{/admin/types}" th:object="${type}" class="ui form">
<!--分类名称-->
<div class="field">
<div class="ui left labeled input">
<label class="ui teal basic label">分类名称</label>
<input type="text" name="name" placeholder="请输入分类" th:value="*{name}">
</div>
</div>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)