javascript
Thymeleaf 3 – Thymeleaf 3和Spring MVC快速入门
Thymeleaf 3發(fā)布到達(dá)。 新版本帶來(lái)了許多新功能,例如HTML5支持以及不帶標(biāo)記的文本模板支持– [# th:utext="${thymeleaf.version}" /] ,改進(jìn)的內(nèi)聯(lián)功能– <p>Thymeleaf [[${thymeleaf.version}]] is great!</p> ,性能改進(jìn)等等。
使用Thymeleaf 3和Spring MVC入門的最簡(jiǎn)單方法是使用Spring MVC 4 Quickstart Maven Archetype 。 已更新原型以支持Thymeleaf3。下面將描述對(duì)原型所做的更改。
依存關(guān)系
該項(xiàng)目使用Spring Platform BOM進(jìn)行依賴關(guān)系管理,但是(在撰寫本文時(shí))尚未聲明對(duì)Thymeleaf 3的依賴關(guān)系,因此我需要手動(dòng)聲明版本。
- 胸腺
- Thymeleaf Spring 4:
- Thymeleaf Spring Security 4:
使用原型生成的應(yīng)用程序使用Java 8時(shí)間方言,并且由于Thymeleaf API已更改,因此方言依賴項(xiàng)也必須更新。 在Maven Central中將其可用之前,我們必須將快照存儲(chǔ)庫(kù)添加到POM:
<repository><id>sonatype-nexus-snapshots</id><name>Sonatype Nexus Snapshots</name><url>https://oss.sonatype.org/content/repositories/snapshots</url><snapshots><enabled>true</enabled></snapshots> </repository>然后聲明依賴項(xiàng):
<dependency><groupId>org.thymeleaf.extras</groupId><artifactId>thymeleaf-extras-java8time</artifactId><version>3.0.0-SNAPSHOT</version> </dependency>配置變更
- 模板解析器
之前的模板解析器:
@Bean public TemplateResolver templateResolver() {TemplateResolver resolver = new ServletContextTemplateResolver();resolver.setPrefix(VIEWS);resolver.setSuffix(".html");resolver.setTemplateMode("HTML5");resolver.setCacheable(false);return resolver; }之后的模板解析器:
@Bean public ITemplateResolver templateResolver() {SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();resolver.setPrefix(VIEWS);resolver.setSuffix(".html");resolver.setTemplateMode(TemplateMode.HTML);resolver.setCacheable(false);return resolver; }- 模板引擎
- 查看解析器:
范本
模板在該項(xiàng)目中未更改。 但是,如果要遷移實(shí)際項(xiàng)目,則可能對(duì)閱讀遷移指南感興趣。
參考文獻(xiàn)
- Thymeleaf 3發(fā)布信息
- Thymeleaf 3遷移指南
- Spring MVC 4快速入門Maven原型
翻譯自: https://www.javacodegeeks.com/2016/05/thymeleaf-3-get-started-quickly-thymeleaf-3-spring-mvc.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的Thymeleaf 3 – Thymeleaf 3和Spring MVC快速入门的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: linux稳定版本号(linux稳定)
- 下一篇: 极端懒惰:使用Spring Boot开发