Thymeleaf strings.arraySplit 不起作用

问题描述 投票:0回答:2

我也有类似的问题,请大家指点一下。

我正在使用这个获取数据

<tbody th:each="map : ${InsDashboardData}">
<tr th:each="mapEntry : ${map}">
<td th:text="${mapEntry.key}"></td>
<td></td>   
<td>[[${mapEntry.value}]]</td>  
</tr>                               
但我需要我的程序名称的拆分数据。作为计算机应用硕士(MCA),摄入量为 500。我正在尝试使用下面的代码,但出现错误。

表达式 [#strings.arraySplit(${insData}, '@@@')] @21:EL1043E:意外的标记。预期为“rparen())”,但结果为“lcurly({)”

<tbody th:each="map : ${InsDashboardData}">
<tr th:each="mapEntry : ${map}">
<td th:with="insData=${mapEntry.key}" th:each="item : ${#strings.arraySplit(${insData}, '@@@')}" th:text="${#strings.arraySplit(item,'#')[0]}"></td>                                            
<td th:text="${#strings.arraySplit(item,'#')[1]}"></td>
<td>[[${mapEntry.value}]]</td>  
</tr>                               
java spring spring-boot thymeleaf
2个回答
0
投票

我并不完全清楚这个要求,但是,我想我可以在这里看到语法错误。内部变量不需要再次添加$。

th:each =“项目:$ {#strings.arraySplit(insData,'@@@')}”


0
投票

你必须使用这行代码才能工作:

  • ${#strings.arraySplit(mapEntry.key, '@@@')[0]}
    - 获取
    @@@
    之前的值。

  • ${#strings.arraySplit(mapEntry.key, '@@@')[1]}
    - 获取
    @@@
    之后的值。

用于测试的控制器代码:

@Controller
public class DemoController {

    @GetMapping("/")
    public ModelAndView save() {
        ModelAndView modelAndView = new ModelAndView();
        Map<String,String> map = new HashMap<>();
        map.put("Master of Computer Application@@@500", "316");
        map.put("Bachelor of Computer Application@@@1000", "11");
        modelAndView.setViewName("index");
        modelAndView.addObject("InsDashboardData", map);
        return modelAndView;
    }
} 

更新了 HTML:

<html xmlns:th="https://thymeleaf.org">
<head>
    <style>
        table, th, td {
  border: 1px solid;
}
    </style>
</head>
<table>
    <thead>
    <tr>
        <th>Programme Name</th>
        <th>Intake Capacity</th>
        <th>Final Admission</th>
    </tr>
    </thead>
    <tbody th:each="map : ${InsDashboardData}">
    <tr th:each="mapEntry : ${map}">
        <td th:text="${#strings.arraySplit(mapEntry.key, '@@@')[0]}"></td>
        <td th:text="${#strings.arraySplit(mapEntry.key, '@@@')[1]}"></td>
        <td>[[${mapEntry.value}]]</td>
    </tr>
</table>
</html>

输出:

© www.soinside.com 2019 - 2024. All rights reserved.