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>

Springboot---显示图片/字符串/map集合/list集合的更多相关文章
- img src 直接显示图片字符串,微信例子
<div class="weui-cell__hd"><img src="data:image/png;base64,iVBORw0KGgoAAAANS ...
- java字符串,数组,集合框架重点
1.字符串的字面量是否自动生成一个字符串的变量? String str1 = “abc”; Sring str2 = new String (“abc”); 对于str1:Jvm在遇到双 ...
- python之字符串,列表,字典,元组,集合内置方法总结
目录 数字类型的内置方法 整型/浮点型 字符串类型的内置方法 列表的内置方法 字典的内置方法 元组的内置方法 集合类型内置方法 布尔类型 数据类型总结 数字类型的内置方法 整型/浮点型 加 + 减 - ...
- C#中服务端接受前端JSON字符串转换成字典集合
我们是否可以把从前端接受的JSON字符串转换成字典集合呢? 比如从前端接收:{'size':'10', 'weight':'10kg'} 在服务端转换成:[{size:"10"}, ...
- 数组转集合、集合转数组、字符串数组与int型、long型数组等的转换
在项目中经常会遇到数组转集合.集合转数组.数组之间类型转换等操作 1.数组转集合 为了实现把一个数组转换成一个ArrayList,很多Java程序员会使用如下的代码: String str[] = { ...
- Python基础(4)列表、元组、字符串、字典、集合、文件操作
列表.元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 详见:http://www.cnblogs.com/alex3714/articles/5717620.html 1.列表和元 ...
- Python之路【第二篇】: 列表、元组、字符串、字典、集合
本文内容: -------------------------------------- 列表.元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 1. 列表(list) 序列是Pyt ...
- Python小白的发展之路之Python基础(二)【字符串、列表、集合、文件操作】
列表.元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 1.列表.元组操作 (1)列表 列表是可变的(mutable)——可以改变列表的内容,这不同于字符串和元组,字符串和元组都是不 ...
- Delphi 读取 c# webservice XML的base64编码图片字符串转化图片并显示
Delphi 读取 c# webservice XML的base64编码图片字符串转化图片并显示 在 开发中遇到应用c#及asp.net的在的webservice 保存图片并以xml文件形式现实出来 ...
随机推荐
- 3 HTML标题&元素&图像&属性&字体增强&链接&头部标签与元素
HTML标题(heading) 通过<h1>~~~<h6>定义,每个元素代表文档中不同级别的内容. h1表示主标题,the main heading , h2,3分别表示二级. ...
- JS 数组相关
数组 function SelectLoadTable() { var mids = $("#mids").val(); var halls = $("#halls&qu ...
- Codeforces Round #586 (Div. 1 + Div. 2)E(拓扑排序,思维)
#include<bits/stdc++.h>using namespace std;int n,m,s; vector<int>edge[200007];queue<i ...
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)B(SET)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;int a[2007];set<int& ...
- SpringMVC配置没有任何问题根据请求却怎么都找不到映射(tomcat所导致的问题)
本人在做SpringMVC练习的时候,配置文件反复检查了不下十几遍,没有任何问题,然后就招了个之前的项目的源码复制进去,原来的项目没有任何问题,这个项目却怎么都不能跳转路径,然后有找了一个Spring ...
- 把PHP大牛记下来,方便以后关注
本帖最后由 fish_study 于 2014-12-31 00:18 编辑 五四陈科学院博主54chen(陈臻),哥学社创始人,前人人网分布式存储nuclear研发人员,现关注erlang.hado ...
- C++函数的理解思考
函数指针调用方式 void testmy(int k) { cout << "testzhixing " <<k << endl; } int ...
- 四 SpringMVC与页面之间的参数传递&高级参数的绑定&日期类型的转换
参数传递: 1 原生方式:使用Servlet API , request.getParameter("id"); 2 直接将请求参数作为Controller中的形参: publ ...
- 【剑指Offer面试编程题】题目1512:用两个栈实现队列--九度OJ
题目描述: 用两个栈来实现一个队列,完成队列的Push和Pop操作. 队列中的元素为int类型. 输入: 每个输入文件包含一个测试样例. 对于每个测试样例,第一行输入一个n(1<=n<=1 ...
- java并发:初探sleep方法
sleep与wait sleep是Thread方法,使得当前线程从运行态变为阻塞态.但它不会释放对象的锁. wait方法是Object方法,它的作用是使得当前拥有对象锁的线程从运行态变为阻塞态, 它会 ...