安装了Lombok插件。使用IntelliJ 15。模型的结构显示了getter和setter,但我从Thymeleaf获得以下错误:
错误:
bean类[com.blog.domain.Post]的无效属性'postTitle':Bean属性'postTitle'不可读取或具有无效的getter方法:getter的返回类型是否与setter的参数类型匹配?
该模型:
@Entity
public @Data class Post {
@Id
@GeneratedValue
private Long id;
@NotEmpty
private String postTitle;
@NotNull
@ManyToOne
private Author postAuthor;
@NotNull
@Temporal(TemporalType.DATE)
private Date postDate;
@Column(columnDefinition = "TEXT")
private String postTeaser;
@Column(columnDefinition = "TEXT")
private String postBody;
}
控制器方法加载表单:
@GetMapping("/create")
public String postForm(Post post, Model model) {
model.addAttribute("authors", authorService.getAllAuthors());
return "postform";
}
发生错误的领域:
<input id="postTitle" type="text" th:field="*{postTitle}" />
有什么想法,我做错了什么?手动添加getter和setter可以解决问题。Lombok在这里做了什么导致出现错误?
<p th:text="'postTitle: ' + ${post.postTitle}" ></p>
并在控制器的 GET 方法中使用model.addAttribute("post", new Post());
进行检查。这很奇怪,难道你没有任何不寻常的 lombok 配置吗? - Enigo