【技能get】springboot-07-web开发-整合freemarker

list.ftl

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
欢迎《${username}》登录
<hr/>

<table border="1">
    <tr>
        <td>ID</td>
        <td>名字</td>
        <td>性别</td>
    </tr>
<#list stulist?sort_by("id")?reverse as stu>
    <tr>
        <td> ${stu.id}</td>
        <td> ${stu.username}</td>
        <td> ${stu.age}</td>
    </tr>
</#list>
</table>


</body>
</html>

StudentController.java

package com.exp.web.controller;

import com.exp.model.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@Controller //如果访问freemarker ,就不要用@RestController
@RequestMapping("/stu")
public class StudentController {

    @RequestMapping("list")
    public String list(Model model){
        model.addAttribute("username","exp");
        model.addAttribute("age",32);
        List<Student> list = new ArrayList<Student>();
        list.add(new Student(1 ,"王宝强",20));
        list.add(new Student(2 ,"周杰伦",39));
        model.addAttribute("stulist",list);
        return "stu/list"; //找模板页面
    }
}

 

 

posted @ 2019-10-26 00:34  expworld  阅读(146)  评论(0)    收藏  举报