Spring MVC-XML视图解析器
XmlViewResolver-servlet.xml 配置如下所示
<bean class="org.springframework.web.servlet.view.XmlViewResolver">
<property name="location">
<value>/WEB-INF/views.xml</value>
</property>
</bean>
views.xml 配置如下所示
<bean id="hello"
class="org.springframework.web.servlet.view.JstlView">
<property name="url" value="/WEB-INF/jsp/hello.jsp" />
</bean>
Spring MVC资源绑定视图解析器
ResourceBundleViewResolver-servlet.xml
<!--资源绑定视图解析器-->
<bean class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
<property name="basename" value="views" />
</bean>
views.properties
hello.(class)=org.springframework.web.servlet.view.JstlView hello.url=/WEB-INF/views/hello.jsp
Spring MVC多解析器映射
MultipleResolver-servlet.xml
bean class="org.springframework.web.servlet.view.ResourceBundleViewResolver"> <property name="basename" value="views" /> <property name="order" value="0" /> </bean> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> <property name="order" value="1" /> </bean>
这里order
属性定义了视图解析器的排序。0
作为第一解析器,1
作为下一解析器,等等
views.properties
hello.(class)=org.springframework.web.servlet.view.JstlView hello.url=/WEB-INF/jsp/hello.jsp