JAVA 2018-06-28

freemarker 动态解析map

后台要用map包含一下需要的map, 因为页面解析一层map的时候 是直接 ${key}就获取

 List<ExchangeRate> exchangeRateList=iExchangeRateService.findNew();
        List<String> countryList=iExchangeRateService.groupByCountry();
        Map map=new HashMap();
        for (int i = 0; i < exchangeRateList.size(); i++) {
            for (int j = 0; j < countryList.size(); j++) {
                if (exchangeRateList.get(i).getCountry().equals(countryList.get(j))){
                    map.put(countryList.get(j), exchangeRateList.get(i).getRate());
                }
            }

        }
        Map map1=new HashMap();
        map1.put("map", map);
        return new ModelAndView("/exchangerate/findNewRate",map1);

<table border="1px">
    <thead>
    <tr>
        <#list map?keys as key>
            <td>${key}</td>
        </#list>
    </tr>
    </thead>
    <tbody>

    <tr>
        <#list map?values as val>
            <td><input value="${val}"></td>
        </#list>

    </tr>

    </tbody>

猜你喜欢

转载自blog.csdn.net/qq_34319145/article/details/80847700