美文网首页
spring boot 集成thymeleaf引擎模板

spring boot 集成thymeleaf引擎模板

作者: 周六不算加班 | 来源:发表于2018-06-04 21:07 被阅读39次

1、添加jar包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

2、配置文件设置
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.mode=LEGACYHTML5

3、java后台代码
@Controller
public class TestController {

    @Autowired
    TestService testService;

    @RequestMapping("/")
    public String testThymeleaf(ModelMap modelMap){
        modelMap.addAttribute("msg", "helloworld");
        return "index";
    }

}

4、页面设计
必须要放指定的文件夹下,此处的路径是resource/templates,内容如下
<!DOCTYPE html>

<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>index</title>
</head>
<body>
<h1 th:text="${msg}"></h1>
</body>
</html>

相关文章

网友评论

      本文标题:spring boot 集成thymeleaf引擎模板

      本文链接:https://www.haomeiwen.com/subject/ncfusftx.html