spring MVC之Spring MVC3.0的RESTFul方式的访问
spring MVC之Spring MVC3.0的RESTFul方式的访问
----------
下面的例子都是在基于Spring MVC 3.0基于注解的配置上进行的. springmvc3.0中增加RESTful URL功能,可以通过下面的方式访问,如:
/blog/1 | HTTP GET => | 得到id = 1的blog |
/blog/1 | HTTP DELETE => | 删除 id = 1的blog |
/blog/1 | HTTP PUT => | 更新id = 1的blog |
/blog | HTTP POST => | 新增BLOG |
springmvc rest实现
springmvc的resturl是通过@RequestMapping及@PathVariable annotation提供的,通过如@RequestMapping(value="/blog/{id}",method=RequestMethod.DELETE)即可处理/blog/1 的delete请求.
@RequestMapping(value="/blog/{id}",method=RequestMethod.DELETE) public ModelAndView delete(@PathVariable Long id,HttpServletRequest request, HttpServletResponse response) { blogManager.removeById(id); return new ModelAndView(LIST_ACTION); }
@RequestMapping(value="/blog/{id}",method=RequestMethod.DELETE) public ModelAndView delete(@PathVariable Long id,HttpServletRequest request, HttpServletResponse response) { blogManager.removeById(id); return new ModelAndView(LIST_ACTION); }
@RequestMapping @PathVariable如果URL中带参数,则配合使用,如:
@RequestMapping @PathVariable如果URL中带参数,则配合使用,如: @RequestMapping(value="/blog/{blogId}/message/{msgId}",method=RequestMethod.DELETE) public ModelAndView delete(@PathVariable("blogId") Long blogId,@PathVariable("msgId") Long msgId,HttpServletRequest request,HttpServletResponse response) { }
相关推荐
84560296 2019-12-01
Eiceblue 2020-08-02
ahnjwj 2020-07-28
playis 2020-06-28
playis 2020-06-16
ahnjwj 2020-06-12
84560296 2020-06-10
84560296 2020-06-09
84560296 2020-06-08
84560296 2020-05-30
81901836 2020-05-26
beibeijia 2020-05-16
85291545 2020-05-01
84560296 2020-04-10
fanix 2020-04-09
bapinggaitianli 2020-04-07
84560296 2020-03-27