码迷,mamicode.com
首页 > 其他好文 > 详细

BeanNameViewResolver自定义视图解析器

时间:2018-03-24 20:41:04      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:解析   body   处理器   视图   jstl   gpo   ref   post   red   

RedirectView:定义外部资源视图对象

JstlView:定义内部资源视图对象

 

使用自定义视图解析器

 

<?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:tx="http://www.springframework.org/schema/tx" 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.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">


    <!--///////////////////////////////////////////////////////////////////////////////////-->
    <!--方式三:参数方法名解析器-->
   <bean id="methodNameResolver" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
       <property name="paramName" value="actionName"/>
   </bean>

    <!--视图解析器BeanNameViewResolver-->
    <bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
    <!--定义内部资源试图对象-->
   <bean id="Inner" class="org.springframework.web.servlet.view.JstlView">
       <property name="url" value="/index.jsp"/>
   </bean>

    <!--定义外部资源视图对象-->
    <bean id="jd" class="org.springframework.web.servlet.view.RedirectView">
        <property name="url" value="https://www.jd.com"/>
    </bean>

    <!--处理器映射-->
    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="urlMap">
            <map>
                <entry key="/hello" value="multiActionController"/>
            </map>
        </property>
    </bean>

    <!--处理器-->
    <bean id="multiActionController" class="cn.happy.day04BeanNameViewResolver.MyMultiActionController">
        <property name="methodNameResolver" ref="methodNameResolver"/>
    </bean>


</beans>

  实体类

package cn.happy.day04BeanNameViewResolver;

import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


//自定义视图解析器
public class MyMultiActionController extends MultiActionController {

    //自定义两个方法
    public String doFirst(HttpServletRequest request,HttpServletResponse response){
        return "jd";//定义外部资源视图id
    }

    public String doSecond(HttpServletRequest request,HttpServletResponse response){
        return "Inner";//返回内部资源视图id
    }

}

  

 

BeanNameViewResolver自定义视图解析器

标签:解析   body   处理器   视图   jstl   gpo   ref   post   red   

原文地址:https://www.cnblogs.com/xuchangqi1/p/8641071.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!