1. @SpringBootApplication
2. @Repository
3. @Service
4. @RestController
5. @Controller
6. @Component
7. @ResponseBody
8. @RequestBody
9. @ComponentScan
10. @Configuration
11. @Bean
12. @EnableAutoConfiguration
13. @AutoWired
14. @Qualifier 
15. @Resource 
16. @RequestMapping 
17. @GetMapping
18. @PostMapping
19. @RequestParam
20. @PathVariable

 

@SpringBootApplication

包含@Configuration、@EnableAutoConfiguration、@ComponentScan通常用在主类上。

@Repository

用于标注数据访问组件,即DAO组件。

@Service

用于标注业务层组件。

@RestController

用于标注控制层组件(如struts中的action),包含@Controller和@ResponseBody。

@Controller

用于标注是控制层组件,需要返回页面时请用@Controller而不是@RestController。

@Component

泛指组件,当组件不好归类的时候,我们可以使用这个注解进行标注。

@ResponseBody

加上@responsebody后返回结果不会被解析为跳转路径,而是直接写入HTTP response body中;比如异步获取json数据,加上@responsebody后,会直接返回json数据。

@RequestBody

参数前加上这个注解之后,认为该参数必填。表示接受json字符串转为对象 List等。

@ComponentScan

组件扫描。个人理解相当于,如果扫描到有@Component @Controller @Service,@Repository等这些注解的类,则把这些类注册为bean。

@Configuration

指出该类是 Bean 配置的信息源,相当于XML中的,一般加在主类上。

@Bean

相当于XML中的,放在方法的上面,而不是类,意思是产生一个bean,并交给spring管理。

@EnableAutoConfiguration

让 Spring Boot 根据应用所声明的依赖来对 Spring 框架进行自动配置,一般加在主类上。

@AutoWired

默认byType方式。把配置好的Bean拿来用,完成属性、方法的组装,它可以对类成员变量、方法及构造函数进行标注,完成自动装配的工作;

当加上(required=false)时,就算找不到bean也不报错。

@Qualifier

当有多个同一类型的Bean时,可以@Qualifier(“name”)来指定。与@Autowired配合使用。

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

与@AutoWired相类似,没有括号内内容的话,默认byName方式。

@RequestMapping

RequestMapping是一个用来处理请求地址映射的注解,可用于类或方法上。用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径。

@GetMapping

相当于@RequestMapping(value=”/”, method=RequestMethod.Get)

@PostMapping等

相当于@RequestMapping(value=”/”, method=RequestMethod.Post)

@RequestParam

用在方法的参数前面,相当于 request.getParameter。

@PathVariable

路径变量。如 RequestMapping(“/user/{user}”) ;

public String getUser(
@PathVariable("user") String user){
//操作代码
}

参数与大括号里的名字相同的话,注解后括号里的内容可以不填。

本次我们就聊到这里,小伙伴们,我们下一个主题再见。

