springbook 注解笔记

springboot 注解笔记

1、springboot启动类

1 @SpringBootApplication

包含了@ComponentScan、@Configuration和@EnableAutoConfiguration注解。

2 @ComponentScan

让spring Boot扫描到Configuration类并把它加入到程序上下文。

3 @MapperScan (value = “com.*.mapper”)

扫描数据访问接口

4 @EnableDubboConfiguration

​ 开启dubbo注解支持

2 控制层

1 @Controller

bean注入

2 @Reference

@Reference(interfaceClass =CategoryService.class,version = “1.0.0”)

//引入服务 springboot 整合dubbo时候 comsumer接收provide 暴露的 service接口

3 @Component

bean 注入

4 @GetMapping @PostMapping

@DeleteMapping @PutMapping

等价 @RequestMapping(value = “/user”,method = RequestMethod.POST)

value 取值最好为结果 实体类名 例如 /user

5 @RestController

包含 @Controller
@ResponseBody

6@Value

将配置文件中的值映射到一个Spring管理的Bean的属性上。

7 @ConfigurationProperties

@ConfigurationProperties(prefix=“配置文件中的key前缀”)

可以将配置文件中的配置自动与数据实体进行映射,配置项通过实体的set方法注入(数据实体必须提供set方法)

如果使用@ConfigurationProperties时出现警告,可以添加以下依赖

8@RequestMapping(“/quick”)

请求

9 @ResponseBody

请求体

10 @Autowired

自动注入
//Autowried 是spring 提供 默认bytpye ,要用byname的话 加@Qulifire(“name”)
//这个name 与 bean 申明时候的component(“name”)一致
//@requried = ture 报错 =flase 不报错null

11@PathVariable

路径传参

@PostMapping(“/user/a{uname}b/c{pwd}d”) //{uname} 可以设置通配符通配符

@PathVariable(“uname”) String username,//路径传参 @PathVariable(“pwd”) String password,

12 @RequestParam

@RequestParam(required = false) String hobby,//表单参数 required = false 可以不传参

13 RequestBody

@RequestBody User user//json数据 @RequestParam 与 @RequestBody(前端响应后端) 二选一

3 service层

1 @Transactional

开启事务

2 @Service

@Service(interfaceClass = CategoryService.class,version = “1.0.0”)

springboot整合dubbo 时候service 层暴露service接口

3 @Service

bean注入

4

4 测试类

1 @SpringBootTest

测试类

2 @Test

5 配置类

1 @Configuration

标志配置类 ,配置拦截器等

2 @Import

用来导入其他配置类。

3 @ImportResource

用来加载xml配置文件。

未完待续

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

huangshaohui00

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值