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 |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· 解决跨域问题的这6种方案,真香!
· Windows 提权-UAC 绕过
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
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 集群架构方面的问题