ThymeLeaf:不等于 th:if 中的表达式 [英] ThymeLeaf: Not Equal expression in th:if

查看:120
本文介绍了ThymeLeaf:不等于 th:if 中的表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对 ThymeLeaf 非常陌生,但在我正在从事的项目中遇到了问题.日志中出现以下错误:

评估 SpringEL 表达式的异常:!searchResults.results.empty"

看看有问题的代码:

我认为感叹号 (!) 的位置不正确.我试过了:

但同样的错误评估.有人可以帮助我如何取消支票吗?

解决方案

假设根据您粘贴的代码,您想要实现一个检查,其中 Thymeleaf 检查对象中的空值.为此:---

 

还有,或者,您可以做的是 - 检查您的控制器本身是否对象为空或没有任何值并在您的 html 页面上发送响应,然后根据 Thymeleaf 上的响应进行检查,如下所示:- - -

1.) 你的控制器 :--

 List ls =//来自你DAO的一些数据如果(ls.isEmpty()){model.addAttribute("response", "NoData");}别的{model.addAttribute("响应", ls);}

然后在你的 Thymeleaf 上:- - -

未找到数据</th:block>

Very new to ThymeLeaf, but have encountered a problem on a project I am working on. Getting the following error in the logs:

Exception evaluating SpringEL expression: "!searchResults.results.empty"

Looking at the offending code it is:

<th:block th:if="${!searchResults.results.empty}">

I assume that the placement of the exclamation mark (!) is incorrect. I have tried:

<th:block th:if="${not searchResults.results.empty}">

But same error evaluating. Can someone help me as to how to negate a check?

解决方案

Assuming from the code you've pasted, you want to implement a check where Thymeleaf checks for empty value in an Object. For that :---

<div th:if= "${searchResults.results != null}">

OR

 <div th:if= "${searchResults.results != ''}">

Also, Alternatively What you can do is-- check on your Controller itself whether the object is empty or doesn't have any Value and send the response on your html page and then check as per that response on Thymeleaf, Like this :- - -

1.) Your controller :--

    List ls = //some data from you DAO
    if(ls.isEmpty()){
         model.addAttribute("response", "NoData");
    }else{
         model.addAttribute("response", ls);
    }

Then on your Thymeleaf :- - -

<th:block th:if="${response=='NoData'}"> No Data Found </th:block>

这篇关于ThymeLeaf:不等于 th:if 中的表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