SpringMVC(二四) 视图解析流程

目标方法无论返回的是string、ModelAndView、View,最终都被解析成modelAndView

关键的实现代码是在springmvc.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.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd">
    
<!--  配置自动扫描包 -->    
<context:component-scan base-package="com.tiekui.springmvc.handlers"></context:component-scan>

<!-- 配置视图解析器:如何把handler方法返回给视图 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/"></property>
    <property name="suffix" value=".jsp"></property>
</bean>

</beans>
复制代码

猜你喜欢

转载自www.cnblogs.com/yuyu666/p/10136112.html
今日推荐