`

springmvc view

 
阅读更多
<?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:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:task="http://www.springframework.org/schema/task"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
			http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
            http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
    <!-- 静态资源映射  -->
	<mvc:resources mapping="/static/**" location="/static/" cache-period="172800"/>
	<!-- 注册mapping,class信息等... -->
	<mvc:annotation-driven />
	<!-- 开启aop -->
	<aop:aspectj-autoproxy />
	<!-- 扫描annotation -->
	<context:component-scan base-package="com.easilycms.blog" />

	<!-- 配置拦截器 -->
	<mvc:interceptors>
		<bean class="org.springframework.web.servlet.mvc.WebContentInterceptor">
			<property name="cacheSeconds" value="0" />
			<property name="useExpiresHeader" value="true" />
			<property name="useCacheControlHeader" value="true" />
			<property name="useCacheControlNoStore" value="true" />
			<property name="alwaysUseFullPath" value="true" />
		</bean>
	</mvc:interceptors>

	<!-- 多视图解析 .json .xml -->
	<bean
		class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
		<property name="order" value="1" />
		<!-- 用于开启 /userinfo/123?format=json 的支持 默认是true -->
		<property name="favorParameter" value="false" />
		<!-- 用于关闭 /userinfo/123.json 的支持 默认是true -->
		<property name="favorPathExtension" value="true" />
		<!-- 设置为true以忽略对Accept Header的支持 -->
		<property name="ignoreAcceptHeader" value="true" />
		<!-- 在没有扩展名时即: "/user/1" 时的默认展现形式 -->
		<property name="defaultContentType" value="text/html" />
		<!-- 扩展名至mimeType的映射,即 /user.json => application/json -->
		<property name="mediaTypes">
			<map>
				<entry key="json" value="application/json" />
				<entry key="xml" value="application/xml" />
			</map>
		</property>
		<property name="defaultViews">
	        <list>
	          <ref bean="jsonView" />
	          <ref bean="xmlViewer" />
	        </list>
	    </property>
	</bean>

	<!-- 设置freeMarker的配置文件路径 -->
	<bean id="freemarkerConfiguration"
		class="org.springframework.beans.factory.config.PropertiesFactoryBean">
		<property name="location" value="classpath:freemarker.properties" />
	</bean>

	<!-- 配置freeMarker的模板路径 -->
	<bean id="freemarkerConfig"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
		<property name="freemarkerSettings" ref="freemarkerConfiguration" />
		<property name="templateLoaderPath">
			<value>/</value>
		</property>
		<property name="freemarkerVariables">
			<map>
				<entry key="xml_escape" value-ref="fmXmlEscape" />
			</map>
		</property>
	</bean>

	<bean id="freeMarkerView"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
		<property name="order" value="2" />
		<property name="viewClass"
			value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
		<property name="prefix" value="WEB-INF/ftl/pages/" />
		<property name="suffix" value=".ftl" />
		<property name="contentType" value="text/html; charset=utf-8" />
	</bean>

	<bean name="jsonView"
		class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
		<property name="encoding">
			<value type="org.codehaus.jackson.JsonEncoding">UTF8</value>
		</property>
		<property name="extractValueFromSingleKeyModel" value="true"></property>
		<property name="contentType" value="application/json;charset=UTF-8" />
	</bean>
	
	<bean id="xmlViewer" 
		class="org.springframework.web.servlet.view.xml.MarshallingView">
		<constructor-arg>
		  <bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
			<property name="classesToBeBound">
				<list>
				</list>
			</property>
		  </bean>
		</constructor-arg>
		<property name="contentType" value="application/xml;charset=UTF-8" />
	</bean>
	
	<!-- 文件上传 -->
	<bean id="multipartResolver"
          class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!--1024**1024*5即5M-->
        <property name="maxUploadSize" value="5242880"/>
    </bean>

	<bean id="fmXmlEscape" class="freemarker.template.utility.XmlEscape" />
</beans>

 

分享到:
评论

相关推荐

    springMVC 多视图配置(Jsp Freemarket Json)实例

    springMVC 多视图配置(Jsp Freemarket Json)实例

    SpringMVC-Spring-Maven 登录、model、view实例

    不需要数据库交互,包括登录验证功能,以及Model/ModelMap/Map/ModelAndView与页面交互

    springMVC4-rest-jackson-jsonview-annotation.zip

    分享一个使用SpringMVC4 Rest 和Jackson的@JsonView注解集成的实例。@JsonView用来过滤JSON响应。Spring4.1开始直接支持@JsonView注解。要使用@JsonView,首先我们需要定义视图,我们可以定义多个视图。一个视图定义...

    springmvc第一天.pdf

    SpringMVC 是一种基于 Java 的实现 MVC 设计模型的请求驱动类型的轻量级 Web 框架, 属于 Spring FrameWork 的后续产品,已经融合在 Spring Web Flow 里面。Spring 框架提供了构建 Web 应用程序的全功 能 MVC 模块。...

    ext + spring Json view + springMVC + Freemaker

    ext + spring Json view + springMVC + Freemaker

    Spring SpringMVC 简单整合

    SpringMVC流程 1、 用户发送请求至前端控制器DispatcherServlet。 2、 DispatcherServlet收到请求调用HandlerMapping处理器映射器。 3、 处理器映射器找到具体的处理器(可以根据xml配置、注解进行查找),生成...

    springmvc关于modelAndView的使用详细

    关于springmvc中的ModelAndView的详细代码,可以更好的了解spring。

    springmvc开发资料

    SpringMVC流程 1、 用户发送请求至前端控制器DispatcherServlet。 2、 DispatcherServlet收到请求调用HandlerMapping处理器映射器。 3、 处理器映射器找到具体的处理器(可以根据xml配置、注解进行查找),生成...

    springmvc demo

    应用控制器其实拆为处理器映射器(Handler Mapping)进行处理器管理和视图解析器(View Resolver)进行视图管理;页面控制器/动作/处理器为Controller接口(仅包含ModelAndView handleRequest(request, response) 方法)...

    SpringMvc源码

    应用控制器其实拆为处理器映射器(Handler Mapping)进行处理器管理和视图解析器(View Resolver)进行视图管理;页面控制器/动作/处理器为Controller接口(仅包含ModelAndView handleRequest(request, response) 方法)...

    springmvc-json-view需要的jar

    json-lib-2.4-jdk15.jar commons-lang-2.6.jar commons-beanutils.jar

    SpringMVC实例

    4、SpringMVC是真正的View层实现无关的,它不会强制开发员使用JSP,我们可以使用其他View技术,比如Velocity,Xskt等。 5、国际化支持,Spring的ApplicationContext提供了对国际化的支持,在这里可以很方便的使用。 6...

    springmvc maven最简配置helloword实例 三页面跳转带log日志

    springmvc maven最简配置helloword实例 带三个简单页面的跳转,还有log日志。 用tomcat7运行,(注意:把index.jsp复制到WEB-INF/view 文件夹下)

    spring+springmvc+mybatis的整合

    [java] view plain copy WebApplicationContext acc = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getServletContext()); ls = (LoginService) acc.getBean("MyService"); 而讲义上的...

    SpringMVC示例

    注解)、ModelAttribute注解如修饰POJO类型的入参、SessionAttributes注解引发的异常处理、JstlView、mvc_view-controller标签转换成注解、自定义视图、重定向、Employee管理RESTRUL_CRUD_显示所有 员工信息、...

    springMVC入门_Java系列教程

    Spring MVC是结构最清晰的MVC Model 2实现。...但在其它的Web Framework中,Action返回值一般都只是一个View Name;Model则需要通过其它的途径(如request.attribute,Context参数,或Action本身的属性数据)传递上去。

    SpringMVC学习指南.pdf

    Spring MVC是Spring框架中用于Web应用快速开发的一个模块,其中的MVC是Model-View-Controller的缩写。作为当今业界*主流的Web开发框架,Spring MVC已经成为当前*热门的开发技能,同时也广泛用于桌面开发领域。  ...

    SpringMVC4教程-超权威__超详细

    SpringMVC4教程-超权威__超详细,

    SpringMVC最基础配置

    用eclipse写的最简单的一个SpringMVC项目 在web.xml中配置servlet 创建Springmvc的xml配置文件spring-servlet.xml 创建Controller和view,dao,servlet

    SpringMVC+Mybatis+Maven 纯XML配置

    1,搭建SpringMVC 2,加载properties配置文件 3,集成mybatis 4,配置事务 5,另一种配置springMVC的方式 6,自定义(扩展)mvc配置 7,解决@ResponseBody return String的...9,配置ViewControllers 10,配置filter 11,配置拦截器

Global site tag (gtag.js) - Google Analytics