Freemarker循环遍历

循环格式

<#list 要循环的数据 as 循环后的数据>
list>

循环的下标
通过,item_index获取

比如

<#list studentList as student>
${student_index}
#list>

数据集

//6.创建一个数据集,可以是pojo也可以是map,推荐使用map
Map data = new HashMap<>();
List<Student> stuList = new ArrayList<>();
stuList.add(new Student(1, "小米", 11, "北京昌平回龙观"));
stuList.add(new Student(2, "小米2", 12, "北京昌平回龙观"));
stuList.add(new Student(3, "小米3", 13, "北京昌平回龙观"));
stuList.add(new Student(4, "小米4", 14, "北京昌平回龙观"));
stuList.add(new Student(5, "小米5", 15, "北京昌平回龙观"));
stuList.add(new Student(6, "小米6", 16, "北京昌平回龙观"));
stuList.add(new Student(7, "小米7", 17, "北京昌平回龙观"));
data.put("stuList", stuList);

模板

<html>
<head>
    <title>测试页面title>
head>
<body>
    学生列表:<br>
    <table border="1">
        <tr>
            <th>序号th>
            <th>学号th>
            <th>姓名th>
            <th>年龄th>
            <th>家庭住址th>
        tr>
        <#list stuList as stu>
        <tr>
            <td>${stu_index}td>
            <td>${stu.id}td>
            <td>${stu.name}td>
            <td>${stu.age}td>
            <td>${stu.address}td>
        tr>
        #list>
    table>
body>
html>

你可能感兴趣的:(————Freemarker)