JavaBean
JavaBean is a reusable component written in JAVA language. To be written as a JavaBean, the class must be concrete and public, and have a parameterless constructor . JavaBean exposes the member attributes of internal domains by providing public methods that conform to the consistent design pattern, and obtains them with set and get methods. As we all know, attribute names conform to this pattern, and other Java classes can discover and manipulate the attributes of these JavaBeans through the introspection mechanism (reflection mechanism).
JavaBean is an ordinary Java class. The entity class belongs to JavaBean
Generally used to map with database fields (ORM)
Entity classes generally correspond to table results in the database one-to-one
ORM: object-relational mapping
- Database tables-Java classes
- Table fields-attributes of the class
- Row records-objects of the class
id | name | age | address |
---|---|---|---|
1 | Zhang San | 1 | Kashgar |
2 | Li Si | 2 | Hami |
3 | Wang Wu | 3 | Wada |
class People{
private int id;
private string name;
private int age;
private string address;
}
class A{
new People(1,"张三",1,"喀什")
new People(2,"李四",2,"哈密")
new People(3,"王五",3,"和田")
}
Specific writing:
- No-parameter construct
- Property must be privatized
- There must be a corresponding get/set method