0
点赞
收藏
分享

微信扫一扫

第五节:SpringBoot常用注解介绍

眼君 2022-01-27 阅读 70

文章目录

启动类上的注解

  • @SpringBootConfiguration继承@Configuration两个注解的功能一样。也就是标注当前类是配置类。会将当前类中声明的一个或者多个@Bean注解标记的方法的实例注入到Spring容器中。实例名就是对象名。
  • @EnableAutoConfigurationSpringBoot的自动配置注解。可以将符合条件的@Configuration加载到SpringBoot,并生成对应配置类的Bean,加载到Srping容器。
  • @ComponentScan扫描当前包和子包下被@Component,@Controller,@Service,@Respository注解的类并注入到Spring容器。

前端控制器

@Controller

@RestController

@RequestMapping

value,method
  • value 请求的方法
  • method 请求的类型,GET,POST,PUT,DELETE
consumes,produces
  • consumes 指定可以处理请求数据的类型。如:application/jsontext/html
  • produces 指定返回数据的类型。只有当request请求头Accept字段中包含此类型,才返回数据
params,headers
  • params 指定request中包含某些参数值,才处理。
  • headers 指定request请求头包含header值,才处理。

@RequestBody@ResponseBody

@RequestBody

@ResponseBody

@PathVariable,@RequestParam,@ModelAttribute,@RequestAttribute

@PathVariable
@RequestParam
@RequestAttribute ,@ModelAttribute
  • 用在方法参数注解上,可以接收前端参数,但是要求数据格式是x-www-form-urlencoded
  • 用在方法上可以预存属性值。

@GetMapping

@PostMapping

服务层

@Service注解在类上,标注这是一个服务层

持久层

@Repository 注解于类上,表示于持久层

配置

@Component

@Configuration

@Bean

依赖注入

@Autowired

@Resource

@Qualifier

@Value

  • GitHub:https://github.com/mifunc/springboot/tree/main/lession5
  • Gitee:https://gitee.com/rumenz/springboot/tree/master/lession5
  • https://rumenz.com/rumenbiji/springboot-annotation.html
  • 我的博客 https://rumenz.com/
  • 我的工具箱 https://tooltt.com/
  • 微信公众号:【入门小站】

  • 关注【入门小站】回复【1001】获取 linux常用命令速查手册
  • 关注【入门小站】回复【1003】获取 LeetCode题解【java语言实现】
  • 关注【入门小站】回复【1004】获取 Java基础核心总结
  • 关注【入门小站】回复【1009】获取 阿里巴巴Java开发手册
举报

相关推荐

0 条评论