SpringMVC 解析器
来源:互联网 发布:编写c语言的步骤 编辑:程序博客网 时间:2024/06/10 00:27
AbstractController
先创建一个MyAbstorctController类,并且让他继承AbstractController父类,并实现该父类中的方法.
public class MyAbstorctController extends AbstractController{ protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { ModelAndView mv=new ModelAndView(); mv.setViewName("index"); return mv; }}
abstorctcontroller.xml配置
<!--处理器映射器--> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="urlMap"> <map> <entry key="/hello.do" value="fistController"></entry> </map> </property> </bean> <!--注册处理器--><!--<bean id="/hello.do" class="cn.happy.controller.Onecontriller"></bean>--> <bean id="fistController" class="cn.happy.controller.MyAbstorctController"> <property name="supportedMethods"> <set> <value>POST</value> <value>GET</value> </set> </property> </bean> <!--视图解析器--><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/"></property><property name="suffix" value=".jsp"></property></bean>
MultiActionController类的实现方式有三种:
首先创建MyMutiActionController类并继承MultiActionController类,自定义方法名
public class MyMutiActionController extends MultiActionController { public ModelAndView insert(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { ModelAndView mv=new ModelAndView(); mv.setViewName("insert"); return mv; } public ModelAndView delete(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { ModelAndView mv=new ModelAndView(); mv.setViewName("delete"); return mv; }}(一)multiactioncontroller.xml配置,默认的方法解析器
<!--处理器映射器--><bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="urlMap"> <map> <entry key="/*.do" value="mutiactioncontroller"></entry> </map> </property></bean> <!--注册处理器--> <bean id="mutiactioncontroller" class="cn.happy.controller.MyMutiActionController"> </bean> <!--视图解析器--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/"></property> <property name="suffix" value=".jsp"></property> </bean>(二)propertiesMrthodNameresolver.xml配置<!--处理器映射器--> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="urlMap"> <map> <entry key="/*.do" value="mutiactioncontroller"></entry> </map> </property> </bean><!--属性方法名称解析器--> <bean id="propertyNameResoler" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver"> <property name="mappings"> <props> <prop key="/first.do">insert</prop> <prop key="/second.do">delete</prop> </props> </property> </bean> <!--注册处理器--> <bean id="mutiactioncontroller" class="cn.happy.controller.MyMutiActionController"> <property name="methodNameResolver" ref="propertyNameResoler"></property> </bean> <!--视图解析器--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/"></property> <property name="suffix" value=".jsp"></property> </bean>(三)propeterMrthodNameresolver.xml配置,参数方法解析器
<!--处理器映射器--> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="urlMap"> <map> <entry key="/hello.do" value="mutiactioncontroller"></entry> </map> </property> </bean><!--属性方法名称解析器--> <bean id="properterNameResoler" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver"> <property name="paramName" value="actionName"></property> </bean> <!--注册处理器--> <bean id="mutiactioncontroller" class="cn.happy.controller.MyMutiActionController"> <property name="methodNameResolver" ref="properterNameResoler"></property> </bean> <!--视图解析器--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/"></property> <property name="suffix" value=".jsp"></property> </bean>视图解析器:先创建一个MyViewResoler类,并继承MultiActionController类,自定义两个方法名。public class MyViewResoler extends MultiActionController { public ModelAndView insert(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { ModelAndView mv=new ModelAndView(); mv.setViewName("innserView"); return mv; } public ModelAndView inserts(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { ModelAndView mv=new ModelAndView(); mv.setViewName("jd"); return mv;}}创建ViewResoler.xml配置
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd "> <!--处理器映射器--> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="urlMap"> <map> <entry key="/hello.do" value="mutiactioncontroller"></entry> </map> </property> </bean><!--属性方法名称解析器--> <bean id="properterNameResoler" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver"> <!-- <property name="paramName" value="actionName"></property>--> </bean> <bean id="propertyNameResoler" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver"> <property name="mappings"> <props> <prop key="/first.do">insert</prop> <prop key="/second.do">delete</prop> </props> </property> </bean> <!--内部视图对象--> <bean id="innserView" class="org.springframework.web.servlet.view.JstlView"> <property name="url" value="/WEB-INF/index.jsp"></property> </bean> <!--外部视图对象--> <bean id="jd" class="org.springframework.web.servlet.view.RedirectView"> <property name="url" value="https://www.jd.com7"></property> </bean> <!--BeanName视图解析器--> <bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/> <!--注册处理器--><bean id="mutiactioncontroller" class="cn.happy.controller.MyViewResoler"><property name="methodNameResolver" ref="properterNameResoler"></property></bean></beans>
阅读全文
0 0
- SpringMVC视图解析器
- SpringMVC视图解析器
- SpringMVC视图解析器
- SpringMVC视图解析器
- SpringMVC视图解析器
- SpringMVC视图解析器
- SpringMVC视图解析器
- SpringMVC视图解析器
- springMVC视图解析器
- SpringMVC视图解析器
- SpringMVC视图解析器
- SpringMVC视图解析器
- SpringMVC 视图解析器
- SpringMVC视图解析器
- SpringMVC视图解析器
- SpringMVC视图解析器
- SpringMVC解析器
- SpringMVC视图解析器
- java基础第十五天 集合
- java数据类型
- 数模培训记录
- SpringMVC 第二种 方式例子
- Spring和MyBatis的整合的查询小案例
- SpringMVC 解析器
- SpringMVC 内外部视图
- Python基础07 函数
- Javascript—if...else语句
- Spring静态页面无法访问解决方案
- vim快捷键整理大全
- 【poj-2406-powerstring】(KMP)
- spring配置数据源的四种方式
- HandlerMapping和BeanNameUrlHandlerMapping的使用