Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.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
Spring boot 如何在Thymeleaf中使用多个If-else语句来更改表行颜色_Spring Boot_Thymeleaf - Fatal编程技术网

Spring boot 如何在Thymeleaf中使用多个If-else语句来更改表行颜色

Spring boot 如何在Thymeleaf中使用多个If-else语句来更改表行颜色,spring-boot,thymeleaf,Spring Boot,Thymeleaf,我正在尝试根据Thymeleaf中的值更改行的颜色。我做了一个if和else语句,效果很好。但当我添加else if语句时,它不起作用如果balls>0则fff,否则如果balls>和&mobile>0则5af716,否则eee。 我如何解决这个问题 工作版本 <tr th:each="country : ${data}" th:style="${country.balls} > 0 ? 'background-color: #fff' :'background-co

我正在尝试根据Thymeleaf中的值更改行的颜色。我做了一个if和else语句,效果很好。但当我添加else if语句时,它不起作用如果balls>0则fff,否则如果balls>和&mobile>0则5af716,否则eee。 我如何解决这个问题

工作版本


       <tr th:each="country : ${data}" th:style="${country.balls} > 0 ? 'background-color: #fff' :'background-color: #eee' " >
              <td th:text="${country.id}"></td>
              <td th:text="${country.msisdn}"></td>
              <td th:text="${country.frequency}"></td>
              <td th:text="${country.balls}"></td>
              <td th:text="${country.mobile}"></td>
              <td th:text="${country.name}"></td>
              <td>
                <!--<a class="btn btn-danger delBtn" th:href="@{delete/(id=${country.id})}">Delete</a>-->
                <a class="btn btn-primary eBtn" th:href="@{findOne/(id=${country.id})}">Edit</a>
              </td>
        </tr>

我需要下面的内容,但它给出了一个错误

 <tr th:each="country : ${data}" th:style="${country.balls > 0}  ? 'background-color: #fff' :
                                                      ${country.balls > 0 and country.mobile > 0} ? 'background-color: #5af716'
                                                      : 'background-color: #eee' " >
              <td th:text="${country.id}"></td>
              <td th:text="${country.msisdn}"></td>
              <td th:text="${country.frequency}"></td>
              <td th:text="${country.balls}"></td>
              <td th:text="${country.mobile}"></td>
              <td th:text="${country.name}"></td>
              <td>
                <!--<a class="btn btn-danger delBtn" th:href="@{delete/(id=${country.id})}">Delete</a>-->
                <a class="btn btn-primary eBtn" th:href="@{findOne/(id=${country.id})}">Edit</a>
              </td>
       </tr>

看看这个:

<tr th:each="country : ${countries}" 
    th:style="${country.balls > 0 and country.mobile > 0} 
        ? 'background-color: #5af716' 
        : (${country.balls > 0 } ? 'background-color: #fff' 
        : 'background-color: #eee' ) " >

这将生成如下表(在我的简化测试用例中):

注意事项如下:

1) 更改运行测试的顺序,以便限制性最强的测试是第一个测试

2) 您可以将三元运算符嵌套在三元运算符中,以模拟多级if语句

我认为这应该适合你的具体情况