本文共 2276 字,大约阅读时间需要 7 分钟。
Spring MVC:
POM:
org.thymeleaf thymeleaf 3.0.7.RELEASE org.thymeleaf thymeleaf-spring4 3.0.7.RELEASE
Bean:
Controller:
package com.jsoft.testspringmvc.controller;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import com.jsoft.testspringmvc.model.Entry;@Controllerpublic class IndexController { @RequestMapping(value = "/index", method = RequestMethod.GET) public String index(Model model) { Entry entry = new Entry(); entry.setText("Text"); entry.setTitle("Title"); model.addAttribute("entries", entry); model.addAttribute("entry", new Entry()); return "index"; }}
HTML:
Text
Maven示例:
Spring Boot:
POM:
org.springframework.boot spring-boot-starter-thymeleaf
properties:
#thymeleaf startspring.thymeleaf.mode=HTML5spring.thymeleaf.encoding=UTF-8spring.thymeleaf.content-type=text/html#\u5F00\u53D1\u65F6\u5173\u95ED\u7F13\u5B58,\u4E0D\u7136\u6CA1\u6CD5\u770B\u5230\u5B9E\u65F6\u9875\u9762spring.thymeleaf.cache=false#thymeleaf end
其余的代码和Spring MVC是一致的。
引入外界静态资源的方式@{
/xxx},默认的静态资源的根是"static",默认放置在resources下,templates文件夹也是如此。Maven示例:
参考:
(基于全注解的形式的SpringMVC项目中使用thymeleaf模板)
(特别说明,此篇文章的集成Spring MVC是不行的,不要参照)
(Spring MVC)
(Spring Boot)
(Spring Boot)
(Spring Boot)
(Spring Boot)
(Spring Boot)
(Spring Boot)
(Spring Boot配置的项目)
(Spring Boot)
(Spring Boot)
(Spring Boot)
(官方配置项,可以通过搜索关键字thymeleaf来查找,这个链接也是所有标准配置的参考)
(Spring Boot)
(Spring Boot)
==>如有问题,请联系我:easonjim#163.com,或者下方发表评论。<==转载地址:http://vhnkl.baihongyu.com/