Skip to content

Commit 1d9a6c5

Browse files
author
Songyu
committed
更新文章springMVC整合thymeleaf及相关图片;更新生成tag目录t
1 parent 5c328d3 commit 1d9a6c5

File tree

13 files changed

+270
-50
lines changed

13 files changed

+270
-50
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
layout: post
3+
title: "springMVC整合thymeleaf"
4+
date: 2020-11-06 21:09:06 +0800
5+
tags: java
6+
description:
7+
---
8+
9+
对于maven项目来说,引入其他jar包是非常方便的。这也是maven的优势之一。
10+
上篇文章说到,对于视图解析器,我们准备使用thymeleaf,特点什么的就不介绍,去[官网][thymeleaf]查看即可
11+
12+
## 引入maven配置
13+
14+
对于thymeleaf的使用,我们需要引入连个jar包,一个是thymeleaf本身,另一个就是thymeleaf对于spring框架的支持jar包
15+
{% highlight xml %}
16+
<dependency>
17+
<groupId>org.thymeleaf</groupId>
18+
<artifactId>thymeleaf</artifactId>
19+
<version>3.0.11.RELEASE</version>
20+
</dependency>
21+
<dependency>
22+
<groupId>org.thymeleaf</groupId>
23+
<artifactId>thymeleaf-spring4</artifactId>
24+
<version>3.0.11.RELEASE</version>
25+
</dependency>
26+
{% endhighlight %}
27+
28+
## springmvc中配置视图解析器
29+
30+
{% highlight xml %}
31+
<!-- 视图解析器 -->
32+
<bean id="templateResolver" class="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver">
33+
<!--前缀(视图根路径)-->
34+
<property name="prefix" value="/WEB-INF/views/"></property>
35+
<!--后缀(类型)-->
36+
<property name="suffix" value=".html"></property>
37+
<!--模板类型-->
38+
<property name="templateMode" value="HTML"></property>
39+
<!--不使用缓存-->
40+
<property name="cacheable" value="false"></property>
41+
<!--编码类型-->
42+
<property name="characterEncoding" value="UTF-8"></property>
43+
</bean>
44+
<!--模板引擎配置-->
45+
<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
46+
<property name="templateResolver" ref="templateResolver"></property>
47+
</bean>
48+
<!--视图处理器-->
49+
<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
50+
<property name="templateEngine" ref="templateEngine"></property>
51+
<property name="characterEncoding" value="UTF-8"></property>
52+
</bean>
53+
{% endhighlight %}
54+
55+
## 结果测试
56+
57+
配置完成后,我们可以创建一个Controller进行测试。具体代码如下
58+
59+
控制器部分:
60+
61+
{% highlight java %}
62+
@Controller
63+
@RequestMapping(value = "show")
64+
public class ShowController{
65+
@GetMapping(value = "index")
66+
public ModelAndView index(){
67+
//注意这里返回的是ModelAndView对象
68+
ModelAndView mv = new ModelAndView();
69+
mv.addObject("name","暮语");
70+
//由于我们在配置文件中配置了根路径和后缀,此处自需要写出视图中间路径即可
71+
mv.setViewName("demo/show/index");
72+
73+
return mv;
74+
}
75+
}
76+
{% endhighlight %}
77+
78+
Html部分:
79+
80+
{% highlight html %}
81+
<!DOCTYPE html>
82+
<html lang="en">
83+
<head>
84+
<meta charset="UTF-8">
85+
<title>Thymeleaf Demo</title>
86+
</head>
87+
<body>
88+
<!-- 这里读取的是,控制器中传过来的参数 -->
89+
<p>我得名字叫:[[${name}]]</p>
90+
</body>
91+
</html>
92+
{% endhighlight %}
93+
94+
完成后,启动项目并在浏览器进行访问,返回如下结果,说明配置成功!
95+
96+
![](/images/2020-11-06-1.png)
97+
98+
Ok,视图引入完成后,下一篇该轮到数据库了
99+
100+
对于thymeleaf的用法,以后如果有机会的话,会写一篇文章单独介绍一下
101+
![](/images/2020-11-06-2.jpg)
102+
103+
104+
[thymeleaf]:https://www.thymeleaf.org/

images/2020-11-06-1.png

9.83 KB
Loading

images/2020-11-06-2.jpg

30.7 KB
Loading

