Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
醒狮指南
JavaGuide
提交
2a85d5d1
J
JavaGuide
项目概览
醒狮指南
/
JavaGuide
与 Fork 源项目一致
从无法访问的项目Fork
通知
5
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
JavaGuide
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
2a85d5d1
编写于
8月 18, 2020
作者:
ipofss
提交者:
GitHub
8月 18, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update spring-annotations.md
上级
63664e6a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
6 addition
and
7 deletion
+6
-7
docs/system-design/framework/spring/spring-annotations.md
docs/system-design/framework/spring/spring-annotations.md
+6
-7
未找到文件。
docs/system-design/framework/spring/spring-annotations.md
浏览文件 @
2a85d5d1
...
...
@@ -7,10 +7,10 @@
-
[
1. `@SpringBootApplication`
](
#1-springbootapplication
)
-
[
2. Spring Bean 相关
](
#2-spring-bean-%e7%9b%b8%e5%85%b3
)
-
[
2.1. `@Autowired`
](
#21-autowired
)
-
[
2.2. `Component`,`@Repository`,`@Service`, `@Controller`
](
#22-componentrepositoryservice-controller
)
-
[
2.2. `
@
Component`,`@Repository`,`@Service`, `@Controller`
](
#22-componentrepositoryservice-controller
)
-
[
2.3. `@RestController`
](
#23-restcontroller
)
-
[
2.4. `@Scope`
](
#24-scope
)
-
[
2.5. `Configuration`
](
#25-configuration
)
-
[
2.5. `
@
Configuration`
](
#25-configuration
)
-
[
3. 处理常见的 HTTP 请求类型
](
#3-%e5%a4%84%e7%90%86%e5%b8%b8%e8%a7%81%e7%9a%84-http-%e8%af%b7%e6%b1%82%e7%b1%bb%e5%9e%8b
)
-
[
3.1. GET 请求
](
#31-get-%e8%af%b7%e6%b1%82
)
-
[
3.2. POST 请求
](
#32-post-%e8%af%b7%e6%b1%82
)
...
...
@@ -130,14 +130,14 @@ public class UserController {
}
```
#### 2.2. `Component`,`@Repository`,`@Service`, `@Controller`
#### 2.2. `
@
Component`,`@Repository`,`@Service`, `@Controller`
我们一般使用
`@Autowired`
注解让 Spring 容器帮我们自动装配 bean。要想把类标识成可用于
`@Autowired`
注解自动装配的 bean 的类,可以采用以下注解实现:
-
`@Component`
:通用的注解,可标注任意类为
`Spring`
组件。如果一个 Bean 不知道属于哪个层,可以使用
`@Component`
注解标注。
-
`@Repository`
: 对应持久层即 Dao 层,主要用于数据库相关操作。
-
`@Service`
: 对应服务层,主要涉及一些复杂的逻辑,需要用到 Dao 层。
-
`@Controller`
: 对应 Spring MVC 控制层,主要用
户
接受用户请求并调用 Service 层返回数据给前端页面。
-
`@Controller`
: 对应 Spring MVC 控制层,主要用
于
接受用户请求并调用 Service 层返回数据给前端页面。
#### 2.3. `@RestController`
...
...
@@ -168,9 +168,9 @@ public Person personSingleton() {
-
request : 每一次 HTTP 请求都会产生一个新的 bean,该 bean 仅在当前 HTTP request 内有效。
-
session : 每一次 HTTP 请求都会产生一个新的 bean,该 bean 仅在当前 HTTP session 内有效。
#### 2.5. `Configuration`
#### 2.5. `
@
Configuration`
一般用来声明配置类,可以使用
`@Component`
注解替代,不过使用
`Configuration`
注解声明配置类更加语义化。
一般用来声明配置类,可以使用
`@Component`
注解替代,不过使用
`
@
Configuration`
注解声明配置类更加语义化。
```
java
@Configuration
...
...
@@ -302,7 +302,6 @@ public class UserRegisterRequest {
private
String
userName
;
@NotBlank
private
String
password
;
@FullName
@NotBlank
private
String
fullName
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录