• 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
        }
    
    }
    

      

  • 相关阅读:
    Node.js github开源代码
    Node.js Base64 Encoding和Decoding
    图论500题
    gvim中的gvimrc和vimrc
    ubuntu 命令行卸载并清理软件
    vim复制到系统剪贴板
    Electron 主进程与渲染进程之间的通 信(同步通信、异步通信)
    Android 使用系统录制视频功能
    Electron 自定义软件顶部菜单、右键菜单以及绑定快捷键
    Electron remote 模块、通过 BrowserWindow 打开新窗口
  • 原文地址:https://www.cnblogs.com/xuchangqi1/p/8641071.html
Copyright © 2020-2023  润新知