SpringMVC(二四) 檢視解析流程
阿新 • • 發佈:2018-12-18
目標方法無論返回的是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>