FreeMarker与SpringMVC整合实例代码教程
来源:互联网 发布:矩阵qr分解 编辑:程序博客网 时间:2024/05/29 07:48
SpringMVC环境的搭建在这里就不多说了,我们这节主要是FreeMarker与SpringMVC整合
首先,在springmvc的配置文件普通视图之前,加入freemarker的视图
fre-servlet.xml
01
<!-- 一定要放在viewResolver的前面,这样就先去找freemarker的 -->
02
03
<
bean
id
=
"freemarkerConfig"
04
05
class="org.springframework.web.servlet
06
07
.view.freemarker.FreeMarkerConfigurer">
08
09
<
property
name
=
"templateLoaderPath"
value
=
"/WEB-INF/ftl/"
/>
10
11
</
bean
>
12
13
<
bean
id
=
"viewResolver"
14
15
class="org.springframework.web.servlet
16
17
.view.freemarker.FreeMarkerViewResolver">
18
19
<
property
name
=
"cache"
value
=
"true"
/>
20
21
<
property
name
=
"prefix"
value
=
""
/>
22
23
<
property
name
=
"suffix"
value
=
".ftl"
/>
24
25
<
property
name
=
"contentType"
value
=
"text/html; charset=UTF-8"
/>
26
27
</
bean
>
28
29
<
bean
30
31
class="org.springframework.web.servlet
32
33
.view.InternalResourceViewResolver">
34
35
<
property
name
=
"viewClass"
36
37
value
=
"org.springframework.web.servlet.view.JstlView"
/>
38
39
<
property
name
=
"prefix"
value
=
"/WEB-INF/jsp/"
/>
40
41
<
property
name
=
"suffix"
value
=
".jsp"
/>
42
43
</
bean
>
控制器HelloController
01
package org. fre.controller;
02
03
04
05
import org.springframework.stereotype.Controller;
06
07
import org.springframework.ui.Model;
08
09
import org.springframework.web.bind.annotation.RequestMapping;
10
11
12
13
@Controller
14
15
public class HelloController {
16
17
@RequestMapping("/hello")
18
19
public String hello(Model model) {
20
21
model.addAttribute("username", "张三");
22
23
return "hello";
24
25
}
26
27
@RequestMapping("/world")
28
29
public String helloworld(Model model) {
30
31
model.addAttribute("username","李四");
32
33
return "world";
34
35
}
36
37
}
在WEB-INF/jsp目录下有一个world.jsp
01
<%@ page language=
"java"
contentType=
"text/html; charset=UTF-8"
02
03
pageEncoding=
"UTF-8"
%>
04
05
<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"
>
06
07
<html>
08
09
<head>
10
11
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
>
12
13
<title>Insert title here</title>
14
15
</head>
16
17
<body>
18
19
${username }
20
21
</body>
22
23
</html>
在WEB-INF/ftl目录下有
01
<html>
02
03
<head>
04
05
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
>
06
07
<title>Insert title here</title>
08
09
</head>
10
11
<body>
12
13
<h1>${username}</h1>
14
15
</body>
16
17
</html>
启动服务,
访问http://localhost:8080/hello时,显示张三
访问http://localhost:8080/world时,显示李四
到此就整合成功了
0 0
- FreeMarker与SpringMVC整合实例代码教程
- FreeMarker与SpringMVC整合实例代码教程
- FreeMarker与SpringMVC整合实例代码教程
- FreeMarker与SpringMVC整合实例代码教程
- springmvc整合freemarker教程
- FreeMarker与SpringMVC整合
- FreeMarker与SpringMVC整合
- FREEMARKER与SPRINGMVC整合
- freemarker与springmvc整合
- FreeMarker与SpringMVC整合
- SpringMVC与freemarker整合
- springMVC与freemarker整合
- Struts2与Freemarker整合实例
- SpringMVC与Freemarker整合获取request对象
- SpringMVC与Freemarker整合获取request对象
- SpringMVC与Freemarker整合获取request对象
- SpringMVC与Freemarker整合获取request对象
- freemarker与springMvc整合的坑
- 一个数组dataArr,我现在拿到一个对象A,想判断在数组中有没有这个对象A,如果存在则从数组dataArr中删除A,如果不存在则将A加入到数组dataArr中
- Mapreduce中Combiner的使用以及注意点
- 数据结构线性表的两种存储形式顺序表和单链表的比较
- 关于 android 中 postDelayed方法的讲解
- Android App打包自动生成版本号Versin Name与Version Code方法之完美方案
- FreeMarker与SpringMVC整合实例代码教程
- OC学习-block处理
- 百度地图集成
- poj-3267 The Cow Lexicon【dp】
- AccountManager
- OMAPL138upp
- 使用unbound在RHEL7上搭建DNS服务
- 数学符号读法及常用符号英文
- android:inputType常用取值