Springboot---显示图片/字符串/map集合/list集合
2020-02-04 16:01:50来源:博客园 阅读 ()
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>

原文链接:https://www.cnblogs.com/crazy-lc/p/12258864.html
如有疑问请与原作者联系
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- 怎么用Java 高效提取、替换、删除PDF文档中的图片 2020-06-09
- HWPFDocument读取doc,wps文档(含图片读取) 2020-05-24
- Mybatis显示修改数据库成功,数据库却没有修改 2020-05-22
- Java窗体加载时不显示组件或需要重置窗口 2020-05-21
- 使用阿里云 OSS 存储、访问图片(Java) 2020-04-29
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
