• SpringMVC配置式开发


    一.PropertiesMethodResolver 属性配置开发

    实体类创建:

    public class Multi extends MultiActionController {
    /*
        public String doFirst(){
            return "First";
        }*/
        public String doFirst(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
            return "First";
        }
    
        public String doSecond(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
            return "Second";
        }
    }

    xml配置:

        <bean id="second" class="day01.Multi">
            <property name="methodNameResolver" ref="propertiesMethod"></property>
        </bean>
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/"></property>
            <property name="suffix" value=".jsp"></property>
        </bean>
        <!--属性配置式开发-->
        <bean id="propertiesMethod" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
            <property name="mappings">
                <props>
                    <prop key="/myfirst">doFirst</prop>
                    <prop key="/mysecond">doSecond</prop>
                </props>
            </property>
        </bean>
      <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="urlMap">
                <map>
                    <entry key="/*" value="second"></entry>
                </map>
            </property>
        </bean>

    web.xml配置:

      <servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    
        <init-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>classpath:springMvcday03properties.xml</param-value>
        </init-param>
    
        <load-on-startup>1</load-on-startup>
      </servlet>
    
      <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/</url-pattern>
      </servlet-mapping>

    二.ParameterMethodResolver 参数方法名解析器

    实体类创建:

    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>
    
        <!--视图解析器-->
        <bean id="beanNameMethod" class="org.springframework.web.servlet.view.BeanNameViewResolver"></bean>
    
        <!--外部资源-->
    <bean id="OutResolver" class="org.springframework.web.servlet.view.RedirectView">
        <property name="url" value="https://www.jd.com"></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>
  • 相关阅读:
    《VR入门系列教程》之21---使用Unity开发GearVR应用
    《VR入门系列教程》之20---使用Oculus移动端SDK
    《VR入门系列教程》之19---GearVR开发初识
    《VR入门系列教程》之18---Oculus代码剖析
    《VR入门系列教程》之17---发布第一个应用
    《VR入门系列教程》之16---第一个OculusVR应用
    阿里巴巴开发手册提取信息
    国富论
    富通天下(W 笔试)
    富通天下(T 面试)
  • 原文地址:https://www.cnblogs.com/1234AAA/p/8640599.html
Copyright © 2020-2023  润新知