mirror of
https://github.com/Snailclimb/JavaGuide
synced 2025-06-20 22:17:09 +08:00
commit
9ae6c3f924
@ -227,7 +227,7 @@ public OneService getService(status) {
|
||||
|
||||
我们一般使用 `@Autowired` 注解自动装配 bean,要想把类标识成可用于 `@Autowired` 注解自动装配的 bean 的类,采用以下注解可实现:
|
||||
|
||||
- `@Component` :通用的注解,可标注任意类为 `Spring` 组件。如果一个Bean不知道属于拿个层,可以使用`@Component` 注解标注。
|
||||
- `@Component` :通用的注解,可标注任意类为 `Spring` 组件。如果一个Bean不知道属于哪个层,可以使用`@Component` 注解标注。
|
||||
- `@Repository` : 对应持久层即 Dao 层,主要用于数据库相关操作。
|
||||
- `@Service` : 对应服务层,主要涉及一些复杂的逻辑,需要用到 Dao层。
|
||||
- `@Controller` : 对应 Spring MVC 控制层,主要用户接受用户请求并调用 Service 层返回数据给前端页面。
|
||||
|
Loading…
x
Reference in New Issue
Block a user