SpringBoot集成Freemarker模板

 1,pom.xml,引入依赖

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

2,application.properties配置

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/**

3,文件目录

 

 

 

4,controller

package com.mangoubiubiu.controller;


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

@Controller
public class UserController {

     @RequestMapping("/helloWorld")
     public  String intoIndex(){
       
         return "index";
     }


}

5,index.ftl

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8"/>
    <title></title>
</head>
<body>
FreeMarker模板引擎
<h1><span style="color: darkseagreen">HTLLO WORLD</span></h1>
</body>
</html>

 效果:

 

posted @ 2020-08-22 14:47  KwFruit  阅读(147)  评论(0编辑  收藏  举报