javaBean
是一种实体类
JavaBean有特定的写法
-
必须有一个无参构造
-
属性必须私有化
-
必须有对应的get,set方法
一般用来和数据库字段做映射:ORM
ORM:对象关系映射
-
表-->类
-
字段-->属性
-
行记录-->对象
实现
创建数据库,
创建对应实体类
//实体类,和数据库中的表结构一一对应 public class People { private int id; private String name; private int age; private String address; public People(int id, String name, int age, String address) { this.id = id; this.name = name; this.age = age; this.address = address; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } @Override public String toString() { return "People{" + "id=" + id + ", name='" + name + '\'' + ", age=" + age + ", address='" + address + '\'' + '}'; } }
用jsp去创建一个实体对象
<body> <% // People people = new People(); %> <jsp:useBean id="people" class="com.gu.pojo.People" scope="page"> </jsp:useBean> <jsp:setProperty name="people" property="address" value="hunan"></jsp:setProperty> <jsp:setProperty name="people" property="name" value="gugu"></jsp:setProperty> <jsp:setProperty name="people" property="age" value="18"></jsp:setProperty> <jsp:setProperty name="people" property="id" value="1"></jsp:setProperty> <jsp:getProperty name="people" property="name"/> <jsp:getProperty name="people" property="id"/> <jsp:getProperty name="people" property="age"/> <jsp:getProperty name="people" property="address"/> </body>
over
标签:name,age,public,String,javaBean,address,id,day,105 From: https://www.cnblogs.com/GUGUZIZI/p/17430568.html