Spring - Spring 常用注解
- 概述
- 简单整理一些 Spring 的注解
- 这个算是一个 水一波 类型的整理
- 内容不全
- 分类可能有的地方不会太符合逻辑
- 而且时间也不太充裕
- 先把自己想写的写下来, 然后随缘整理吧
- 约定
- 版本
- Spring
- 5
- Spring
- 版本
- 后悔
- 相关的书, 看了 半个月后 才想起来整理
- 现在看起来, 有点累
- 有些东西, 可能记的不那么精准
- 发现问题, 及时修补吧
- 相关的书, 看了 半个月后 才想起来整理
1. 基本
- @SpringBootApplication
- 概述
- spring 入口类的注解
- 由 3 个老注解合成
- 类型
- 类注解
- SpringBoot 的入口类
- 类注解
- 组成
- @SpringBootConfiguration
- 配置类
- 是 @Configuration 的一个特殊形式
- 告诉大家, 这是一个 配置类
- 配置类
- @EnableAutoConfiguration
- 选项
- 开启自动配置
- 自动配置, 是 spring boot 的特性
- 用很多的约定代替了配置
- 开启自动配置
- 选项
- @ComponentScan
- 选项
- 开启组件扫描
- 为后面的自动注入, 做了基础
- 开启组件扫描
- 相关注解
- @Component
- @Controller
- @Service
- 选项
- @SpringBootConfiguration
- ref
- 概述
- @Component
- 概述
- spring 组件注解
- 有子类
- @Controller
- @Service
- 有子类
- spring 组件注解
- 类型
- 类注解
- 组件类
- 自动扫描
- 类注解
- 配合
- 需要与 @SpringBootApplication 配合
- 主要是 自动扫描
- 需要与 @SpringBootApplication 配合
- ref
- 概述
- @Controller
- 概述
- Spring WebMvc 的注解
- 类型
- 类注解
- 出现在 Controller 上
- 类注解
- 配合
- 需要与 @SpringBootApplication 配合
- 主要是 自动扫描
- 需要与 @SpringBootApplication 配合
- ref
- 概述
- @Service
- 概述
- Spring 注解
- 类型
- 类注解
- 出现在 Service 上
- Service 通常是某个接口的实现
- 出现在 Service 上
- 类注解
- 配合
- 需要与 @SpringBootApplication 配合
- 主要是 自动扫描
- 需要与 @SpringBootApplication 配合
- ref
- 概述
- @Autowired
- 概述
- Spring 注解
- 自动注入
- 类型
- 对象注解
- 出现在对象声明上
- 自动识别类型进行填充
- 也可以手动执行
- 对象注解
- 配合
- @Component
- @Controller
- @Service
- @Repository
- ref
- Annotation Type Autowired
- Spring 注解配置(2)——@Autowired
- Autowired 指定特定类型来 填充对象
- 概述
- @Configuration
- 概述
- Spring 注解类
- 类型
- 类注解
- 类中会有方法
- 运行时生成 bean
- 运行时处理 对这些 bean 的秦秋
- 比如 WebConfig
- web 配置
- 本身也是 bean
- 类中会有方法
- 类注解
- ref
- 概述
- @Repository
- 概述
- Spring 数据库交互类注解
- 类型
- 类注解
- 通常会借助 各种template类, 与持久化数据交互
- 类注解
- ref
- 概述
2. mvc
- @RequestMapping
- 概述
- 声明 Controller 负责的路径
- 类型
- 类注解
- 规定了整个 controller 下的默认路径
- 下面的 处理方法, 如果没有描述 路径, 按这个路径来
- 如果描述了, 则以这个为 根路径, 继续处理
- 规定了整个 controller 下的默认路径
- 方法注解
- 通常还需要指定其他
- 请求方式
- 路径
- 路径中的参数
- 通常还需要指定其他
- 类注解
- 配合
- 各种 @Mapping
- ref
- 概述
- 各种 @Mapping
- 概述
- 对应各种协议
- 类型
- 方法注解
- 注解处理特定协议的 controller 方法
- 方法注解
- 注解
- @GetMapping
- @PostMapping
- @PutMapping
- @DeleteMapping
- @PatchMapping
- 配合
- @RequestMapping
- ref
- Annotation Type GetMapping
- 只给了 GetMapping
- 其他的可以从页面跳转
- Annotation Type GetMapping
- 概述
- @SessionAttributes
- 概述
- 声明要保存在 session 的 model 属性值
- 类型
- 类注解
- 对特定 controller 使用
- 一个 controller 使用就行
- 对特定 controller 使用
- 类注解
- ref
- 概述
- @ModelAttribute
- 概述
- model 属性
- 功能有点多
- model 属性
- 类型
- 属性注解
- 用在 reqeust 方法的形参里
- 可以从 请求的 model 里抓取出相应类型对象, 并传给形参
- 用在 reqeust 方法的形参里
- 方法注解
- 将方法的返回值, 作为 model 对应属性的值
- 这块还需要 复习, 有点模糊了
- 将方法的返回值, 作为 model 对应属性的值
- 属性注解
- ref
- 概述
3. rest
- @RestController
- 概述
- 将 controller 标注为 restcontroller
- 类型
- 类注解
- 默认类里的 controller 方法, 带有一下注解
- @ResponseBody
- 返回 数据, 写到 responsebody 里
- @ResponseBody
- 默认类里的 controller 方法, 带有一下注解
- 类注解
- ref
- 概述
- @PathVariable
- 概述
- 属性作为形参
- 类型
- 属性注解
- 从 url 路径中, 取出 同名字段, 作为形参
- 属性注解
- ref
- 概述
- @ResponseStatus
- 概述
- 为 response 指定属性
- 类型
- 方法注解
- 为 response 指定属性
- 方法注解
- 配合
- @Mapping
- @RequestMapping
- Enum HttpStatus
- ref
- Annotation Type ResponseStatus
- Enum HttpStatus
- 状态, 配合 responsestatus
- 概述
- @RequestBody
- 概述
- 从 RequestBody 里获取内容
- 类型
- 属性注解
- controller 方法参数
- 从 request 的 body 里获取
- 问题, 貌似 request body 里, 必须是一个完整的对象
- controller 方法参数
- 属性注解
- ref
- 概述
4. 测试
- @RunWith(SpringRunner.class)
- 概述
- spring boot 的测试注解
- 其实是 JUnit 的一个注解
- JUnit 4
- 类型
- 类注解
- 测试类
- 需要 spring 注解, 都需要添加
- 否则 spring 相关注解会被无视
- 测试类
- 类注解
- SpringRunner.class
- 指定的 runner
- 这个不太清楚
- 一般用这个没错
- 指定的 runner
- 概述
- @SpringBootTest
- 概述
- spring boot 测试
- 完整的 spring 上下文
- 类注解
- 类注解
- spring boot 测试类
- 类注解
- 作用
- 启动 spring boot application context
- 使用默认的 SpringBootContextLoader 加载 context
- 使用默认的 @SpringBootConfiguration 加载配置
- 其他详见 api 文档吧...
- ref
- 概述
- @WebMvcTest
- 概述
- spring boot 测试注解
- spring web mvc 相关测试
- 类型
- 类注解
- spring boot webmvc 测试类
- 只测试 webmvc
- 补充
- 如果需要完整的 spring 上下文
- 请带上 @SpringBootTest
- 如果需要完整的 spring 上下文
- 配合
- 可能会和 MockMvc 这个类做配合
- ref
- [Annotation Type WebMvcTest](https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTest.html
- 概述
- @RequestParam
- 略
ps
- ref
- spring in action 5th edition
- 其他注解
- lombok
- testng
- spring security
- 这个要补充...
- spring valid
- 这个随缘补充
- spring configuration properties
- 这个需要补充
Spring - Spring 常用注解的更多相关文章
- Spring Boot常用注解总结
Spring Boot常用注解总结 @RestController和@RequestMapping注解 @RestController注解,它继承自@Controller注解.4.0之前的版本,Spr ...
- Spring MVC学习总结(2)——Spring MVC常用注解说明
使用Spring MVC的注解及其用法和其它相关知识来实现控制器功能. 02 之前在使用Struts2实现MVC的注解时,是借助struts2-convention这个插件,如今我们使 ...
- Spring学习总结(2)——Spring的常用注解
本文汇总了Spring的常用注解,以方便大家查询和使用,具体如下: 使用注解之前要开启自动扫描功能 其中base-package为需要扫描的包(含子包). ? 1 <context:compon ...
- Spring Boot 常用注解汇总
一.启动注解 @SpringBootApplication @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documen ...
- 接近8000字的Spring/SpringBoot常用注解总结!安排!
0.前言 大家好,我是 Guide 哥!这是我的 221 篇优质原创文章.如需转载,请在文首注明地址,蟹蟹! 本文已经收录进我的 75K Star 的 Java 开源项目 JavaGuide:http ...
- Spring/SpringBoot常用注解总结
转自:[Guide哥] 0.前言 可以毫不夸张地说,这篇文章介绍的 Spring/SpringBoot 常用注解基本已经涵盖你工作中遇到的大部分常用的场景.对于每一个注解我都说了具体用法,掌握搞懂,使 ...
- Spring MVC常用注解
cp by http://www.cnblogs.com/leskang/p/5445698.html 1.@Controller 在SpringMVC 中,控制器Controller 负责处理由Di ...
- Spring Ioc 常用注解
在开发中spring ioc的配置方式有多种方式,常用的一般都是byName.byType .以及其自动装配可以查看http://www.cnblogs.com/gubai/p/9140840.htm ...
- spring 、spring boot 常用注解
@Profile 1.用户配置文件注解. 2.使用范围: @Configration 和 @Component 注解的类及其方法, 其中包括继承了 @Component 的注解: @Service. ...
- Spring 中常用注解原理剖析
前言 Spring 框架核心组件之一是 IOC,IOC 则管理 Bean 的创建和 Bean 之间的依赖注入,对于 Bean 的创建可以通过在 XML 里面使用 <bean/> 标签来配置 ...
随机推荐
- PIE-SDK For C++栅格数据集的读写
1.功能简介 栅格数据包含很多信息,在数据的运用中需要对数据的信息进行读取或写入,目前PIE SDK支持多种数据格式的数据读取和写入,下面对栅格数据格式的数据读写功能进行介绍. 2.功能实现说明 2. ...
- MySQL 8.0.18 在 Windows Server 2019 上的安装(ZIP)公开
AskScuti MySQL : Windows Server 2019 安装 MySQL 8.0 温馨提示:为了展现我最“魅力”的一面,请用谷歌浏览器撩我. 一切就绪,点我开撩
- COS上传图片和显示图片
写这篇文章之前,我也是刚刚实现COS上传和显示图片.我百度了好多相关文章,COS上传图片成功的文章不少,上传后显示图片的文章几乎没有.于是写一篇记录下. COS上传图片推荐链接:https://blo ...
- ASP.NET MVC 获取表单数据
public class Person { public string Name{get;set;} public string Phone{get;set;} } view层 @model Mode ...
- 连续张量理解和contiguous()方法使用,view和reshape的区别
连续张量理解和contiguous()方法使用,view和reshape的区别 待办 内存共享: 下边的x内存布局是从0开始的,y内存布局,不是从0开始的张量 For example: when yo ...
- PLSQL官网下载地址
记录一下 https://www.allroundautomations.com/registered/plsqldev.html
- Ubuntu18.04 一条命令安装caffe问题
由于caffe安装坑很多,而且caffe框架很久不更新了,微调对框架影响不大,所以对与ubuntu18.04在caffe官网提供了一条命令安装,避免很多踩坑痛苦. CPU的一条命令安装: sudo a ...
- Java开发新闻管理系统(前后端)+爬虫百度、新浪等新闻
ForFuture News 新闻管理系统 项目演示地址:http://www.ganquanzhong.top [注]:文档下 ...
- 《Java程序设计》第十一周学习总结
20175334 <Java程序设计>第十一周学习总结 教材学习内容总结 第十三章 URL类 一个URL对象通常包含最基本的三部分信息:协议.地址.资源. URL对象调用 InputStr ...
- codeforces 1269D. Domino for Young (二分图证明/结论题)
链接:https://codeforces.com/contest/1269/problem/D 题意:给一个不规则的网格,在上面放置多米诺骨牌,多米诺骨牌长度要么是1x2,要么是2x1大小,问最多放 ...