XML
有效的XML
XHTML
有效的XHTML
HTML5
旧版HTML5
XHTML 1.0过渡版
严格的XHTML 1.0
XHTML 1.0框架集
XHTML 1.1。
<form:inputText name="student.Name" value="${student.name}" />
<input type="text" name=" student Name" value="Thomas" th:value="${student.name}" />
它既可以在网络环境中使用,也可以在非网络环境中使用。
用于HTML5/XML/XHTML的Java模板引擎。
其高性能的解析模板缓存将I/O降至最低。
如果需要,它可以用作模板引擎框架。
它支持几种模板模式: XML,XHTML和HTML5。
它允许开发人员扩展和创建自定义方言。
它基于称为方言的模块化功能集。
它支持国际化。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
package com.lidihuo;
public class User
{
String name;
String email;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getEmail()
{
return email;
}
public void setEmail(String email)
{
this.email = email;
}
}
package com.lidihuo;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.stereotype.Controller;
@Controller
public class DemoController
{
@RequestMapping("/")
public String index()
{
return"index";
}
@RequestMapping(value="/save", method=RequestMethod.POST)
public ModelAndView save(@ModelAttribute User user)
{
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("user-data");
modelAndView.addObject("user", user);
return modelAndView;
}
}
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<html xmlns:th="https://thymeleaf.org">
<table>
<tr>
<td><h4>User Name: </h4></td>
<td><h4 th:text="${user.name}"></h4></td>
</tr>
<tr>
<td><h4>Email ID: </h4></td>
<td><h4 th:text="${user.email}"></h4></td>
</tr>
</table>
</html>
<html lang="en">
<head>
<title>Index Page</title>
</head>
<body>
<form action="save" method="post">
<table>
<tr>
<td><label for="user-name">User Name</label></td>
<td><input type="text" name="name"></input></td>
</tr>
<tr>
<td><label for="email">Email</label></td>
<td><input type="text" name="email"></input></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit"></input></td>
</tr>
</table>
</form>
</body>
</html>
spring.thymeleaf.cache=false
spring.thymeleaf.suffix: .html
package com.lidihuo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringBootThymeleafViewExampleApplication
{
public static void main(String[] args)
{
SpringApplication.run(SpringBootThymeleafViewExampleApplication.class, args);
}
}