BeanNameViewResolver自定义视图解析器

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
    }

}

  

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

木易学长~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值