FreeMarker与SpringMVC整合
来源:互联网 发布:淘宝旗舰店多少钱 编辑:程序博客网 时间:2024/05/17 14:18
FreeMarker与SpringMVC整合
摘要: SpringMVC环境的搭建在这里就不多说了,我们这节主要是FreeMarker与SpringMVC整合 首先,在springmvc的配置文件普通视图之前,加入freemarker的视图...
SpringMVC环境的搭建在这里就不多说了,我们这节主要是FreeMarker与SpringMVC整合
首先,在springmvc的配置文件普通视图之前,加入freemarker的视图
fre-servlet.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!-- 一定要放在viewResolver的前面,这样就先去找freemarker的 -->
<
bean
id
=
"freemarkerConfig"
class="org.springframework.web.servlet
.view.freemarker.FreeMarkerConfigurer">
<
property
name
=
"templateLoaderPath"
value
=
"/WEB-INF/ftl/"
/>
</
bean
>
<
bean
id
=
"viewResolver"
class="org.springframework.web.servlet
.view.freemarker.FreeMarkerViewResolver">
<
property
name
=
"cache"
value
=
"true"
/>
<
property
name
=
"prefix"
value
=
""
/>
<
property
name
=
"suffix"
value
=
".ftl"
/>
<
property
name
=
"contentType"
value
=
"text/html; charset=UTF-8"
/>
</
bean
>
<
bean
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
name
=
"suffix"
value
=
".jsp"
/>
</
bean
>
控制器HelloController
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package
org. fre.controller;
import
org.springframework.stereotype.Controller;
import
org.springframework.ui.Model;
import
org.springframework.web.bind.annotation.RequestMapping;
@Controller
public
class
HelloController {
@RequestMapping
(
"/hello"
)
public
String hello(Model model) {
model.addAttribute(
"username"
,
"张三"
);
return
"hello"
;
}
@RequestMapping
(
"/world"
)
public
String helloworld(Model model) {
model.addAttribute(
"username"
,
"李四"
);
return
"world"
;
}
}
在WEB-INF/jsp目录下有一个world.jsp
1
2
3
4
5
6
7
8
9
10
11
12
<%@ page language=
"java"
contentType=
"text/html; charset=UTF-8"
pageEncoding=
"UTF-8"
%>
<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"
>
<html>
<head>
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
>
<title>Insert title here</title>
</head>
<body>
${username }
</body>
</html>
在WEB-INF/ftl目录下有
1
2
3
4
5
6
7
8
9
<
html
>
<
head
>
<
meta
http-equiv
=
"Content-Type"
content
=
"text/html; charset=UTF-8"
>
<
title
>Insert title here</
title
>
</
head
>
<
body
>
<
h1
>${username}</
h1
>
</
body
>
</
html
>
启动服务,
访问http://localhost:8080/hello时,显示张三
访问http://localhost:8080/world时,显示李四
到此就整合成功了
- FreeMarker与SpringMVC整合
- FreeMarker与SpringMVC整合
- FREEMARKER与SPRINGMVC整合
- freemarker与springmvc整合
- FreeMarker与SpringMVC整合
- SpringMVC与freemarker整合
- springMVC与freemarker整合
- SpringMVC与Freemarker整合获取request对象
- SpringMVC与Freemarker整合获取request对象
- FreeMarker与SpringMVC整合实例代码教程
- SpringMVC与Freemarker整合获取request对象
- FreeMarker与SpringMVC整合实例代码教程
- FreeMarker与SpringMVC整合实例代码教程
- FreeMarker与SpringMVC整合实例代码教程
- SpringMVC与Freemarker整合获取request对象
- freemarker与springMvc整合的坑
- Freemarker整合SpringMVC与JSP配置详解
- FreeMarker+JSP+SpringMVC整合
- Uva10970 Big Chocolate
- 斯坦福大学机器学习课程讲义
- java中的定时器以及schedule和scheduleAtFixedRate方法的探究
- 技术人员如何创业
- c语言内存占用区域,以及详解
- FreeMarker与SpringMVC整合
- linux网络嗅探器
- 鼠标点击物体使其消失
- android支付宝接入(一)
- PHP漏洞全解(五)-SQL注入攻击
- win7_oracle11g_64位连接32位PLSQL_Develop
- javascript符号的各种意义
- 堆栈的深度理解
- how to design a 2D game map?