tag/docker/index.html

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ <h2 class="post_title">标签分类 "docker&rdquo;</h2>
126126

127127

128128

129+
130+
131+
132+
133+
134+
135+
136+
129137

130138

131139

@@ -280,16 +288,16 @@ <h2 class="post-title">
280288
<h2>近期文章</h2>
281289
<ul>
282290

291+
<li><a href="/2020/11/springmvc%E6%95%B4%E5%90%88thymeleaf">springMVC整合thymeleaf</a></li>
292+
293+
<li><a href="/2020/11/idea%E6%90%AD%E5%BB%BAspringmvc">idea搭建springMVC</a></li>
294+
283295
<li><a href="/2020/10/shiro%E6%B5%8F%E8%A7%88%E5%99%A8%E5%90%8C%E6%97%B6%E7%99%BB%E5%BD%95%E4%B8%A4%E4%B8%AA%E4%B8%8D%E5%90%8C%E7%9A%84%E7%94%A8%E6%88%B7">shiro浏览器同时登录两个不同的用户</a></li>
284296

285297
<li><a href="/2020/10/springmvci%E9%9B%86%E6%88%90shiro-%E5%A4%9A%E8%BA%AB%E4%BB%BD">springMVCi集成shiro(多身份)</a></li>
286298

287299
<li><a href="/2020/05/git-%E7%94%9F%E6%88%90%E8%A1%A5%E4%B8%81%E5%92%8C%E6%89%93%E8%A1%A5%E4%B8%81">git 生成补丁和打补丁</a></li>
288300

289-
<li><a href="/2020/03/windwos%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AEmaven">Windwos安装配置maven</a></li>
290-
291-
<li><a href="/2020/02/nginx%E6%97%A5%E5%BF%97">nginx日志</a></li>
292-
293301
</ul>
294302
</div>
295303

@@ -307,7 +315,7 @@ <h2>文章分类</h2>
307315
<span>github</span></a></li>
308316

309317
<li>
310-
<a href="/tag/java" data-toggle="tooltip" data-placement="right" title="2">
318+
<a href="/tag/java" data-toggle="tooltip" data-placement="right" title="4">
311319
<span>java</span></a></li>
312320

313321
<li>

tag/github/index.html

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ <h2 class="post_title">标签分类 "github&rdquo;</h2>
6363

6464

6565

66+
67+
68+
69+
70+
71+
72+
73+
6674
<h2 class="post-title">
6775
<a href="https://GuoSongyu.github.io/2020/05/git-%E7%94%9F%E6%88%90%E8%A1%A5%E4%B8%81%E5%92%8C%E6%89%93%E8%A1%A5%E4%B8%81">
6876
git 生成补丁和打补丁
@@ -334,16 +342,16 @@ <h2 class="post-title">
334342
<h2>近期文章</h2>
335343
<ul>
336344

345+
<li><a href="/2020/11/springmvc%E6%95%B4%E5%90%88thymeleaf">springMVC整合thymeleaf</a></li>
346+
347+
<li><a href="/2020/11/idea%E6%90%AD%E5%BB%BAspringmvc">idea搭建springMVC</a></li>
348+
337349
<li><a href="/2020/10/shiro%E6%B5%8F%E8%A7%88%E5%99%A8%E5%90%8C%E6%97%B6%E7%99%BB%E5%BD%95%E4%B8%A4%E4%B8%AA%E4%B8%8D%E5%90%8C%E7%9A%84%E7%94%A8%E6%88%B7">shiro浏览器同时登录两个不同的用户</a></li>
338350

339351
<li><a href="/2020/10/springmvci%E9%9B%86%E6%88%90shiro-%E5%A4%9A%E8%BA%AB%E4%BB%BD">springMVCi集成shiro(多身份)</a></li>
340352

341353
<li><a href="/2020/05/git-%E7%94%9F%E6%88%90%E8%A1%A5%E4%B8%81%E5%92%8C%E6%89%93%E8%A1%A5%E4%B8%81">git 生成补丁和打补丁</a></li>
342354

343-
<li><a href="/2020/03/windwos%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AEmaven">Windwos安装配置maven</a></li>
344-
345-
<li><a href="/2020/02/nginx%E6%97%A5%E5%BF%97">nginx日志</a></li>
346-
347355
</ul>
348356
</div>
349357

