You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
825 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

## 分层解耦
三层架构
单一职责原则,使得代码更清晰,更易维护。可读性强。更容易复用。
1. 控制层,接受前段发送的请求,对请求进行处理,然后返回结果。
controller
2. 业务逻辑层,处理具体的业务逻辑
service
3. 数据访问层,处理与数据库的交互。
dao(Data Access Object)
为了完成分层解耦,防止空指针异常,不能在类中直接创建另一层的对象
为了解决这个问题我们引入IOC与DI即反转控制与依赖注入。
用容器来管理对象,将对象的创建与使用分离。
1. IOC容器
将Dao和Service的创建权交给容器容器负责创建对象并将对象注入到Service中。
加上注解@Component
2. DI
为Controller和Service注入所依赖对象。
加上@Autowired