【发布时间】:2020-02-18 13:43:19
【问题描述】:
我正在使用 Thymeleaf 创建一个简单的 Spring MVC 应用程序。懒惰,我也在使用 Lombok。我有一个简单的 DTO,往返于 Thymeleaf:
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class TypeDto {
private Long id;
private String title;
private boolean isActive;
}
但我在尝试访问页面时遇到以下错误:
Bean property 'isActive' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter? 在以下 Thymeleaf sn-p 中失败:
<td><input type="checkbox" th:field="*{isActive}"/></td>
如果我在 DTO 和 Thymeleaf 模板中将 isActive 重命名为 active 它工作正常,所以我猜 Thymeleaf 正在尝试使用 getIsActive 读取属性,而 OFC 不存在。尽管我很喜欢简单的解决方案,但有没有办法将布尔值保留为 isActive 并仍然使 Thymeleaf 工作?
【问题讨论】:
标签: java spring thymeleaf lombok