• 面试题-springboot篇-SpringBoot的注解


    @SpringBootApplication是SpringBoot的最核心的注解

    @SpringBootApplication注解在SpringBoot的主类上,标识是SpringBoot应用,用来开启SpringBoot的各项能力。由@SpringBootConfiguration、@EnableAutoConfiguration、@ComponentScan三个注解组成。这三个注解是一起使用,所以SpringBoot提供了一个统一的注解@SpringBootApplication

    SpringBoot的注解有很多,每个注解都有不同的功能,下面列举一些常用的注解及其功能1:

    1. @SpringBootApplication:这是一个复合注解,它包含了@SpringBootConfiguration、@EnableAutoConfiguration、@ComponentScan,通常用在主类上。

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

    3. @ComponentScan:SpringBoot会自动扫描@SpringBootApplication所在类的同级包以及下级包里的Bean。

    4. @Configuration:定义配置类,可替换xml配置文件。

    5. @Bean:用在方法上,将方法的返回值添加到容器中,容器中这个组件默认的id就是方法名。

    6. @Controller:定义控制器类,在Spring 4.x版本之后,增加了@RestController注解,原来在@Controller中返回json需要@ResponseBody来配合,如果直接用@RestController替代@Controller就不需要再配置@ResponseBody,默认返回json格式。

    7. @RequestMapping:提供路由信息,负责URL到Controller中的具体函数的映射。

    8. @RequestParam:获取请求参数的值。

    9. @Autowired:自动装配bean,可以省略set方法。

    10. @Service:用于标注业务层组件。

    11. @Repository:用于标注数据访问组件,即DAO组件。

    12. @Entity:标注实体类,与数据库表对应。

  • 相关阅读:
    《011.SpringBoot之餐厅点餐系统》
    Linux下的stratis高级存储
    VC中怎么进行结构体数组的初始化?
    5.ARP地址解析协议
    Node.js精进(5)——HTTP
    class java.lang.Integer cannot be cast to class java.lang.String解决方案
    Java 栈和队列的基本使用
    Redis的启动方法
    Python-网络编程中数据的打包与字节流的解包
    Zemax操作37--更换玻璃和非球面
  • 原文地址:https://blog.csdn.net/qq_34783818/article/details/133855296