1. 概述

    1. 简单整理一些 Spring 的注解
    2. 这个算是一个 水一波 类型的整理
      1. 内容不全
      2. 分类可能有的地方不会太符合逻辑
      3. 而且时间也不太充裕
      4. 先把自己想写的写下来, 然后随缘整理吧
  2. 约定
    1. 版本

      1. Spring

        1. 5
  3. 后悔
    1. 相关的书, 看了 半个月后 才想起来整理

      1. 现在看起来, 有点累
      2. 有些东西, 可能记的不那么精准
        1. 发现问题, 及时修补吧

1. 基本

  1. @SpringBootApplication

    1. 概述

      1. spring 入口类的注解
      2. 由 3 个老注解合成
    2. 类型
      1. 类注解

        1. SpringBoot 的入口类
    3. 组成
      1. @SpringBootConfiguration

        1. 配置类

          1. 是 @Configuration 的一个特殊形式
          2. 告诉大家, 这是一个 配置类
      2. @EnableAutoConfiguration
        1. 选项

          1. 开启自动配置

            1. 自动配置, 是 spring boot 的特性
            2. 用很多的约定代替了配置
      3. @ComponentScan
        1. 选项

          1. 开启组件扫描

            1. 为后面的自动注入, 做了基础
        2. 相关注解
          1. @Component
          2. @Controller
          3. @Service
    4. ref
      1. Annotation Type SpringBootApplication
  2. @Component
    1. 概述

      1. spring 组件注解

        1. 有子类

          1. @Controller
          2. @Service
    2. 类型
      1. 类注解

        1. 组件类
        2. 自动扫描
    3. 配合
      1. 需要与 @SpringBootApplication 配合

        1. 主要是 自动扫描
    4. ref
      1. @Component
  3. @Controller
    1. 概述

      1. Spring WebMvc 的注解
    2. 类型
      1. 类注解

        1. 出现在 Controller 上
    3. 配合
      1. 需要与 @SpringBootApplication 配合

        1. 主要是 自动扫描
    4. ref
      1. Annotation Type Controller
  4. @Service
    1. 概述

      1. Spring 注解
    2. 类型
      1. 类注解

        1. 出现在 Service 上

          1. Service 通常是某个接口的实现
    3. 配合
      1. 需要与 @SpringBootApplication 配合

        1. 主要是 自动扫描
    4. ref
      1. Annotation Type Service
  5. @Autowired
    1. 概述

      1. Spring 注解
      2. 自动注入
    2. 类型
      1. 对象注解

        1. 出现在对象声明上
        2. 自动识别类型进行填充
          1. 也可以手动执行
    3. 配合
      1. @Component
      2. @Controller
      3. @Service
      4. @Repository
    4. ref
      1. Annotation Type Autowired
      2. Spring 注解配置(2)——@Autowired
        1. Autowired 指定特定类型来 填充对象
  6. @Configuration
    1. 概述

      1. Spring 注解类
    2. 类型
      1. 类注解

        1. 类中会有方法

          1. 运行时生成 bean
          2. 运行时处理 对这些 bean 的秦秋
        2. 比如 WebConfig
          1. web 配置
          2. 本身也是 bean
    3. ref
      1. Annotation Type Configuration
  7. @Repository
    1. 概述

      1. Spring 数据库交互类注解
    2. 类型
      1. 类注解

        1. 通常会借助 各种template类, 与持久化数据交互
    3. ref
      1. Annotation Type Repository

2. mvc

  1. @RequestMapping

    1. 概述

      1. 声明 Controller 负责的路径
    2. 类型
      1. 类注解

        1. 规定了整个 controller 下的默认路径

          1. 下面的 处理方法, 如果没有描述 路径, 按这个路径来
          2. 如果描述了, 则以这个为 根路径, 继续处理
      2. 方法注解
        1. 通常还需要指定其他

          1. 请求方式
          2. 路径
          3. 路径中的参数
    3. 配合
      1. 各种 @Mapping
    4. ref
      1. Annotation Type RequestMapping
  2. 各种 @Mapping
    1. 概述

      1. 对应各种协议
    2. 类型
      1. 方法注解

        1. 注解处理特定协议的 controller 方法
    3. 注解
      1. @GetMapping
      2. @PostMapping
      3. @PutMapping
      4. @DeleteMapping
      5. @PatchMapping
    4. 配合
      1. @RequestMapping
    5. ref
      1. Annotation Type GetMapping

        1. 只给了 GetMapping
        2. 其他的可以从页面跳转
  3. @SessionAttributes
    1. 概述

      1. 声明要保存在 session 的 model 属性值
    2. 类型
      1. 类注解

        1. 对特定 controller 使用

          1. 一个 controller 使用就行
    3. ref
      1. Annotation Type SessionAttributes
  4. @ModelAttribute
    1. 概述

      1. model 属性

        1. 功能有点多
    2. 类型
      1. 属性注解

        1. 用在 reqeust 方法的形参里

          1. 可以从 请求的 model 里抓取出相应类型对象, 并传给形参
      2. 方法注解
        1. 将方法的返回值, 作为 model 对应属性的值

          1. 这块还需要 复习, 有点模糊了
    3. ref
      1. Annotation Type ModelAttribute

