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>

  • 相关阅读:
    【19】什么时候该改变开发集和评估指标
    【18】训练/开发/测试集划分
    【17】满足和优化指标
    【16】机器学习中的单一评估指标
    【15】ML项目流程与正交化
    【14】Softmax回归
    【13】正则化网络激活函数(Batch归一化)
    【12】超参数及超参数的选择
    【11】神经网络的优化算法
    06-----Nodejs介绍
  • 原文地址:https://www.cnblogs.com/crazy-lc/p/12258864.html
Copyright © 2011-2022 走看看