Spring的复杂性来自于自身,而不是它所处理的对象。 不断进化的Spring带来了时间维度上的复杂性。 例如,SpringMVC早期版本的*@RequestMapping*到新版本将被以下新评论替换,相当于增加选择。
根据@ getmappingpost * mapping @ put mapping @ delete mapping @ patch mapping命名约定,每个注释都有各自的传入请求方法类型,即*@GetMapping为请求方法类型
如果使用传统的*@RequestMapping*注释实现URL处理程序,则:
@ request mapping (value=“/get/{ id }”,method=RequestMethod.GET ) )
新方法可以简化为
@getmapping(/get/{id} ) )。
如何工作以上所有注释都在内部注释为*@RequestMapping和方法*元素的相应值。
例如,如果查看*@GetMapping注释的源代码,则可以看到使用RequestMethod.GET*进行了以下注释:
@ target (Java.lang.annotation.element type.method ) ) retentionpolicy.runtime ) documented @ request pububbbe 也就是说,*@PostMapping使用RequestMethod.POST创建注释,@ PutMapping使用request
代码示例BuyerProductController /** *购买者商品* createdbyxndzc * 2020/10/1720336011 */package com.LBL.controller; importorg.spring帧web.bind.annotation.get mapping; importorg.spring帧web.bind.annotation.request mapping; importorg.spring帧web.bind.annotation.rest controller; @ rest controller @ request mapping (/buyer/product ) ) publicclassbuyerproductcontroller (@ get mapping )/list ) puust