select前台转义后台取到的值为对应的文本 select同时接受list和map

简单描述:select动态取值 要求是根据后台传过来的值在前台进行转义,emmm干就完了

思路分析:后台同时传过去一个map一个list ,map用来前台转义,list用来获取值,list取到的值相当于map的key

代码:

//后台java代码
HashMap<String, String> serviceMap = new HashMap<>();
serviceMap.put("1", "仅保存");
serviceMap.put("2", "已发布");
serviceMap.put("3", "已删除"); modelMap.addAttribute("serviceMap", serviceMap); modelMap.addAttribute("list",list); return VIEW_PATH + "/list";

//html代码
<tr th:each="list : ${list}">
<td>
<label class="mt-checkbox mt-checkbox-single mt-checkbox-outline">
<input type="checkbox" class="checkboxes" th:value="${list.serviceId}"/>
</label>
</td>
<td th:text="${list.serviceName}">服务名称</td>
<td th:text="${list.serviceCode}">服务编码</td>
<td th:text="${serviceMap['__${list.serviceType}__']}">服务类型</td>
</tr>
//说明一下: 最后一个td 中的${list.serviceType}取出来的值是1 2 3,serviceMap会把list取出来的1 2 3当做key来取值 仅保存 已发布 已删除

猜你喜欢

转载自www.cnblogs.com/xuchao0506/p/9779533.html