day 105 - 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>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?