zoukankan      html  css  js  c++  java
  • Springboot---显示图片/字符串/map集合/list集合

    1.字符串/图片/map集合

      @GetMapping("/hello")
        public String test(Model model){
            String message="first thymeleaf !!";
            model.addAttribute("message",message);
            User u = new User();
            u.setId(1);
            u.setName("ttttttt");
            u.setAge(18);
    
            Map<String,Object> map=new HashMap<>();
            map.put("s1","/static/1.jpg");
            map.put("s2","/static/2.jpg");
    
            model.addAttribute("message", message);
            model.addAttribute("user", u);
            model.addAttribute("src", map);
            return "index2";
        }
    index2.html

    <
    body> <h1 th:text="${message}"></h1> <img th:src="${src.s1}"/></br> <img th:src="${src.s2}"/></br> 实体类信息<br> <span th:text="${user.id}"></span> <span th:text="${user.name}"></span> <span th:text="${user.age}"></span> <br> </body>

    访问:http://localhost:8080/test/hello

    结果:

    2.List集合

    @GetMapping("/hello2")
        public String test2(Model model){
            List<User> list=new ArrayList<User>();
            User u1 = new User();
            u1.setId(1);
            u1.setName("11111111");
            u1.setAge(18);
            list.add(u1);
    
            User u2 = new User();
            u2.setId(2);
            u2.setName("2222222222");
            u2.setAge(28);
            list.add(u2);
            User u3 = new User();
            u3.setId(3);
            u3.setName("3333333333");
            u3.setAge(88);
            list.add(u3);
    
            User u4 = new User();
            u4.setId(4);
            u4.setName("4444444444");
            u4.setAge(888);
            list.add(u4);
    
            model.addAttribute("userList", list);
            return "index3";
        }
    <body>
        <table width="200" style="text-align: center;">
            <tr>
                <th>编号</th>
                <th>姓名</th>
                <th>年龄</th>
                <th>index</th>
            </tr>
            <tr th:each="user,iterStat : ${userList}">
                <td th:text="${user.id}"></td>
                <td th:text="${user.name}"></td>
                <td th:text="${user.age}"></td>
                <td th:text="${iterStat.index}">index</td>
            </tr>
        </table>
    </body>

  • 相关阅读:
    UVA1349 Optimal Bus Route Design 最优巴士路线设计
    POJ3565 Ants 蚂蚁(NEERC 2008)
    UVA1663 Purifying Machine 净化器
    UVa11996 Jewel Magic 魔法珠宝
    NEERC2003 Jurassic Remains 侏罗纪
    UVA11895 Honorary Tickets
    gdb调试coredump(使用篇)
    使用 MegaCLI 检测磁盘状态并更换磁盘
    员工直接坦诚直来直去 真性情
    山东浪潮超越3B4000申泰RM5120-L
  • 原文地址:https://www.cnblogs.com/crazy-lc/p/12258864.html
Copyright © 2011-2022 走看看