Spring boot 除非在thymeleaf引擎中给出相同的重新运行

Spring boot 除非在thymeleaf引擎中给出相同的重新运行,spring-boot,if-statement,spring-data-jpa,thymeleaf,Spring Boot,If Statement,Spring Data Jpa,Thymeleaf,我试图在thymeleaf引擎中为列表中对象的属性之一执行if语句 我的目的是如果somoLetu.hsecondrarding==null我应该看到没有二读的文本,但如果没有,我应该看到二读的文本。但输出在两种情况下都显示二读文本,无论是否为空,我做错了什么 下面是我如何在masomo.html文件中的thymeleaf中执行此操作 <div th:each="somoLetu : ${masomoYote}" class="containe

我试图在thymeleaf引擎中为列表中对象的属性之一执行if语句

我的目的是如果somoLetu.hsecondrarding==null我应该看到没有二读的文本,但如果没有,我应该看到二读的文本。但输出在两种情况下都显示二读文本,无论是否为空,我做错了什么

下面是我如何在masomo.html文件中的thymeleaf中执行此操作

        <div th:each="somoLetu : ${masomoYote}" class="container my-5">

        <h1 th:text= "${somoLetu.date}"></h1>
        <h1 th:text= "${somoLetu.familiaName}"></h1>
        <h1 th:text= "${somoLetu.kanda}"></h1>
  
        <div th:if= "${somoLetu.hSecondReading == null}" ><h1>No Second Reading</h1></div>
        <div th:unless= "${somoLetu.hSecondReading == null}" ><h1>Second Reading</h1>  <h1 th:text="${somoLetu.hSecondReading}"></h1></div>
       </div>
        </div>
这是我在控制器类中获取所有列表的方法

@Autowired
 private MisaleRepository misaleRepository;
 @GetMapping("/masomo")
    public String masomoAngalia(Model model){
        model.addAttribute("masomoYote", misaleRepository.findAll() );
   
        return "masomo";
    
}



        

hs经济恐惧的值是多少?您确定它是
null
且不是空字符串吗?这不是一回事

您应该知道变量是否为空(或可以为空)。如果您不注意这一点,Java中可能会出现更严重的错误


也许可以使用Thymeleaf的
isEmpty
helper:
${{strings.isEmpty(somoLetu.hsecondrarding)}

什么是
hsecondrarding
的值?您确定它是
null
且不是空字符串吗?这不是一回事。可能使用Thymeleaf的
isEmpty
helper:
${{strings.isEmpty(somoLetu.hsecondrarding)}
哇,我已经按照建议试用了Thymeleaf的isEmpty helper:${{strings.isEmpty(somoLetu.hsecondrarding)},效果很好。非常感谢@RoToRa@RoToRa把它作为答案贴出来,这样我就可以接受了。谢谢
@Autowired
 private MisaleRepository misaleRepository;
 @GetMapping("/masomo")
    public String masomoAngalia(Model model){
        model.addAttribute("masomoYote", misaleRepository.findAll() );
   
        return "masomo";
    
}