zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    topcoder SRM 592 DIV2 LittleElephantAndBooks
    codeforces round #201 Div2 A. Difference Row
    Codeforces Round #199 (Div. 2) A Xenia and Divisors
    objective-c "performSelector may cause a leak because its selector is unknown".
    ccrendertexture to uiimage
    TopCoder SRM 588 DIV2 KeyDungeonDiv2
    ios clang: error: linker command failed with exit code 1 (use -v to see invocation)解决方法
    c++ for_each()与仿函数
    c++ map删除元素
    c++ map和mutimaps 插入值
  • 原文地址:https://www.cnblogs.com/1234AAA/p/8640599.html
Copyright © 2011-2022 走看看