springboot最常用的注解们

目录

@SpringBootApplication

@Configuration

@EnableAutoConfiguration

@ComponentScan

@Component

@Service

@RestController

@Controller

@ResponseBody

@RequestMapping

@Autowired

@Qualifier(“name”)

@Resource(name=”name”,type=”type”)

@PathVariable

@Import

@Bean

@Value

@Repository


草草整理一下在使用springboot中最常用的注解们

@SpringBootApplication

包含了@ComponentScan、@EnableAutoConfiguration注解,其中@ComponentScan让springboot扫描到configuration类,并把其加入到上下文,@EnableAutoConfiguration声明让springboot自动对程序进行必要的配置

@Configuration

相当于spring的xml文件

@EnableAutoConfiguration

自动配置声明

@ComponentScan

扫描,可以自动发现和装配bean

@Component

组件,当组件不好归类的时候,可以使用这个注解,交给spring管理

@Service

一般用于修饰service层

@RestController

相当于@Controller和@ResponseBody的合集,表示这是个controller层bean,并且将返回值直接填写到http响应体,rest风格

@Controller

定义控制器类,通常需要配合注解@RequestMapping

@ResponseBody

将方法的返回值填写到响应体中

@RequestMapping

提供路由信息,可以从url映射到具体方法

@Autowired

注入

@Qualifier(“name”)

同类型bean,不同名字,采用这个来声明名字

@Resource(name=”name”,type=”type”)

注入,没有括号里的内容,默认byName

@PathVariable

获取请求参数

@Import

导入其他配置类

@Bean

声明bean

@Value

获取属性

@Repository

标注在dao上,不只是可以被spring识别为bean,还能将被修饰的类抛出的异常封装为spring的异常

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值