常用的一些注解注解

前后端开发常用的一些注解
controller

controller层 作用 例子 用法
@Api 用于生成接口文档方便于开发 @Api(tags = {“Login”}, description = “相关接口”) io.swagger.annotations.Api 在controller类上
@Slf4j 用于日志输出 @Slf4j lombok.extern.slf4j.Slf4j 在controller类上
@RestController 相当于@ResponseBody + @Controller合在一起(无法放回jsp页面,放回json数据) @RestController org.springframework.web.bind.annotation.* 在controller类上
@RequestMapping常用的一些注解注解 用来处理请求地址映射的注解,可用于类或方法上 @RequestMapping(value = “/myBag”, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) org.springframework.web.bind.annotation.* 用于类或方法
@Validated 用来校验数据,如果数据异常则会统一抛出异常 @Validated org.springframework.validation.annotation.Validated 在controller类上
@Autowired 注入属性 @Autowired org.springframework.web.bind.annotation.* 用于属性上
@Resources 注入bean @Resources org.springframework.web.bind.annotation.* 用于方法上
@ApiOperation 用于生成接口文档方便于开发 @ApiOperation(value = “查询所有目录(分页)”) io.swagger.annotations.Api 用于方法上
@PostMapping 访问时的url @PostMapping("/page") org.springframework.web.bind.annotation.* 用于方法
@RequestParam 配置参数(可以连用) @RequestParam(“id”) int id, @RequestParam(“fieldName”) String fieldName org.springframework.web.bind.annotation.* 用于参数配置(用于get,post)
@RequestBody 配置参数 @RequestBody DmdImplParam implParam org.springframework.web.bind.annotation.* 用于参数配置(用于post)

impl

Service层 作用 例子 作用
@Service 注入bean @Service org.springframework.stereotype.Service 用于类
@Autowired 注入属性 @Autowired org.springframework.web.bind.annotation.* 用于属性上

mapper

mapper层 作用 列子 作用
@Mapper 注入bean @Mapper @Service org.springframework.stereotype.Service
@Param 作用参数 @Param(“cataTitle”) String cataTitle, @Param(“deptCode”) String deptCode org.apache.ibatis.annotations.* 用于方法的参数(可以设置多个)

小白刚接触不久为了记得深点做点笔记,希望对和小白一样的有帮助