JavaBean实体类
JavaBean
就是实体类
JavaBean有特定的写法:
- 必须要有一个无参构造
- 属性必须私有化
- 必须有对应的get/set方法
一般用来和数据库的字段做映射:ORM
ORM:对象关系映射
- 表----->类
- 字段---->属性
- 行记录---->对象
例如:
| id | name | age | address |
|---|---|---|---|
| 1 | 1 | 12 | 西安 |
| 2 | 2 | 121 | 西安 |
| 3 | 3 | 12 | 西安 |
class People{
private int id;
private String name;
private int age;
private String address;
}
class A{
new people(1,"1",12,"西安");
new people(2,"2",121,"西安");
new people(3,"3",12,"西安");
}
jsp标签也可以对实体类创建对象并赋值:
<%--获取对象中的值--%>
id:
姓名:
年龄:
地址: