Spring MVC MultiActionController annotation example
2015-09-13 15:01
399 查看
In this tutorial, we show you how to develop a Spring MVC annotation-based
In XML-based
To configure it, define
Now, the URL will map to the method name in the following patterns :
Note
In Spring MVC, this
MultiActionController, by using
@RequestMapping.
In XML-based
MultiActionController, you have to configure the method name resolver (
InternalPathMethodNameResolver,
PropertiesMethodNameResolveror
ParameterMethodNameResolver) to map the URL to a particular method name. But, life is more easier with annotation support, now you can use
@RequestMappingannotation as a method name resolver, which used to map URL to a particular method.
To configure it, define
@RequestMappingwith mapping URL above the method name.
package com.mkyong.common.controller; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; @Controller public class CustomerController{ @RequestMapping("/customer/add.htm") public ModelAndView add(HttpServletRequest request, HttpServletResponse response) throws Exception { return new ModelAndView("CustomerAddView"); } @RequestMapping("/customer/delete.htm") public ModelAndView delete(HttpServletRequest request, HttpServletResponse response) throws Exception { return new ModelAndView("CustomerDeleteView"); } @RequestMapping("/customer/update.htm") public ModelAndView update(HttpServletRequest request, HttpServletResponse response) throws Exception { return new ModelAndView("CustomerUpdateView"); } @RequestMapping("/customer/list.htm") public ModelAndView list(HttpServletRequest request, HttpServletResponse response) throws Exception { return new ModelAndView("CustomerListView"); } }
Now, the URL will map to the method name in the following patterns :
/customer/add.htm –> add() method /customer/delete.htm –> delete() method /customer/update.htm –> update() method /customer/list.htm –> list() method
Note
In Spring MVC, this
@RequestMappingis always the most flexible and easy to use mapping mechanism.
相关文章推荐
- 分享微信开发Html5轻游戏中的几个坑
- 一个jar包里的网站
- 一个jar包里的网站之文件上传
- 一个jar包里的网站之返回对媒体类型
- Zend的MVC机制使用分析(二)
- ASP.NET MVC 4 捆绑和缩小实例介绍
- ASP.NET MVC中将控制器分离到类库的实现
- asp.net实现在非MVC中使用Razor模板引擎的方法
- ASP.NET MVC中的AJAX应用
- 如何在MVC应用程序中使用Jquery
- ASP.NET MVC小结之基础篇(二)
- ASP.NET小结之MVC, MVP, MVVM比较以及区别(一)
- Asp.net实现MVC处理文件的上传下载功能实例教程
- ASP.NET MVC小结之基础篇(一)
- spring+html5实现安全传输随机数字密码键盘
- Spring中属性注入详解
- Flex中最好的MVC框架Mate框架
- struts2 spring整合fieldError问题
- ASP.NET MVC学习笔记
- 关于php mvc开发模式的感想