@@ -361,7 +369,7 @@ <h2>文章分类</h2>
361369
<span>github</span></a></li>
362370

363371
<li>
364-
<a href="/tag/java" data-toggle="tooltip" data-placement="right" title="2">
372+
<a href="/tag/java" data-toggle="tooltip" data-placement="right" title="4">
365373
<span>java</span></a></li>
366374

367375
<li>

tag/java/index.html

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,50 @@ <h2 class="post_title">标签分类 "java&rdquo;</h2>
5555

5656

5757

58+
<h2 class="post-title">
59+
<a href="https://GuoSongyu.github.io/2020/11/springmvc%E6%95%B4%E5%90%88thymeleaf">
60+
springMVC整合thymeleaf
61+
</a>
62+
</h2>
63+
64+
<div class="post-meta">
65+
<div class="post-time">
66+
<i class="fa fa-calendar"></i>
67+
<time datetime='2020-11-06'>06 Nov 2020</time>
68+
</div>
69+
</div>
70+
<div class="post-descr">
71+
<p>
72+
73+
</p>
74+
</div>
75+
76+
77+
78+
79+
80+
<h2 class="post-title">
81+
<a href="https://GuoSongyu.github.io/2020/11/idea%E6%90%AD%E5%BB%BAspringmvc">
82+
idea搭建springMVC
83+
</a>
84+
</h2>
85+
86+
<div class="post-meta">
87+
<div class="post-time">
88+
<i class="fa fa-calendar"></i>
89+
<time datetime='2020-11-02'>02 Nov 2020</time>
90+
</div>
91+
</div>
92+
<div class="post-descr">
93+
<p>
94+
95+
</p>
96+
</div>
97+
98+
99+
100+
101+
58102
<h2 class="post-title">
59103
<a href="https://GuoSongyu.github.io/2020/10/shiro%E6%B5%8F%E8%A7%88%E5%99%A8%E5%90%8C%E6%97%B6%E7%99%BB%E5%BD%95%E4%B8%A4%E4%B8%AA%E4%B8%8D%E5%90%8C%E7%9A%84%E7%94%A8%E6%88%B7">
60104
shiro浏览器同时登录两个不同的用户
@@ -280,16 +324,16 @@ <h2 class="post-title">
280324
<h2>近期文章</h2>
281325
<ul>
282326

327+
<li><a href="/2020/11/springmvc%E6%95%B4%E5%90%88thymeleaf">springMVC整合thymeleaf</a></li>
328+
329+
<li><a href="/2020/11/idea%E6%90%AD%E5%BB%BAspringmvc">idea搭建springMVC</a></li>
330+
283331
<li><a href="/2020/10/shiro%E6%B5%8F%E8%A7%88%E5%99%A8%E5%90%8C%E6%97%B6%E7%99%BB%E5%BD%95%E4%B8%A4%E4%B8%AA%E4%B8%8D%E5%90%8C%E7%9A%84%E7%94%A8%E6%88%B7">shiro浏览器同时登录两个不同的用户</a></li>
284332

285333
<li><a href="/2020/10/springmvci%E9%9B%86%E6%88%90shiro-%E5%A4%9A%E8%BA%AB%E4%BB%BD">springMVCi集成shiro(多身份)</a></li>
286334

287335
<li><a href="/2020/05/git-%E7%94%9F%E6%88%90%E8%A1%A5%E4%B8%81%E5%92%8C%E6%89%93%E8%A1%A5%E4%B8%81">git 生成补丁和打补丁</a></li>
288336

289-
<li><a href="/2020/03/windwos%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AEmaven">Windwos安装配置maven</a></li>
290-
291-
<li><a href="/2020/02/nginx%E6%97%A5%E5%BF%97">nginx日志</a></li>
292-
293337
</ul>
294338
</div>
295339

@@ -307,7 +351,7 @@ <h2>文章分类</h2>
307351
<span>github</span></a></li>
308352

309353
<li>
310-
<a href="/tag/java" data-toggle="tooltip" data-placement="right" title="2">
354+
<a href="/tag/java" data-toggle="tooltip" data-placement="right" title="4">
311355
<span>java</span></a></li>
312356

313357
<li>

tag/jekyll/index.html

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ <h2 class="post_title">标签分类 "jekyll&rdquo;</h2>
118118

119119

120120

