在使用springmvc集成jsp和freemarker时,我们要在spriingmvc的配置文件中同时配置sp的解析器和freemarker的解析器,同时解析器order属性(order越小,优先级别越高),指定视图的解析优先级,于是配置如下:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<mvc:annotation-driven></mvc:annotation-driven>
<context:component-scan base-package="com.lyl.controller"></context:component-scan>
<!-- jsp视图解析器 -->
<bean id="jspViewResolver" 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="order" value="1"></property>
<property name="cache" value="false"></property>
</bean>
<!-- FreeMarker环境配置 -->
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<!-- freemarker模板位置 -->
<property name="templateLoaderPath" value="/WEB-INF/freemarker/"/>
</bean>
<!-- FreeMarker视图解析 -->
<bean id="freeMarkerViewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="cache" value="true"/>
<property name="prefix" value="/"/>
<property name="suffix" value=".xhtml"/>
<property name="order" value="0"></property>
</bean>
</beans>
红色字体部分,需要注意,一定要设置freemarker的优先级别高于jsp,这样当找不到相应的freemarker页面时,还会继续找jsp页面,否则,当jsp页面不存在,会报404错误!
相关推荐
springMVC 多视图配置(Jsp Freemarket Json)实例
SpringMVC自定义多视图,多视图实现
springMVC配置好的环境
配置多数据源、SpringMVC框架下多数据源的配置问题、如何在同一个项目中使用多个数据库、如果在同一个项目中使用不同的数据库。
springmvc 3.1 多视图,freemarker jsp
SpringMVC配置文件 SpringMVC配置文件 SpringMVC配置文件
springMVC配置、注解、列子
springmvc 配置文件 纯配置文件 主要供自己使用
SpringMVC-配置文档以及其中的说明。 包含使用注解、扫描带注解的包 、使用注解方式配置springMVC的映射器和适配器
springmvc配置webservice服务的例子,下载直接可以运行,可以参考java的webservice服务的配置
这是SpringMVC的2019配置,最近需要做一个项目配置的原始环境,可以运行,简单配置的修改,大家应该自己能懂,里面需要的jar包,都存在了,写了一个简单的首页,调用bootstrap,jquery风格,需要的同学,自己下载吧。
主要包含springmvc的基本配置内容,及spring定时任务quartz的配置与动态修改。
spring springmvc jpa配置文件 内容详细简单易懂 可直接使用
SpringMVC 使用JSON、XML视图,json-lib jackson,xstream castor,jibx jaxb2
SpringMVC核心配置文件示例.rar
SpringMVC配置项目
SpringMVC一些配置文件的demo
springMVC最简单的配置,springMVC最简单的配置,springMVC最简单的配置
springmvc maven配置,里面有步骤,按照步骤搭建。
Springmvc配置约束