springboot-集成freemaker

springboot-集成freemaker

1,添加依赖

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>

2,添加 index.ftl 文件

index.ftl 文件放在 resource/template 目录下
ftl 支持 jstl 语法

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8"/>
    <title></title>
</head>
<body>
    ${name}
</body>
</html>

3,编写 controller 类

package com.test.freemarker;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 
 */
@Controller
public class IndexController {

    @RequestMapping("/index")
    public String index(ModelMap map){
        map.addAttribute("name", "张三");
        return "index";
    }
}

你可能感兴趣的:(springBoot)