Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.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
使用Thymeleaf(Java)读取布尔值时出现问题_Java_Html_Thymeleaf - Fatal编程技术网

使用Thymeleaf(Java)读取布尔值时出现问题

使用Thymeleaf(Java)读取布尔值时出现问题,java,html,thymeleaf,Java,Html,Thymeleaf,我用Thymeleaf从对象读取布尔值时遇到问题。这是代码中的外观: <tr th:each="item : ${individualTransactions}"> <td><span th:text="${item.itemName}"> </span></td>

我用Thymeleaf从对象读取布尔值时遇到问题。这是代码中的外观:

                    <tr th:each="item : ${individualTransactions}">
                        <td><span th:text="${item.itemName}"> </span></td>
                        <td><span th:text="${item.itemDescription}"> </span></td>
                        <td><span th:text="${item.itemCost}"> </span></td>
                        <td>
                            <div th:switch="${item.isUsed}">
                                <p th:case="true"> USED </p>
                                <p th:case="false"> USE </p>
                            </div>
                        </td>
                    </tr>

已使用

使用

这是消息:EL1008E:在类型为“xxx.entity.Transaction”的对象上找不到属性或字段“isUsed”-可能不是公共的或无效的

我不知道问题是在语法上还是在访问属性时。访问其他属性没有问题。

此外,对于布尔属性,我们允许getter方法匹配模式:

public boolean is<PropertyName>();
public boolean is();

您的属性名是
used
,而不是
isUsed

我更改了getter和setter名称-默认名称是getUsed和setUsed,我将它们更改为getIsUsed和setIsUsed,现在就可以使用了。@krzysiekcr您应该将模板更改为
${item.used}
。一开始我不理解您的意思,当然您是对的。