spring 实例
@Mapper
@Service
@Autowired
@Override
@RestController
@RequestMapping("/archives")
@Autowired
@PostMapping("/selectArchivesCollectList")
@RequestBody
用法
<context id="MyBatis3Generator" targetRuntime="MyBatis3"></context>
1.在类上写注解
@Controller, @Service, @Repository,@Component
@RestController = @Controller + @ResponseBody
@RequestMapping 处理映射请求的注解
@RequestMapping(value =”/testValid”)
@RequestMapping(value=”/{day}”)
@RequestMapping(value=”/{textualPart:[a-z-]+}.{numericPart:[\\d]+}”)
@RequestMapping(value = ”/test”, consumes=”application/json”)
@RequestMapping(value = “/test”, method = RequestMethod.GET, params=“name=chenyuan”)
2.成员变量上写注解
@Autowired
Autowired默认先按byType,如果发现找到多个bean,则,又按照byName方式比对,如果还有多个,则报出异常。
如果要允许null 值,可以设置它的required属性为false,如:@Autowired(required=false)
3.成员方法参数前写注解
@RequestBody
@RequestBody(required=true):有个默认属性required,默认是true,当body里没内容时抛异常。
4.在成员方法上写注解
@GetMapping(value = “page”)等价于@RequestMapping(value = “page”, method = RequestMethod.GET)
@PostMapping(value = “page”)等价于@RequestMapping(value = “page”, method = RequestMethod.POST)
https://blog.csdn.net/weixin_39805338/article/details/80770472 spring 注解整理