spring mvc整合freemarker基于注解方式
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<!-- 針對(duì)freemarker的視圖配置 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="order" value="5" />
<property name="suffix" value=".ftl" />
<property name="contentType" value="text/html;charset=UTF-8" />
</bean>
<bean id="freemarkerConfig"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF/view/" />
<property name="freemarkerSettings">
<props>
<prop key="template_update_delay">0</prop>
<prop key="default_encoding">UTF-8</prop>
<prop key="number_format">0.##########</prop>
<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
<prop key="classic_compatible">true</prop>
<prop key="template_exception_handler">ignore</prop>
</props>
</property>
</bean>
Controller建立
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class SpringMvcController {
@RequestMapping(value="/welcome",method={RequestMethod.GET})
public ModelAndView getFirstPage(HttpServletRequest request) {
//welcom就是視圖的名稱(welcom.ftl)
ModelAndView mv = new ModelAndView("welcom");
mv.addObject("name", "My First Spring Mvc");
return mv;
}
}
在url上敲http://localhost:8080/welcome就會(huì)到WEB-INF/view/welcom.ftl頁(yè)面渲染數(shù)據(jù)
welcom.ftl頁(yè)面
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Hello ${name}
</body>
</html>
頁(yè)面出來(lái)的效果:
Hello My First Spring Mvc
- 使用SpringBoot注解方式處理事務(wù)回滾實(shí)現(xiàn)
- spring boot注解方式使用redis緩存操作示例
- Spring AOP如何整合redis(注解方式)實(shí)現(xiàn)緩存統(tǒng)一管理詳解
- Spring 使用注解方式進(jìn)行事務(wù)管理配置方式
- Spring-MVC異步請(qǐng)求之Servlet異步處理
- springmvc處理異步請(qǐng)求的示例
- 詳解spring mvc對(duì)異步請(qǐng)求的處理
- SpringMVC環(huán)境下實(shí)現(xiàn)的Ajax異步請(qǐng)求JSON格式數(shù)據(jù)
- Spring中注解方式的異步請(qǐng)求
相關(guān)文章
ASP.NET2.0中數(shù)據(jù)源控件之異步數(shù)據(jù)訪問(wèn)
ASP.NET2.0中數(shù)據(jù)源控件之異步數(shù)據(jù)訪問(wèn)...2006-09-09
動(dòng)態(tài)指定任意類型的ObjectDataSource對(duì)象的查詢參數(shù)
我在使用ObjectDataSource控件在ASP.NET中實(shí)現(xiàn)Ajax真分頁(yè) 一文中詳細(xì)介紹過(guò)如何使用ObjectDataSource和ListView實(shí)現(xiàn)數(shù)據(jù)綁定和分頁(yè)功能。事實(shí)上,采用ObjectDataSource和ListView相結(jié)合,可以減少我們很多的開(kāi)發(fā)任務(wù)。2009-11-11
3分鐘快速學(xué)會(huì)在ASP.NET Core MVC中如何使用Cookie
這篇文章主要給大家介紹了關(guān)于如何通過(guò)3分鐘快速學(xué)會(huì)在ASP.NET Core MVC中使用Cookie的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用ASP.NET具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
淺析Repeater控件的使用 (原樣導(dǎo)出和動(dòng)態(tài)顯示/隱藏Repeater中的列)
本文主要介紹了淺析Repeater控件的使用 (原樣導(dǎo)出和動(dòng)態(tài)顯示/隱藏Repeater中的列)的具體方法,需要的朋友可以看下2016-12-12
如何在ASP.NET Core中給上傳圖片功能添加水印實(shí)例代碼
這篇文章主要給大家介紹了關(guān)于如何在ASP.NET Core中給上傳圖片功能添加水印的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-02-02
ASP.NET 廣告控件AdRotator的使用方法與實(shí)例
廣告控件是asp.net中一個(gè)獨(dú)有的東西,他可以利用asp.net來(lái)生成廣告控件所需的xml文檔,然后再利用AdRotator來(lái)調(diào)用廣告xml文件,根據(jù)我們的參考進(jìn)行顯示2013-08-08
Asp.Net Core中基于Session的身份驗(yàn)證的實(shí)現(xiàn)
這篇文章主要介紹了Asp.Net Core中基于Session的身份驗(yàn)證的實(shí)現(xiàn)2018-09-09

