zoukankan      html  css  js  c++  java
  • velocity获取list,map以及list套map中数据

    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 
    
  • 相关阅读:
    vim 命令替换重复命令
    Python环境安装
    MySQL 查看show profile
    XSS攻击与CSRF攻击与防御
    HTTPS的原理
    PHP curl的请求步骤
    【论文阅读】HRNet
    【学习笔记】gRPC-python
    【Linux学习笔记】Linux基础
    【Golang学习笔记】入门:结构体、方法与接口
  • 原文地址:https://www.cnblogs.com/interdrp/p/15777692.html
Copyright © 2011-2022 走看看