SpringBoot 集成Freemarker

2020-02-14 17:48:38 浏览数 (3)

本文讲述简单的freemarker小案例搭建,更多详细关于freemarker点击文章结尾链接

创建环境

首先使用idea 创建项目,选择freemarker包

配置yml
代码
代码语言:javascript复制
@Controller
public class HelloController {
    @RequestMapping("/")
    public ModelAndView hello(){
        ModelAndView modelAndView = new ModelAndView();
        People people = new People();
        people.setName("zhangsan");
        people.setSex("男");
        people.setAge(15);
        modelAndView.addObject("people", people);
        modelAndView.setViewName("index");
        return modelAndView;
    }
}
代码语言:javascript复制
@Data
public class People {
    String name;
    String sex;
    Integer age;
}
代码语言:javascript复制
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>name:${people.name}</h1>
<h1>sex:${people.sex}</h1>
<h1>age:${people.age}</h1>
</body>
</html>
运行结果

更多更详细的请看 springboot的两大常用模版:thymeleaf和freemarker

实现一个代码自动生成(一):模板引擎Freemarker

0 人点赞