Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使Thymeleaf th:field使用Lombok生成的布尔getter_Java_Spring_Thymeleaf_Lombok - Fatal编程技术网

Java 使Thymeleaf th:field使用Lombok生成的布尔getter

Java 使Thymeleaf th:field使用Lombok生成的布尔getter,java,spring,thymeleaf,lombok,Java,Spring,Thymeleaf,Lombok,我正在用Thymeleaf创建一个简单的Spring MVC应用程序。由于懒惰,我也在使用龙目。我有一个简单的DTO,往返于Thymeleaf: @Getter @Setter @NoArgsConstructor @AllArgsConstructor public class TypeDto { private Long id; private String title; private boolean isActive; } 但我在尝试访问页面时遇到以下错误:

我正在用Thymeleaf创建一个简单的Spring MVC应用程序。由于懒惰,我也在使用龙目。我有一个简单的DTO,往返于Thymeleaf:

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class TypeDto {

    private Long id;
    private String title;
    private boolean isActive;
}
但我在尝试访问页面时遇到以下错误:
Bean属性“isActive”不可读或具有无效的getter方法:getter的返回类型是否与setter的参数类型匹配?
它在以下代码段中失败:

    <td><input type="checkbox" th:field="*{isActive}"/></td>


如果我在DTO和Thymeleaf模板中将
isActive
重命名为
active
,它工作得很好,所以我猜Thymeleaf正在尝试使用
getIsActive
读取属性,而OFC不存在。尽管我一直在寻找简单的解决方案,但有没有一种方法可以让布尔值保持活动状态,并且仍然可以让Thymeleaf工作?

在键入此问题时,我发现如果我将Thymeleaf模板中的属性匹配器本身更改为活动状态,一切都按预期工作,无需在DTO级别及以下更改任何内容。

键入此问题时,我发现如果我将Thymeleaf模板中的属性匹配器本身更改为活动,则一切都按预期工作,无需在DTO级别及以下更改任何内容。

从字段名中删除“是”

<td><input type="checkbox" th:field="*{Active}"/></td>

从字段名中删除“is”

<td><input type="checkbox" th:field="*{Active}"/></td>


你在发布表单时没有遇到问题吗?没有。只要我只有一个属性匹配
active
,它就会像一个符咒一样工作,你在发布表单时没有遇到问题吗?没有。只要我只有一个属性匹配
active
,它就会像一个符咒一样工作,