Spring Boot使用模板引擎总结

前言

GitHub:https://github.com/yihonglei/SpringBoot-Study

spring boot常用模板引擎,thymeleaf,reemarker,使用步骤:

1) 在pom.xml文件中添加thymeleaf或freemarker依赖

2) 在application.properties文件中添加thymeleaf或freemarker配置

3) 在src/main/resources下新建templates文件夹,存放thymeleaf(xx.html)或freemarker(xx.ftl)模板

4) 编写controller类(注意,使用@Controller注解,而不是@RestController注解;如果使用了@RestController,我们就可以不使用模板引擎了,是直接返回json格式的数据给前端,实现前后端分离

5) 编写启动类(App.java)

6) 访问服务进行测试

 

thymeleaf参考实例:

http://blog.csdn.net/yhl_jxy/article/details/60572902

freemarker参考实例:

http://blog.csdn.net/yhl_jxy/article/details/60573458

posted @ 2020-08-05 12:34  坚持沉淀  阅读(380)  评论(0编辑  收藏  举报