常用的一些注解注解

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

controller层作用例子用法
@Api用于生成接口文档方便于开发@Api(tags = {“Login”}, description = “相关接口”)io.swagger.annotations.Api在controller类上
@Slf4j用于日志输出@Slf4jlombok.extern.slf4j.Slf4j在controller类上
@RestController相当于@ResponseBody + @Controller合在一起(无法放回jsp页面,放回json数据)@RestControllerorg.springframework.web.bind.annotation.*在controller类上
@RequestMapping在这里插入图片描述用来处理请求地址映射的注解,可用于类或方法上@RequestMapping(value = “/myBag”, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)org.springframework.web.bind.annotation.*用于类或方法
@Validated用来校验数据,如果数据异常则会统一抛出异常@Validatedorg.springframework.validation.annotation.Validated在controller类上
@Autowired注入属性@Autowiredorg.springframework.web.bind.annotation.*用于属性上
@Resources注入bean@Resourcesorg.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 fieldNameorg.springframework.web.bind.annotation.*用于参数配置(用于get,post)
@RequestBody配置参数@RequestBody DmdImplParam implParamorg.springframework.web.bind.annotation.*用于参数配置(用于post)

impl

Service层作用例子作用
@Service注入bean@Serviceorg.springframework.stereotype.Service用于类
@Autowired注入属性@Autowiredorg.springframework.web.bind.annotation.*用于属性上
@Value注入一些在配置文件的数据@Value("${image}")org.springframework.web.bind.annotation.*一般较多用于服务层

mapper

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

entity

实体层作用列子作用
@Pattern可以对一些实体进行正则校验@Pattern(regexp = Regex.name, message = “姓名长度不得超过50字”)javax.validation.constraints.*用于实体类(Regex接口编写的正则表达式字符串)

其他

实体层作用列子作用
@ConfigurationProperties获取配置文件中的数据@ConfigurationProperties(prefix = “ridden”) private String url;org.springframework.boot.context.properties.*用户获取配置文件的一些值

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值