Spring MVC PropertiesMethodNameResolver example
来源:互联网 发布:c语言程序的基本单位 编辑:程序博客网 时间:2024/05/22 14:35
PropertiesMethodNameResolver
, a flexible MultiActionController
method name resolver, to define the mapping between the URL and method name explicitly. 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. PropertiesMethodNameResolver
With PropertiesMethodNameResolver
, you can map whatever URL name to corresponds method name easily :
<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.PropertiesMethodNameResolver"> <property name="mappings"> <props> <prop key="/customer/a.htm">add</prop> <prop key="/customer/b.htm">update</prop> <prop key="/customer/c.htm">delete</prop> <prop key="/customer/d.htm">list</prop> <prop key="/customer/whatever.htm">add</prop> </props> </property> </bean> </property> </bean></beans>
Now, the URL will map to the method name in the following pattern :
/customer/a.htm –> add() method /customer/b.htm –> update() method /customer/c.htm –> delete() method /customer/d.htm –> list() method /customer/whatever.htm –> add() method
Note
By default,MultiActionController
is used theInternalPathMethodNameResolver
to map URL to the corresponds method name.
0 0
- Spring MVC PropertiesMethodNameResolver example
- Spring MVC PropertiesMethodNameResolver example
- Spring MVC - DispatcherServlet Example
- Spring MVC Model Example
- Spring MVC MultiActionController example
- Spring MVC ParameterMethodNameResolver example
- Spring MVC ParameterMethodNameResolver 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
- 【LeetCode-面试算法经典-Java实现】【198-House Robber(抢劫犯)】
- Spring MVC MultiActionController example
- 【LeetCode-面试算法经典-Java实现】【199-Binary Tree Right Side View(从右边看二叉树)】
- Spring MVC MultiActionController annotation example
- 【LeetCode-面试算法经典-Java实现】【200-Number of Islands(岛的数目)】
- Spring MVC PropertiesMethodNameResolver example
- 正则表达式测试工具 regexbuddy
- HDU 3625 Examining the Rooms(第一类斯特林数)
- 轻松python文本专题-单独处理字符串每个字符的方法汇总
- C语言的标准库概述
- Exactly-once Spark Streaming from Apache Kafka
- CentOS6.5 升级 Python 2.7 版本
- Leecode_Single Number
- Leetcode: Unique Binary Search Trees II