velocity获取list,map以及list套map中数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
1.velocity 获取list 中的值
 
VelocityEngine veloEngine = new VelocityEngine();
 
 
Template template = veloEngine.getTemplate(xmlPath, "UTF-8");
VelocityContext velocityContext = new VelocityContext();
List<Object> list = new ArrayList<Object>();
list.add("1");
list.add("2");
 
 
velocityContext.put("list", list);
 
   
 
  XML中写法为
 
   #foreach($data in $list)    
<risk>
<age>$!data </age> @$!其中!代表非空时取值,避免值为空时显示为data
</risk>
#end
 
   2.velocity 获取map 中的值
 
  Map<String,Object> map = new HashMap<String,Object>();
map.put("age", "11");
map.put("sex","男");
 
velocityContext.put("data", map);
 
XML中写法为
 
  <age>$!data.age</age>
  <sex>$!data.sex</sex>
  3.velocity 获取list套map 中的值
 
 
List<Object> list = new ArrayList<Object>();
Map<String, Object> map2 = new HashMap<String, Object>();
map2.put("age", "11");
Map<String, Object> map3 = new HashMap<String, Object>();
map3.put("age", "22");
map3.put("bname", "bname");
list.add(map2);
list.add(map3);
 
Map<String, Object> map = new HashMap<String, Object>();
map.put("list", list);
velocityContext.put("data", map);
 
 
XML中写法为
 
 
   
   #foreach ($lis in ${data})  @第一次循环获取list
   #foreach( $aa in $lis)    @然后将lis循环获取变量
<risk>
 
<age>$!aa.age </age>
<age>$!aa.bname </age>
</risk>
#end
   #end

 

posted @   锐洋智能  阅读(923)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· 分享4款.NET开源、免费、实用的商城系统
· 解决跨域问题的这6种方案,真香!
· 5. Nginx 负载均衡配置案例(附有详细截图说明++)
· Windows 提权-UAC 绕过
历史上的今天:
2015-01-08 解决html5 audio iphone,ipd,safari不能自动播放问题
2014-01-08 序列化人人网框架下的DAO?也就是在Spring下序列化DAO的问题(spring+quartz集群下)
2014-01-08 quartz 中JobExecutionContext的使用
2014-01-08 Memcached 集群架构方面的问题
点击右上角即可分享
微信分享提示