Spring MVC ParameterMethodNameResolver example
来源:互联网 发布:java兼职平台 编辑:程序博客网 时间:2024/05/19 19:55
ParameterMethodNameResolver
, a MultiActionController
method name resolver to map URL to method name via request parameter name, and the parameter name is customizable through the “paramName
” property. See following example :
1. MultiActionController
A MultiActionController
example.
package com.mkyong.common.controller;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.web.servlet.ModelAndView;import org.springframework.web.servlet.mvc.multiaction.MultiActionController;public class CustomerController extends MultiActionController{ public ModelAndView add(HttpServletRequest request, HttpServletResponse response) throws Exception { return new ModelAndView("CustomerPage", "msg","add() method"); } public ModelAndView delete(HttpServletRequest request, HttpServletResponse response) throws Exception { return new ModelAndView("CustomerPage", "msg","delete() method"); } public ModelAndView update(HttpServletRequest request, HttpServletResponse response) throws Exception { return new ModelAndView("CustomerPage", "msg","update() method"); } public ModelAndView list(HttpServletRequest request, HttpServletResponse response) throws Exception { return new ModelAndView("CustomerPage", "msg","list() method"); }}
2. ParameterMethodNameResolver
With ParameterMethodNameResolver
configured, and define the parameter name thought the “paramName
” property:
<beans ...> <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" /> <bean class="com.mkyong.common.controller.CustomerController"> <property name="methodNameResolver"> <bean class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver"> <property name="paramName" value="action"/> </bean> </property> </bean></beans>
Now, the URL will map to the method name via the “action
” request parameter name :
/customer/*.htm?action=add –> add() method /customer/whatever.htm?action=add –> add() method /customer/*.htm?action=update –> update() method /customer/*.htm?action=delete –> delete() method /customer/*.htm?action=list –> list() method
P.S the “*
” means any text.
Note
By default,MultiActionController
is used theInternalPathMethodNameResolver
to map URL to the corresponds method name.
0 0
- Spring MVC ParameterMethodNameResolver example
- Spring MVC ParameterMethodNameResolver example
- Spring MVC ParameterMethodNameResolver example
- Spring MVC - DispatcherServlet Example
- Spring MVC Model Example
- Spring MVC MultiActionController example
- Spring MVC PropertiesMethodNameResolver example
- Spring MVC ParameterizableViewController example
- Spring MVC InternalResourceViewResolver example
- Spring MVC XmlViewResolver example
- Spring MVC ResourceBundleViewResolver example
- Spring MVC BeanNameUrlHandlerMapping example
- Spring MVC ControllerClassNameHandlerMapping example
- Spring MVC SimpleUrlHandlerMapping example
- Spring MVC RedirectView example
- Spring MVC textbox example
- Spring MVC BeanNameUrlHandlerMapping example
- Spring MVC ControllerClassNameHandlerMapping example
- SublimeText3 常用插件
- 去哪网实习总结:windows下配置JavaWeb环境、开发helloworld、发布系统(附截图,绝对详细)(JavaWeb)
- 我的第一篇博客
- cp复制软连接
- vim 中Ctags的安装和使用
- Spring MVC ParameterMethodNameResolver example
- BW on HANA迁移的四种途径
- mathematica的使用
- 轻轻写书软件
- 【Java并发编程实战】-----“J.U.C”:ReentrantLock之三unlock方法分析
- Spring MVC ParameterizableViewController example
- 怎么分析竞争对手网站提高自身的网站ccxtqj
- 汇编语言学习(三)
- 父进程waitpid子进程的一般实现