Thymeleaf的jar自带了 与 Spring的整合的相关扩展包 ThymeleafViewResolver 视图
首先添加依赖
1
2
3
4
5
|
<
dependency
>
<
groupId
>org.thymeleaf</
groupId
>
<
artifactId
>thymeleaf</
artifactId
>
<
version
>2.0.18</
version
>
</
dependency
>
|
添加与spring的整合包
1
2
3
4
5
|
<
dependency
>
<
groupId
>org.thymeleaf</
groupId
>
<
artifactId
>thymeleaf-spring3</
artifactId
>
<
version
>2.0.18</
version
>
</
dependency
>
|
第二步 在spring mvc中加入下列
1
2
3
4
5
6
7
8
9
10
11
12
|
<!--声明视图 -->
<
bean
id
=
"templateResolver"
class
=
"org.thymeleaf.templateresolver.ServletContextTemplateResolver"
p:prefix
=
"/WEB-INF/templates/"
p:suffix
=
".html"
p:templateMode
=
"HTML5"
p:order
=
"1"
/>
<
bean
id
=
"templateEngine"
class
=
"org.thymeleaf.spring3.SpringTemplateEngine"
p:templateResolver-ref
=
"templateResolver"
/>
<
bean
class
=
"org.thymeleaf.spring3.view.ThymeleafViewResolver"
p:templateEngine-ref
=
"templateEngine"
/>
|
注意到这里 加了p xmlns命名空间 其实p命名空间相当于property 属性 ,同spring 配置基本视图一样 你也可以改成这种风格
1
2
3
4
5
6
7
8
|
<
bean
id
=
"viewResolver"
class
=
"org.springframework.web.servlet.view.InternalResourceViewResolver"
>
<
property
name
=
"viewClass"
value
=
"org.springframework.web.servlet.view.JstlView"
/>
<
property
name
=
"prefix"
value
=
"/WEB-INF/jsp/"
></
property
>
<
property
name
=
"suffix"
value
=
".jsp"
></
property
>
</
bean
>
|
到这里 配置已经完成了
下面就可以看上一篇文章 controller注入model 绑定,,,等等 进行开发了
http://my.oschina.net/yilian/blog/172566