设置Thymeleaf页面复选框显示勾选效果

Springboot版本

1
2
3
4
5
6
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.14</version>
        <relativePath/>
</parent>

  引入的thymeleaf依赖

1
2
3
4
5
<!--引入thymeleaf依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

  java层代码

1
2
3
4
5
6
7
8
9
10
11
12
for (Map<String, Object> map : mapList) {
           String userName = map.get("user_name").toString();
           if (selectUserList.contains(userName)){
               map.put("status","1");
           }else {
               map.put("status","0");
           }
       }
       mapList.forEach(a->{
           System.out.println(a);
       });
       model.addAttribute("users",mapList);

  thymeleaf页面代码

 

1
2
3
4
5
6
<div th:each="user : ${users}">
                <div class="form-check">
                    <span th:text="${user.user_name}" >用户名</span>
                    <input class="form-check-input permission-checkbox"  th:checked="${user.status} eq '1'"  type="checkbox" th:value="${user.user_role_id}" th:id="${'user' + user.user_role_id}">
                </div>
            </div>

  

 

posted @   不忘初心2021  阅读(162)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
历史上的今天:
2022-11-09 oracle游标简单使用
2022-11-09 ArrayBlockingQueue简单介绍
点击右上角即可分享
微信分享提示