thymeleaf是spring官方推崇的模板引擎,下面说一说如何配置
1 添加依赖
如果是多模块项目最好放到顶层模块中。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.11.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring4</artifactId>
<version>3.0.11.RELEASE</version>
</dependency>
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
2 配置文件中添加配置

3 目录结构

4 测试调用
代码:1
2
3
4
5
6
7
public class UserLoginController {
public String login(){
return "home";
}
}
页面:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<html lang="en" xmlns:th="http://www.thymeleaf.org" >
<head>
<meta charset="UTF-8" />
<title>主页</title>
</head>
<body>
<form class="form-signin" role="form" th:action="@{/user/login}" th:method="post">
<input type="text" class="form-control" placeholder="用户名" required="required" name="userName" />
<input type="password" class="form-control" placeholder="密码" required="required" name="password" />
<button class="btn btn-lg btn-warning btn-block" type="submit">登录</button>
</form>
</body>
</html>
一切正常的话就可以用了,刚开始怎么都不能跳转页面,最后终于发现是没有引用nekohtml依赖,弄了俩小时。。
