SpringBoot注解方式

基本注解 

#注解在类上

@Service: 表示这是一个业务层bean

@Controller:表示这是一个控制层bean

@Repository: 表示这是一个数据访问层bean

@Component: 表示通用bean ,value不写默认就是类名首字母小写

#按类型注入

@Autowired:对类成员变量、方法及构造函数进行标注,让 spring 完成 bean 自动装配的工作;默认属性required= true

#启动注解

@SpringBootApplication:该注解是@ComponentScan、@SpringBootConfiguration、@EnableAutoConfiguration的组合

@ComponentScan:将SpringBoot扫描到的Configuration类加入到程序上下文

@SpringBootConfiguration:允许在 Spring 上下文中注册额外的 bean 或导入其他配置类

@EnableAutoConfiguration:启用 SpringBoot 的自动配置机制

#HTTP注解

@RequestBody:HTTP请求获取请求体(处理复杂数据,比如JSON)

@RequestHeader:HTTP请求获取请求头

@RequestParam:HTTP请求获取请求参数(处理简单数据,键值对)

@SessionAttribute:HTTP请求获取会话

@RequestAttribute:HTTP请求获取请求的Attribute(比如过滤器和拦截器手动设置的一些临时数据)

@MatrixAttribute:HTTP请求获取矩阵变量允许我们采用特殊的规则在URL路径后加参数(分号区分不同参数,逗号为参数增加多个值)

@PathVariable:HTTP请求获取路径片段

@CookieValue:HTTP请求获取cookie

猜你喜欢

转载自blog.csdn.net/qq_53376718/article/details/129743783