Thymeleaf 无法识别 Lombok getter 和 setter

问题描述 投票:0回答:2

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 在这里做什么破坏了它?

java intellij-idea spring-boot thymeleaf lombok
2个回答
0
投票

我使用名为“isEnabled”的布尔值遇到了这个问题。将其重命名为“启用”有效。但不确定其原因。


0
投票

如果您从某个地方获取帖子,请确保它作为类而不是可选对象给出。

© www.soinside.com 2019 - 2024. All rights reserved.