【新建实体类:DeptEntity.java】
package com.lyh.entity;
public class DeptEntity {
private String deptName;
private Double salary;
public String getDeptName() {
return deptName;
}
public void setDeptName(String deptName) {
this.deptName = deptName;
}
public Double getSalary() {
return salary;
}
public void setSalary(Double salary) {
this.salary = salary;
}
@Override
public String toString() {
return "DeptEntity{" +
"deptName='" + deptName + '\'' +
", salary=" + salary +
'}';
}
}
【新建实体类:PersonEntity.java】
package com.lyh.entity;
public class PersonEntity {
private String name;
private String password;
private DeptEntity dept;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public DeptEntity getDept() {
return dept;
}
public void setDept(DeptEntity dept) {
this.dept = dept;
}
@Override
public String toString() {
return "PersonEntity{" +
"name='" + name + '\'' +
", password='" + password + '\'' +
", dept=" + dept +
'}';
}
}
【index.jsp】
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isErrorPage="true"%>
<html>
<head>
<title>首页</title>
</head>
<body>
<form action="/testPOJO/1">
<label for="name">姓名</label>
<input type="text" id="name" name ="name" placeholder="请输入姓名..." />
<label for="password">密码</label>
<input type="password" id="password" name ="password" placeholder="请输入密码..." />
<label for="deptName">部门名</label>
<input type="text" id="deptName" name ="dept.deptName" placeholder="请输入部门名..." />
<label for="salary">工资</label>
<input type="text" id="salary" name ="dept.salary" placeholder="请输入工资..." />
<input type="submit" value="test POJO"/>
</form>
</body>
</html>
【hello.jsp】
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isErrorPage="