实体类
JavaBean有特定的写法:
-
必须要有一个无参构造
-
属性必须私有化
-
必须有对应的get/set方法;
一般用来和数据库的字段做映射 ORM;
ORM :对象关系映射
-
表--->类
-
字段-->属性
-
行记录---->对象
User表
ID | name | age | address |
---|---|---|---|
0 | 苍老师 | 18 | 日本 |
1 | 小泽老师 | 18 | 日本 |
2 | 女朋友 | 18 | 被窝 |
class People{
private int id;
private String name;
private int id;
private String address;
}
class A{
new People(1,"凯莉",3,"西海岸");
new People(2,"阿甘左",3,"后街");
new People(3,"赛利亚",3,"格兰之森");
}
JSP
<%@ page import="Dto.User" %><%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2020/12/24
Time: 22:06
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
User user=new User();
user.setId(1);
user.setName("小泽老师");
int id=user.getId();
String name= user.getName();
%>
<%--存值--%>
<jsp:useBean id="User" class="Dto.User" scope="page"/>
<jsp:setProperty name="User" property="id" value="0"/>
<jsp:setProperty name="User" property="name" value="苍老师"/>
<%--取值--%>
id:<jsp:getProperty name="User" property="id"/>
name:<jsp:getProperty name="User" property="name"/>
</body>
</html>