121+
122+
123+
124+
125+
126+
127+
128+
121129

122130

123131

@@ -334,16 +342,16 @@ <h2 class="post-title">
334342
<h2>近期文章</h2>
335343
<ul>
336344

345+
<li><a href="/2020/11/springmvc%E6%95%B4%E5%90%88thymeleaf">springMVC整合thymeleaf</a></li>
346+
347+
<li><a href="/2020/11/idea%E6%90%AD%E5%BB%BAspringmvc">idea搭建springMVC</a></li>
348+
337349
<li><a href="/2020/10/shiro%E6%B5%8F%E8%A7%88%E5%99%A8%E5%90%8C%E6%97%B6%E7%99%BB%E5%BD%95%E4%B8%A4%E4%B8%AA%E4%B8%8D%E5%90%8C%E7%9A%84%E7%94%A8%E6%88%B7">shiro浏览器同时登录两个不同的用户</a></li>
338350

339351
<li><a href="/2020/10/springmvci%E9%9B%86%E6%88%90shiro-%E5%A4%9A%E8%BA%AB%E4%BB%BD">springMVCi集成shiro(多身份)</a></li>
340352

341353
<li><a href="/2020/05/git-%E7%94%9F%E6%88%90%E8%A1%A5%E4%B8%81%E5%92%8C%E6%89%93%E8%A1%A5%E4%B8%81">git 生成补丁和打补丁</a></li>
342354

343-
<li><a href="/2020/03/windwos%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AEmaven">Windwos安装配置maven</a></li>
344-
345-
<li><a href="/2020/02/nginx%E6%97%A5%E5%BF%97">nginx日志</a></li>
346-
347355
</ul>
348356
</div>
349357

@@ -361,7 +369,7 @@ <h2>文章分类</h2>
361369
<span>github</span></a></li>
362370

363371
<li>
364-
<a href="/tag/java" data-toggle="tooltip" data-placement="right" title="2">
372+
<a href="/tag/java" data-toggle="tooltip" data-placement="right" title="4">
365373
<span>java</span></a></li>
366374

367375
<li>

tag/nginx/index.html

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ <h2 class="post_title">标签分类 "nginx&rdquo;</h2>
6464

6565

6666

67+
68+
69+
70+
71+
72+
73+
74+
6775

6876

6977

@@ -478,16 +486,16 @@ <h2 class="post-title">
478486
<h2>近期文章</h2>
479487
<ul>
480488

489+
<li><a href="/2020/11/springmvc%E6%95%B4%E5%90%88thymeleaf">springMVC整合thymeleaf</a></li>
490+
491+
<li><a href="/2020/11/idea%E6%90%AD%E5%BB%BAspringmvc">idea搭建springMVC</a></li>
492+
481493
<li><a href="/2020/10/shiro%E6%B5%8F%E8%A7%88%E5%99%A8%E5%90%8C%E6%97%B6%E7%99%BB%E5%BD%95%E4%B8%A4%E4%B8%AA%E4%B8%8D%E5%90%8C%E7%9A%84%E7%94%A8%E6%88%B7">shiro浏览器同时登录两个不同的用户</a></li>
482494

483495
<li><a href="/2020/10/springmvci%E9%9B%86%E6%88%90shiro-%E5%A4%9A%E8%BA%AB%E4%BB%BD">springMVCi集成shiro(多身份)</a></li>
484496

485497
<li><a href="/2020/05/git-%E7%94%9F%E6%88%90%E8%A1%A5%E4%B8%81%E5%92%8C%E6%89%93%E8%A1%A5%E4%B8%81">git 生成补丁和打补丁</a></li>
486498

487-
<li><a href="/2020/03/windwos%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AEmaven">Windwos安装配置maven</a></li>
488-
489-
<li><a href="/2020/02/nginx%E6%97%A5%E5%BF%97">nginx日志</a></li>
490-
491499
</ul>
492500
</div>
493501

@@ -505,7 +513,7 @@ <h2>文章分类</h2>
505513
<span>github</span></a></li>
506514

507515
<li>
508-
<a href="/tag/java" data-toggle="tooltip" data-placement="right" title="2">
516+
<a href="/tag/java" data-toggle="tooltip" data-placement="right" title="4">
509517
<span>java</span></a></li>
510518

511519
<li>

0 commit comments

Comments
 (0)