3. rest

  1. @RestController

    1. 概述

      1. 将 controller 标注为 restcontroller
    2. 类型
      1. 类注解

        1. 默认类里的 controller 方法, 带有一下注解

          1. @ResponseBody

            1. 返回 数据, 写到 responsebody 里
    3. ref
      1. Annotation Type RestController
  2. @PathVariable
    1. 概述

      1. 属性作为形参
    2. 类型
      1. 属性注解

        1. 从 url 路径中, 取出 同名字段, 作为形参
    3. ref
      1. Annotation Type PathVariable
  3. @ResponseStatus
    1. 概述

      1. 为 response 指定属性
    2. 类型
      1. 方法注解

        1. 为 response 指定属性
    3. 配合
      1. @Mapping
      2. @RequestMapping
      3. Enum HttpStatus
    4. ref
      1. Annotation Type ResponseStatus
      2. Enum HttpStatus
        1. 状态, 配合 responsestatus
  4. @RequestBody
    1. 概述

      1. 从 RequestBody 里获取内容
    2. 类型
      1. 属性注解

        1. controller 方法参数

          1. 从 request 的 body 里获取
          2. 问题, 貌似 request body 里, 必须是一个完整的对象
    3. ref
      1. Annotation Type RequestBody

4. 测试

  1. @RunWith(SpringRunner.class)

    1. 概述

      1. spring boot 的测试注解
      2. 其实是 JUnit 的一个注解
        1. JUnit 4
    2. 类型
      1. 类注解

        1. 测试类

          1. 需要 spring 注解, 都需要添加
          2. 否则 spring 相关注解会被无视
    3. SpringRunner.class
      1. 指定的 runner

        1. 这个不太清楚
        2. 一般用这个没错
  2. @SpringBootTest
    1. 概述

      1. spring boot 测试
      2. 完整的 spring 上下文
    2. 类注解
      1. 类注解

        1. spring boot 测试类
    3. 作用
      1. 启动 spring boot application context
      2. 使用默认的 SpringBootContextLoader 加载 context
      3. 使用默认的 @SpringBootConfiguration 加载配置
      4. 其他详见 api 文档吧...
    4. ref
      1. Annotation Type SpringBootTest
  3. @WebMvcTest
    1. 概述

      1. spring boot 测试注解
      2. spring web mvc 相关测试
    2. 类型
      1. 类注解
      2. spring boot webmvc 测试类
        1. 只测试 webmvc
    3. 补充
      1. 如果需要完整的 spring 上下文

        1. 请带上 @SpringBootTest
    4. 配合
      1. 可能会和 MockMvc 这个类做配合
    5. ref
      1. [Annotation Type WebMvcTest](https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTest.html
  4. @RequestParam

ps

  1. ref

    1. spring in action 5th edition
  2. 其他注解
    1. lombok
    2. testng
    3. spring security
      1. 这个要补充...
    4. spring valid
      1. 这个随缘补充
    5. spring configuration properties
      1. 这个需要补充

Spring - Spring 常用注解的更多相关文章

  1. Spring Boot常用注解总结

    Spring Boot常用注解总结 @RestController和@RequestMapping注解 @RestController注解,它继承自@Controller注解.4.0之前的版本,Spr ...

  2. Spring MVC学习总结(2)——Spring MVC常用注解说明

        使用Spring MVC的注解及其用法和其它相关知识来实现控制器功能. 02     之前在使用Struts2实现MVC的注解时,是借助struts2-convention这个插件,如今我们使 ...

  3. Spring学习总结(2)——Spring的常用注解

    本文汇总了Spring的常用注解,以方便大家查询和使用,具体如下: 使用注解之前要开启自动扫描功能 其中base-package为需要扫描的包(含子包). ? 1 <context:compon ...

  4. Spring Boot 常用注解汇总

    一.启动注解 @SpringBootApplication @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documen ...

  5. 接近8000字的Spring/SpringBoot常用注解总结!安排!

    0.前言 大家好,我是 Guide 哥!这是我的 221 篇优质原创文章.如需转载,请在文首注明地址,蟹蟹! 本文已经收录进我的 75K Star 的 Java 开源项目 JavaGuide:http ...

  6. Spring/SpringBoot常用注解总结

    转自:[Guide哥] 0.前言 可以毫不夸张地说,这篇文章介绍的 Spring/SpringBoot 常用注解基本已经涵盖你工作中遇到的大部分常用的场景.对于每一个注解我都说了具体用法,掌握搞懂,使 ...

  7. Spring MVC常用注解

    cp by http://www.cnblogs.com/leskang/p/5445698.html 1.@Controller 在SpringMVC 中,控制器Controller 负责处理由Di ...

  8. Spring Ioc 常用注解

    在开发中spring ioc的配置方式有多种方式,常用的一般都是byName.byType .以及其自动装配可以查看http://www.cnblogs.com/gubai/p/9140840.htm ...

  9. spring 、spring boot 常用注解

    @Profile 1.用户配置文件注解. 2.使用范围: @Configration 和 @Component 注解的类及其方法, 其中包括继承了 @Component 的注解: @Service. ...

  10. Spring 中常用注解原理剖析

    前言 Spring 框架核心组件之一是 IOC,IOC 则管理 Bean 的创建和 Bean 之间的依赖注入,对于 Bean 的创建可以通过在 XML 里面使用 <bean/> 标签来配置 ...

随机推荐

  1. SVM-支持向量机(二)非线性SVM分类

    非线性SVM分类 尽管SVM分类器非常高效,并且在很多场景下都非常实用.但是很多数据集并不是可以线性可分的.一个处理非线性数据集的方法是增加更多的特征,例如多项式特征.在某些情况下,这样可以让数据集变 ...

  2. 机器学习作业(六)支持向量机——Matlab实现

    题目下载[传送门] 第1题 简述:支持向量机的实现 (1)线性的情况: 第1步:读取数据文件,可视化数据: % Load from ex6data1: % You will have X, y in ...

  3. PP: Neural tensor factorization

    relational data. Neural collaborative filtering and recurrent recommender systems have been successf ...

  4. arm汇编笔记

    ARM汇编(非虫笔记) 1.ARM汇编的目的: 分析elf文件的需要. 2.原生程序生成过程. (1)预处理,编译器处理c代码中的预处理指令. gcc -E hello.c -o hello.i (2 ...

  5. 回形数字矩阵(Java)

    将矩阵从里到外分为多层,每一层都是一个口字型数字序列,方向都是顺时针/逆时针,由此我们可以将问题分解为相同的子问题来解决 回形矩阵概述 ☃ 回形矩阵有n行n列 ☃ 数字按顺时针或者逆时针递增 **使用 ...

  6. STM 32 内部功能回顾

    EXTI   外部中断 NVIC 嵌套的向量式中断控制器 AHB 是高级高性能内部总线,主要是用在CPU.DMA.DSP(数字信号处理) APB 是外围总线,I2C. 串口 APB 分为高速APB2( ...

  7. 巨杉Talk | 拒绝数据碎片化,原生分布式数据库灵活应对数据管理需求

    2019年7月19-20日,以“运筹帷幄,数揽未来”为主题的DAMS中国数据智能管理峰会在上海青浦区成功举办.在DAMS峰会上,巨杉数据库为大家带来了题为“云架构下的分布式数据库设计与实践”的主题分享 ...

  8. Spring解决bean之间的循环依赖

    转自链接:https://blog.csdn.net/lyc_liyanchao/article/details/83099675通过前几节的分析,已经成功将bean实例化,但是大家一定要将bean的 ...

  9. [HEOI2015] 小Z的房间 - 矩阵树定理

    #include <bits/stdc++.h> using namespace std; #define int long long const int N = 105; const i ...

  10. jQuery func

    1.  $(selector).each(function(index,element)); -----------index 选择器的index位置,element --当前的元素 2. _.eac ...