新建一个springboot工程,加入thymeleaf依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
application.properties文件:
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.encoding=utf-8
spring.thymeleaf.enabled=true
spring.thymeleaf.servlet.content-type=text/html
在src/main/java/resources/templates下新建一个hello.html文件
建一个controller
package com.xhx.springboot.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.Map;
/**
* xuhaixing
* 2018/8/18 22:10
*
* thymeleaf3.0之前 html标签需要闭合,之后不需要
**/
@Controller
@RequestMapping(value = "templates")
public class HelloController {
@RequestMapping("hello")
public String getHello(Map<String,Object> map){
map.put("name","大大");
return "hello";
}
}
启动程序请求,会跳转到hello.html页面