报错:EL1007E: Property or field 'name' cannot be found on null

SpringBoot integrated development experience to do the wrong thymeleaf

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field ‘name’ cannot be found on null


  • Details :( fragment)
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

  • The reason:
    static pages using the expression thymeleaf receiving object background controller transmission (data), but the background did not pass over this object, or pass over an empty object, all error, which means looking not see this field (of course object no where's field).

  • solution:

  1. In yml profile adds:

    mybatis:
      configuration:
        call-setters-on-nulls: true #设置返回字段不为空,前端不报错
    
  2. Background controller layer, and then when the jump page with an empty object in the past on the line. E.g:

 /**
     * 静态页面跳转
     * @return
     */
    @GetMapping("types/input")
    public String typesInput(Model model) {
        model.addAttribute("type", new Type());
        return "/admin/types-input";
    }

  • Front-end code shows:
<!--表单提交-->
        <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>
Published 33 original articles · won praise 1 · views 1416

Guess you like

Origin blog.csdn.net/smileKutper/article/details/104061455