pom.xml配置
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
package com.xiaowen.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/freemark")
public class FreemakerController {
/**
* 设置数据,返回到freemarker视图
* @return
*/
@RequestMapping("/sayHello")
public ModelAndView sayHello(){
ModelAndView mv=new ModelAndView();
mv.addObject("message", "SpringBoot");
mv.setViewName("helloWorld");
return mv;
}
}
freemark模板
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
show:${message}
</body>
</html>
浏览器访问:http://localhost:8088/freemark/sayHello