Advantages:
Isolate details
Reduce coupling between codes
Improve code scalability and maintainability
##Note:
## ##DAO mode provides an interface for operations required to access relational data systems, separates data access from business logic, and provides an object-oriented data access interface to the upper layer.The DAO
pattern achieves two-layer separation:
The division of labor between codes is clear, and the data access layer code does not affect the business logic layer code, which is also consistent with The single-function principle reduces coupling and improves code reusability. .
DAO interface: Define all operations on the database as abstract methods and place them in the interface. A variety of implementations can be provided
Properties configuration file
Example:
Driver=com.mysql.jdbc.Driver //添加加载驱动的字符串Url=jdbc:mysql://localhost:3306/epet //添加链接的字符串 Username=epetAdmin //数据库用户名 Password=root //数据库用户密码
Properties
Method
Description |
##String getProperty(String key) |
Object setProperties(String key,String value) | |
Void load(InputStream instr) | |
Void clear() | |
Characteristics of entity classes | General attributes of entity classes are modified with private | Defining entities based on business needs and encapsulation requirements The class performs getter/setter methods and is responsible for reading and assigning attributes. Generally, the public modification
If the entity class implements the serializable interface. You should define the attribute serialVersionUID to solve the serialization problem of different versions.
The above is the detailed content of DAO mode in mysql. For more information, please follow other related articles on the PHP Chinese website!