freemaker在表格中遍历数据

Controller层如下所示:

  @RequestMapping(value = "/test", method = RequestMethod.GET)
    public String test(Model model) {
        List<City> cityList = cityService.findAllCity();
        model.addAttribute("cityList",cityList);
        return "test";
    }

Freemaker如下所示:

 <table border="1">
        <tr>
            <td>城市名</td>
            <td>省编码</td>
            <td>描述</td>
        </tr>
    <#list cityList! as city>
        <tr>
            <td>${city.cityName!}</td>
            <td>${city.provinceId!}</td>
            <td>${city.description!}<br></td>
        </tr>
    </#list>
    </table>

 注意:freemaker在对象后面添加 ! ,表示允许该对象为空。也可以不加!,直接写对象。

效果如下:

原文地址:https://www.cnblogs.com/expiator/p/9199174.html