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标签也可以对实体类创建对象并赋值:
<jsp:useBean id="people" class="com.kuang.pojo.People" scope="page"/>
<jsp:setProperty name="people" property="id" value="1"/>
<jsp:setProperty name="people" property="name" value="1"/>
<jsp:setProperty name="people" property="age" value="12"/>
<jsp:setProperty name="people" property="address" value="西安"/>
<%--获取对象中的值--%>
id:<jsp:getProperty name="people" property="id"/>
姓名:<jsp:getProperty name="people" property="name"/>
年龄:<jsp:getProperty name="people" property="age"/>
地址:<jsp:getProperty name="people" property="address"/>
标签:12,people,private,实体类,西安,id,JavaBean 来源: https://www.cnblogs.com/H-scholar/p/15757422.html