项目描述
上传时间
浏览人数
Controller控制层
@Controller // 将当前class作为控制层 public class wedController { @Autowired //导入 private HttpServletRequest request; @RequestMapping("/webHome") // 当前函数的请求映射路径 public String webHome() { Map<String, Object> stu = new HashMap<>(); stu.put("id", 100012); stu.put("name", "tom"); stu.put("age", 19); stu.put("is_Mar", true); stu.put("gender", true); Map<String, Object> u = new HashMap<>(); u.put("id", 100013); u.put("name", "jreey"); u.put("age", 25); u.put("is_Mar", true); u.put("gender", false); Map<String, Object> aa = new HashMap<>(); aa.put("id", 100014); aa.put("name", "potty"); aa.put("age", 28); aa.put("is_Mar", false); aa.put("gender", true); List<Map<String, Object>> sss = new ArrayList<>(); sss.add(stu); sss.add(u); sss.add(aa); request.setAttribute("sss", sss); return ("wedHome.html"); } }
home显示页面
<!DOCTYPE html> <html lang="zh" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>webHome</title> <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script> <script type="text/javascript" th:src="@{/js/bootstrap.min.js}"></script> <link rel="stylesheet" type="text/css" th:href="@{/css/bootstrap.min.css}"> </head> <body> <div class="container"> <div class="row"> <div class="col-2"></div> <table class="table"> <tr> <th>社员号</th> <th>姓名</th> <th>年龄</th> <th>婚姻</th> <th>性别</th> </tr> <tr th:each="s,state:${sss}" th:switch="state.count"> <td><span th:text="${s.id}"></span></td> <td><span th:text="${s.name}"> </span></td> <td> <span th:text="${s.age}" th:if="${s.age >= 20}" class=" ps-1"></span> <span th:text="${s.age}" th:unless="${s.age >= 20}" class="ps "></span> </td> <td> <span th:if="${s.is_Mar} "class="cl">已婚</span> <span th:unless="${s.is_Mar}"class="co">未婚</span> </td> <td><span th:text="${s.gender ? 'men':'women'}"></span></td> </tr> </table> </div> </div> </body> <style> .ps-1 { color: #86b7fe; } .ps { color: red; } .cl{ color: #ffcd39; } .co{ color: tomato; } </style>