设置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> |
标签:
springboot
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 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简单介绍