springboot的常用注解的更多相关文章

  1. SpringBoot 中常用注解

    本篇博文将介绍几种SpringBoot 中常用注解 其中,各注解的作用为: @PathVaribale 获取url中的数据 @RequestParam 获取请求参数的值 @GetMapping 组合注 ...

  2. SpringBoot 中常用注解@PathVaribale/@RequestParam/@GetMapping介绍

    SpringBoot 中常用注解@PathVaribale/@RequestParam/@GetMapping介绍 本篇博文将介绍几种如何处理url中的参数的注解@PathVaribale/@Requ ...

  3. SpringBoot 中常用注解@Controller/@RestController/@RequestMapping的区别

    SpringBoot中常用注解@Controller/@RestController/@RequestMapping的区别 @Controller 处理http请求 @Controller //@Re ...

  4. SpringBoot 中常用注解@Controller/@RestController/@RequestMapping介绍

    原文 SpringBoot 中常用注解 @Controller/@RestController/@RequestMapping介绍 @Controller 处理http请求 @Controller / ...

  5. SpringBoot+Spring常用注解总结

    为什么要写这篇文章? 最近看到网上有一篇关于 SpringBoot 常用注解的文章被转载的比较多,我看了文章内容之后属实觉得质量有点低,并且有点会误导没有太多实际使用经验的人(这些人又占据了大多数). ...

  6. SpringBoot中常用注解@Controller/@RestController/@RequestMapping的区别

    @Controller 处理http请求 @Controller //@ResponseBody public class HelloController { @RequestMapping(valu ...

  7. springboot部分常用注解

    目录:[持续更新.....] spring 部分常用注解 spring boot 学习之路1(简单入门) spring boot 学习之路2(注解介绍) spring boot 学习之路3( 集成my ...

  8. springboot系列总结(二)---springboot的常用注解

    上一篇文章我们简单讲了一下@SpringBootApplication这个注解,申明让spring boot自动给程序进行必要的配置,他是一个组合注解,包含了@ComponentScan.@Confi ...

  9. SpringBoot之常用注解

    在spring boot中,摒弃了spring以往项目中大量繁琐的配置,遵循约定大于配置的原则,通过自身默认配置,极大的降低了项目搭建的复杂度.同样在spring boot中,大量注解的使用,使得代码 ...

  10. 【SpringBoot】常用注解

    @EnableAutoConfiguration 启动自动装载:使用了这个注解之后,所有引入的jar的starters都会被自动注入.这个类的设计就是为starter工作的. @RestControl ...

随机推荐

  1. 深度学习论文翻译解析(十一):OverFeat: Integrated Recognition, Localization and Detection using Convolutional Networks

    论文标题:OverFeat: Integrated Recognition, Localization and Detection using Convolutional Networks 标题翻译: ...

  2. 看完这一篇,再也不怕面试官问到IntentService的原理

    IntentService是什么 在内部封装了 Handler.消息队列的一个Service子类,适合在后台执行一系列串行依次执行的耗时异步任务,方便了我们的日常coding(普通的Service则是 ...

  3. Python file() 函数

    描述 file() 函数用于创建一个 file 对象,它有一个别名叫 open(),更形象一些,它们是内置函数.参数是以字符串的形式传递的.每组词 www.cgewang.com 更多文件操作可参考: ...

  4. PHP is_callable() 函数

    is_callable() 函数用于检测函数在当前环境中是否可调用.高佣联盟 www.cgewang.com is_callable() 函数验证变量的内容能否作为函数调用. 这可以检查包含有效函数名 ...

  5. PHP tan() 函数

    实例 返回不同数的正切: <?php高佣联盟 www.cgewang.comecho(tan(M_PI_4) . "<br>");echo(tan(0.50) . ...

  6. Vue无限滚动加载数据

    Web项目经常会用到下拉滚动加载数据的功能,今天就来种草Vue-infinite-loading 这个插件,讲解一下使用方法! 第一步:安装 npm install vue-infinite-load ...

  7. Blob分析之board _components.hdev

    *用立体方法分割板子组件的示例程序*Application program to illustrate the segmentation* of board _components.hdev  wit ...

  8. ElasticSearch实战系列六: Logstash快速入门和实战

    前言 本文主要介绍的是ELK日志系统中的Logstash快速入门和实战 ELK介绍 ELK是三个开源软件的缩写,分别表示:Elasticsearch , Logstash, Kibana , 它们都是 ...

  9. 数据库Schema

    在学习SQL的过程中,会遇到一个让你迷糊的Schema的概念.实际上,schema就是数据库对象的集合,这个集合包含了各种对象如:表.视图.存储过程.索引等.为了区分不同的集合,就需要给不同的集合起不 ...

  10. Python 为什么会有个奇怪的“...”对象?

    本文出自"Python为什么"系列,请查看全部文章 在写上一篇<Python 为什么要有 pass 语句?>时,我想到一种特别的写法,很多人会把它当成 pass 语句的 ...