SpringMvc使用Freemarker时的配置文件
来源:互联网 发布:mac 蓝牙鼠标漂移 编辑:程序博客网 时间:2024/05/24 07:28
一、在使用Freemarker 时,需要在springmvc-servlet.xml 配置文件中作如下配置:
- <?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:mvc="http://www.springframework.org/schema/mvc"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.2.xsd
- http://www.springframework.org/schema/mvc
- http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
- <!-- 组件自动扫描 -->
- <context:component-scan base-package="com.tliu.case2.web"/>
- <!--主要作用于@Controller激活该模式下面是一种简写形式
- 它会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter,
- 是spring MVC为@Controllers分发请求所必须的 -->
- <mvc:annotation-driven/>
- <!-- 配置JSON视图 -->
- <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
- <property name="supportedMediaTypes">
- <list>
- <value>application/json;charset=UTF-8</value>
- </list>
- </property>
- <property name="objectMapper">
- <bean class="org.codehaus.jackson.map.ObjectMapper">
- <property name="dateFormat">
- <bean class="java.text.SimpleDateFormat">
- <constructor-arg index="0" type="java.lang.String" value="yyyy-MM-dd HH:mm:ss"/>
- </bean>
- </property>
- </bean>
- </property>
- </bean>
- <bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter"/>
- <bean id="requestMappingHandlerAdapter" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
- <property name="messageConverters">
- <list>
- <ref bean="mappingJacksonHttpMessageConverter"/>
- <ref bean="stringHttpMessageConverter"/>
- </list>
- </property>
- </bean>
- <!-- 配置JSP视图 -->
- <bean id="internalResourceViewResolver" 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"/>
- <property name="contentType" value="text/html;charset=UTF-8"/>
- <property name="order" value="1"/>
- </bean>
- <!-- 配置FreeMark视图 -->
- <bean id="freeMarkerViewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
- <property name="contentType" value="text/html;charset=UTF-8"/>
- <property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView"/>
- <property name="suffix" value=".ftl"/>
- <property name="cache" value="true"/>
- <property name="exposeSessionAttributes" value="true"/>
- <property name="exposeRequestAttributes" value="true"/>
- <property name="exposeSpringMacroHelpers" value="true"/>
- <!-- 在页面中使用${rc.contextPath}就可获得contextPath -->
- <property name="requestContextAttribute" value="rc"/>
- <property name="order" value="0"/>
- </bean>
- <bean id="freemarkConfig" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
- <property name="location" value="classpath:freemark.properties"/>
- </bean>
- <bean id="fmXmlEscape" class="freemarker.template.utility.XmlEscape"/>
- <bean id="FreeMarkerConfigurer" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
- <property name="templateLoaderPath" value="/WEB-INF/ftl/"/>
- <property name="defaultEncoding" value="UTF-8"/>
- <property name="freemarkerSettings" ref="freemarkConfig"/>
- <property name="freemarkerVariables">
- <map>
- <entry key="xml_escape" value-ref="fmXmlEscape"/>
- </map>
- </property>
- </bean>
- <!-- 文件上传配置注意:这里申明的id必须为multipartResolver -->
- <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
- <property name="maxUploadSize" value="500000"/>
- </bean>
- <!-- 简单的异常处理 -->
- <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
- <property name="exceptionMappings">
- <props>
- <!-- 映射目录为/WEB-INF/jsp/error/upload_error.jsp -->
- <prop key="org.springframework.web.multipart.MaxUploadSizeExceededException">/error/upload_error</prop>
- </props>
- </property>
- </bean>
- <!-- 对静态资源文件的访问 -->
- <mvc:resources mapping="/images/**" location="/images/" cache-period="31556926"/>
- <mvc:resources mapping="/js/**" location="/js/" cache-period="31556926" />
- <mvc:resources mapping="/css/**" location="/css/" cache-period="31556926" />
- <mvc:resources mapping="/upload/**" location="/upload/" cache-period="31556926" />
- </beans>
该文件中的freemarker.properties文件配置内容如下:
- #FreeMarker settings:
- #0 is for development only! Use higher value otherwise.
- template_update_delay=0
- locale=zh_CN
- default_encoding=UTF-8
- number_format=0.##########
- date_format=yyyy-MM-dd
二、在该文件中,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"
- xmlns:util="http://www.springframework.org/schema/util"
- xmlns:mvc="http://www.springframework.org/schema/mvc"
- xsi:schemaLocation="
- http://www.springframework.org/schema/util
- http://www.springframework.org/schema/util/spring-util-3.1.xsd
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.1.xsd
- http://www.springframework.org/schema/mvc
- http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd" >
- <!-- 开启注解 -->
- <mvc:annotation-driven />
- <!-- 扫描包 -->
- <context:component-scan base-package="com.misl.*" />
- <!-- FreeMarker settings -->
- <bean id="freeMarkerConfigurer" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
- <property name="templateLoaderPath" value="" />
- <property name="freemarkerSettings">
- <props>
- <prop key="template_update_delay">0</prop>
- <prop key="default_encoding">UTF-8</prop>
- <prop key="locale">zh_CN</prop>
- </props>
- </property>
- </bean>
- <!-- FreeMarker view Reslover -->
- <bean id="freeMarkerViewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
- <property name="cache" value="false" />
- <property name="prefix" value="/WEB-INF/views/" />
- <property name="suffix" value=".ftl" />
- <property name="contentType" value="text/html;charset=UTF-8" />
- </bean>
- </beans>
0 0
- SpringMvc使用Freemarker时的配置文件
- SpringMvc使用Freemarker时的配置文件
- SpringMVC+FreeMarker的使用
- SpringMVC + Freemarker 模版的使用
- springMVC整合freemarker的使用
- springmvc整合freemarker时,freemarker使用include的根路径的问题
- Freemarker使用教程-基于Springmvc的Freemarker实例
- SpringMVC的架设,使用Freemarker模板引擎
- SpringMVC + freemarker使用
- springmvc使用freemarker
- 【Freemarker】SpringMVC使用Freemarker作为视图解析
- SpringMVC+Maven+FreeMarker+MyBatis 使用
- Ibatis +Springmvc+Freemarker+Dwr 搭建之后的使用
- springmvc freemarker 之间的传参问题练习 出问题出现在配置文件上
- 使用springMVC框架的相关配置文件
- 使用maven进行springmvc+hibernate的配置文件
- springmvc+freemarker的简单demo
- springmvc+freemarker的简单demo
- 欢迎使用CSDN-markdown编辑器
- 腾讯云主机中MySQL无法远程连接的解决办法
- vscode几个常用插件推荐[补充]
- CURL模拟提交数据,TP暴力版
- PHP学习笔记——PHP变量的范围;
- SpringMvc使用Freemarker时的配置文件
- Struts2配置时报struts-default.xml:65:72异常的解决方法
- css + js实现简单无缝滚动字幕
- ruby transaction(交易)
- Spring Data JPA 系列 —— 两张表(多对多关联,关联表带扩展字段)
- 7805(一)
- 操作系统面试题总结
- 使用Vue.js制作仿Metronic高级表格(一)静态设计
- java 泛型详解