默认的BeanNameViewResolver
RedirectView 外部资源视图解析器
实体类创建如下:
public class BeanNameResolvetTest extends MultiActionController { /* public String doFirst(){ return "First"; }*/ public String doFirst(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { return "InnerReslover"; } public String doSecond(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { return "OutResolver"; } }
xml的配置:
<bean id="second" class="day05.BeanNameResolvetTest"> <property name="methodNameResolver" ref="paramMethod"></property> </bean> <!--xml视图解析器--> <bean id="beanNameMethod" class="org.springframework.web.servlet.view.XmlViewResolver"> <property name="location" value="classpath:myView.xml"></property> </bean> <!--外部资源--> <bean id="OutResolver" class="org.springframework.web.servlet.view.RedirectView"> <property name="url" value="https://www.jd.com"></property> </bean> <!--参数配置式开发--> <bean id="paramMethod" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver"> <property name="paramName" value="actionName"></property> </bean> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="urlMap"> <map> <entry key="/doFirst" value="second"></entry> </map> </property> </bean>
JstlView 内部资源视图解析器
实体类创建:
public class BeanNameResolvetTest extends MultiActionController { /* public String doFirst(){ return "First"; }*/ public String doFirst(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { return "InnerReslover"; } public String doSecond(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { return "OutResolver"; } }
xml配置:
<bean id="second" class="day05.BeanNameResolvetTest"> <property name="methodNameResolver" ref="paramMethod"></property> </bean> <!--xml视图解析器--> <bean id="beanNameMethod" class="org.springframework.web.servlet.view.XmlViewResolver"> <property name="location" value="classpath:myView.xml"></property> </bean> <!--内部资源--> <bean id="InnerReslover" class="org.springframework.web.servlet.view.JstlView"> <property name="url" value="/Second.jsp"></property> </bean> <!--参数配置式开发--> <bean id="paramMethod" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver"> <property name="paramName" value="actionName"></property> </bean> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="urlMap"> <map> <entry key="/doFirst" value="second"></entry> </map> </property> </bean>
XmlViewResolver视图解析器
可以分离庞大的主配置文件的信息到多个小文件,方便主配置文件的管理和使用
具体实现功能代码如下:
实体类:
public class BeanNameResolvetTest extends MultiActionController { /* public String doFirst(){ return "First"; }*/ public String doFirst(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { return "InnerReslover"; } public String doSecond(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { return "OutResolver"; } }
xml配置:
<bean id="second" class="day05.BeanNameResolvetTest"> <property name="methodNameResolver" ref="paramMethod"></property> </bean> <!--xml视图解析器--> <bean id="beanNameMethod" class="org.springframework.web.servlet.view.XmlViewResolver"> <property name="location" value="classpath:myView.xml"></property> </bean> <!--参数配置式开发--> <bean id="paramMethod" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver"> <property name="paramName" value="actionName"></property> </bean> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="urlMap"> <map> <entry key="/doFirst" value="second"></entry> </map> </property> </bean>