Thymeleaf与Lombok getter和setter不兼容

时间:2017-02-07 13:22:37

标签: spring-mvc thymeleaf lombok

错误

org.springframework.beans.NotReadablePropertyException: Invalid property 'mytemplate' of bean class [at.test.Mytemplate]: Bean property 'mytemplate' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

Cause: org.thymeleaf.exceptions.TemplateProcessingException Error during execution of processor 'org.thymeleaf.spring4.processor.attr.SpringInputGeneralFieldAttrProcessor'

@Data
@Builder
public class Mytemplate{

    String name;

}

HTML

<form id="myform" class="form-horizontal" data-toggle="validator" method="POST" role="form" th:action="@{'/save'}" th:object="${mytemplate}">
    <input type="text" class="form-control" th:field="*{mytemplate.name}" required="required"/>
</form>

知道我为什么会收到这个错误吗?为什么我不能使用带百里香的lombok?

1 个答案:

答案 0 :(得分:1)

错误说明Bean property 'mytemplate' is not readable,它没有说name属性 - at.test.Mytemplate本身的任何内容被用作百里香的根,以启动变量解析。

所以只需引用name而不是mytemplate.name

<input type="text" class="form-control" th:field="*{name}" required="required"/>