0
点赞
收藏
分享

微信扫一扫

springboot集成freemarker

科牛 2023-02-28 阅读 96


pom.xml中添加:

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

application.properties中添加:

spring.jpa.open-in-view=true

spring.freemarker.charset=UTF-8
spring.freemarker.suffix=.ftl
spring.freemarker.content-type=text/html; charset=utf-8
spring.freemarker.template-loader-path=classpath:/templates
spring.mvc.static-path-pattern=/static/**

如果要设置多个模板文件的位置用逗号分隔:

spring.freemarker.template-loader-path=classpath:/templates,classpath:/public

然后在resources,下面新建templates文件夹(默认约定存放么模板文件),新建index.ftl

controller指向这里即可:

@Controller
class FreemarkerController {
@RequestMapping("/index")
public String index(Model model){
model.addAttribute("name","hello pillar");
return "index";
}
}


举报

相关推荐

0 条评论