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>