自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(0)
  • 资源 (1)
  • 收藏
  • 关注

空空如也

carcar.sql

自从来公司后都没用过jsp当界面渲染了,因为前后端分离不是很好,反而模板引擎用的比较多,thymeleaf最大的优势后缀为html,就是只需要浏览器就可以展现页面了,还有就是thymeleaf可以很好的和spring集成.下面开始学习. 1.引入依赖 maven中直接引入 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> 1 2 3 4 可以查看依赖关系,发现spring-boot-starter-thymeleaf下面已经包括了spring-boot-starter-web,所以可以把spring-boot-starter-web的依赖去掉. 2.配置视图解析器 spring-boot很多配置都有默认配置,比如默认页面映射路径为 classpath:/templates/*.html 同样静态文件路径为 classpath:/static/ 在application.properties中可以配置thymeleaf模板解析器属性.就像使用springMVC的JSP解析器配置一样 #thymeleaf start spring.thymeleaf.mode=HTML5 spring.thymeleaf.encoding=UTF-8 spring.thymeleaf.content-type=text/html #开发时关闭缓存,不然没法看到实时页面 spring.thymeleaf.cache=false #thymeleaf end 1 2 3 4 5 6 7 具体可以配置的参数可以查看 org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties这个类,上面的配置实际上就是注入到该类中的属性值. 3.编写DEMO 1.控制器 @Controller public class HelloController { private Logger logger = LoggerFactory.getLogger(HelloController.class); /** * 测试hello * @return */ @RequestMapping(value = "/hello",method = RequestMethod.GET) public String hello(Model model) { model.addAttribute("name", "Dear"); return "hello"; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 2.view(注释为IDEA生成的索引,便于IDEA补全) <!DOCTYPE HTML> &lt;html xmlns:th="http://www.thymeleaf.org"&gt; &lt;head&gt; &lt;title&gt;hello&lt;/title&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt; &lt;/head&gt; &lt;body&gt; &lt;!--/*@thymesVar id="name" type="java.lang.String"*/--&gt; <p th:text="'Hello!, ' + ${name} + '!'" >3333</p> &lt;/body&gt; &lt;/html&gt; 1 2 3 4 5 6 7 8 9 10 11 3.效果

2019-08-07

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除