23.MyBatis使用注解

 

MyBatis使用注解CRUD

UserDao.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.course.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.course.vo.User;

public interface UserDao {

@Insert("insert into user(name, age, address, birthday) values(#{name}, #{age}, #{address}, #{birthday})")
public void addUser(User user);

@Update("update user set name=#{name}, age=#{age}, address=#{address}, birthday=#{birthday} where id=#{id}")
public void updateUser(User user);

@Delete("delete from user where id=#{val}")
public void deleteUser(Integer id);

@Select("select * from user where id=#{val}")
public User getUserById(Integer id);

@Select("select * from user")
public List<User> getAllUser();

}

mybatis.cfg.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">

<!-- MyBatis的整体配置 -->
<configuration>

<!-- 配置Mapper.xml文件 -->
<mappers>
<!-- 使用注解的时候使用class属性 -->
<mapper class="com.course.dao.UserDao" />
</mappers>

</configuration>

test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.course.test;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import com.course.dao.EmployeeDao;
import com.course.dao.UserDao;
import com.course.util.MyBatisUtil;
import com.course.vo.Employee;
import com.course.vo.EmployeeVo;
import com.course.vo.EmployeeVo3;
import com.course.vo.User;

public class MainTest {

private SqlSession sqlSession = MyBatisUtil.openSqlSession();
private UserDao userDao = sqlSession.getMapper(UserDao.class);

@Test
public void addUser() {
User user1 = new User("userTest", 10, "address1", new Date());
userDao.addUser(user1);
MyBatisUtil.closeSqlSession(sqlSession);
}

@Test
public void updateUser() {
User user1 = new User();
user1.setId(160);
user1.setName("UserUpdate");
userDao.updateUser(user1);
MyBatisUtil.closeSqlSession(sqlSession);
}

@Test
public void deleteUser() {
userDao.deleteUser(160);
MyBatisUtil.closeSqlSession(sqlSession);
}

@Test
public void getOneUser() {
User user = userDao.getUserById(159);
System.out.println(user);
MyBatisUtil.closeSqlSession(sqlSession);
}

@Test
public void getAllUser() {
List<User> userList = userDao.getAllUser();
for (User user : userList) {
System.out.println(user);
}
MyBatisUtil.closeSqlSession(sqlSession);
}

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
DEBUG [main] - ==>  Preparing: insert into user(name, age, address, birthday) values(?, ?, ?, ?) 
DEBUG [main] - ==> Parameters: userTest(String), 10(Integer), address1(String), 2021-09-14 16:46:49.273(Timestamp)
DEBUG [main] - <== Updates: 1

DEBUG [main] - ==> Preparing: update user set name=?, age=?, address=?, birthday=? where id=?
DEBUG [main] - ==> Parameters: UserUpdate(String), null, null, null, 161(Integer)
DEBUG [main] - <== Updates: 1

DEBUG [main] - ==> Preparing: delete from user where id=?
DEBUG [main] - ==> Parameters: 161(Integer)
DEBUG [main] - <== Updates: 1

DEBUG [main] - ==> Preparing: select * from user where id=?
DEBUG [main] - ==> Parameters: 159(Integer)
DEBUG [main] - <== Total: 1

DEBUG [main] - ==> Preparing: select * from user
DEBUG [main] - ==> Parameters:
DEBUG [main] - <== Total: 154

使用MyBatis注解实现多对一

第一种方法

Employee.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.course.vo;

import java.util.Date;

public class Employee {

private Integer employee_id;
private String employee_name;
private String employee_gender;
private Integer age;
private Date hire_date;
private Integer department_id;

private Department department;

public Employee() {
super();
}

public Employee(Integer employee_id, String employee_name, String employee_gender, Integer age, Date hire_date,
Integer department_id, String department_name, String location) {
super();
this.employee_id = employee_id;
this.employee_name = employee_name;
this.employee_gender = employee_gender;
this.age = age;
this.hire_date = hire_date;
this.department_id = department_id;
}

public Integer getEmployee_id() {
return employee_id;
}

public void setEmployee_id(Integer employee_id) {
this.employee_id = employee_id;
}

public String getEmployee_name() {
return employee_name;
}

public void setEmployee_name(String employee_name) {
this.employee_name = employee_name;
}

public String getEmployee_gender() {
return employee_gender;
}

public void setEmployee_gender(String employee_gender) {
this.employee_gender = employee_gender;
}

public Integer getAge() {
return age;
}

public void setAge(Integer age) {
this.age = age;
}

public Date getHire_date() {
return hire_date;
}

public void setHire_date(Date hire_date) {
this.hire_date = hire_date;
}

public Integer getDepartment_id() {
return department_id;
}

public void setDepartment_id(Integer department_id) {
this.department_id = department_id;
}

public Department getDepartment() {
return department;
}

public void setDepartment(Department department) {
this.department = department;
}

@Override
public String toString() {
return "Employee [employee_id=" + employee_id + ", employee_name=" + employee_name + ", employee_gender="
+ employee_gender + ", age=" + age + ", hire_date=" + hire_date + ", department_id=" + department_id
+ ", department=" + department + "]";
}

}

EmployeeDao.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package com.course.dao;

import java.util.List;

import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import com.course.vo.Employee;

public interface EmployeeDao {

@Select("select * from employee e LEFT JOIN department d ON e.department_id = d.department_id")
@ResultMap("com.course.dao.EmployeeMapper.myEmployeeMap")
public List<Employee> getAllEmployee();

}

EmployeeMapper.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">


<mapper namespace="com.course.dao.EmployeeMapper">

<resultMap id="myEmployeeBaseMap" type="Employee">
<id property="employee_id" column="employee_id" />
<result property="employee_name" column="employee_name" />
<result property="employee_gender" column="employee_gender" />
<result property="age" column="age" />
<result property="hire_date" column="hire_date" />
<result property="department_id" column="department_id" />
</resultMap>

<resultMap id="myEmployeeMap" type="Employee" extends="myEmployeeBaseMap">
<!-- 建立关联关系 -->
<association property="department" javaType="Department">
<id property="department_id" column="department_id" />
<result property="department_name" column="department_name" />
<result property="location" column="location" />
</association>
</resultMap>

</mapper>

mybatis.cfg.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">

<!-- MyBatis的整体配置 -->
<configuration>

<!-- 配置Mapper.xml文件 -->
<mappers>
<!-- 使用注解的时候使用class属性 -->
<!--
xml最好放在class的前面
-->
<mapper resource="com/course/mapper/EmployeeMapper.xml" />
<mapper class="com.course.dao.EmployeeDao"/>
</mappers>

</configuration>

test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.course.test;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import com.course.dao.EmployeeDao;
import com.course.util.MyBatisUtil;
import com.course.vo.Employee;

public class EmployeeTest {

private SqlSession sqlSession = MyBatisUtil.openSqlSession();
private EmployeeDao employeeDao = sqlSession.getMapper(EmployeeDao.class);

@Test
public void getAllEmployee() {
List<Employee> employeelist = employeeDao.getAllEmployee();
for (Employee employee : employeelist) {
System.out.println(employee);
}

}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
DEBUG [main] - ==>  Preparing: select * from employee e LEFT JOIN department d ON e.department_id = d.department_id 
DEBUG [main] - ==> Parameters:
DEBUG [main] - <== Total: 10
Employee [employee_id=1, employee_name=staff1, employee_gender=M, age=31, hire_date=Wed Sep 01 00:00:00 CST 2021, department_id=1, department=Department [department_id=1, department_name=Retail Department, location=5 floor]]
Employee [employee_id=2, employee_name=staff2, employee_gender=F, age=32, hire_date=Thu Sep 02 00:00:00 CST 2021, department_id=2, department=Department [department_id=2, department_name=Operations Management Department, location=6 floor]]
Employee [employee_id=3, employee_name=staff3, employee_gender=M, age=33, hire_date=Fri Sep 03 00:00:00 CST 2021, department_id=3, department=Department [department_id=3, department_name=Information technology department, location=9 floor]]
Employee [employee_id=4, employee_name=staff4, employee_gender=F, age=34, hire_date=Sat Sep 04 00:00:00 CST 2021, department_id=4, department=Department [department_id=4, department_name=accounting department, location=10 floor]]
Employee [employee_id=5, employee_name=staff5, employee_gender=M, age=35, hire_date=Sun Sep 05 00:00:00 CST 2021, department_id=5, department=Department [department_id=5, department_name=Marketing Department, location=12 floor]]
Employee [employee_id=6, employee_name=staff6, employee_gender=F, age=36, hire_date=Mon Sep 06 00:00:00 CST 2021, department_id=1, department=Department [department_id=1, department_name=Retail Department, location=5 floor]]
Employee [employee_id=7, employee_name=staff7, employee_gender=M, age=37, hire_date=Tue Sep 07 00:00:00 CST 2021, department_id=2, department=Department [department_id=2, department_name=Operations Management Department, location=6 floor]]
Employee [employee_id=8, employee_name=staff8, employee_gender=F, age=38, hire_date=Wed Sep 08 00:00:00 CST 2021, department_id=3, department=Department [department_id=3, department_name=Information technology department, location=9 floor]]
Employee [employee_id=9, employee_name=staff9, employee_gender=M, age=39, hire_date=Thu Sep 09 00:00:00 CST 2021, department_id=4, department=Department [department_id=4, department_name=accounting department, location=10 floor]]
Employee [employee_id=10, employee_name=staff10, employee_gender=F, age=40, hire_date=Fri Sep 10 00:00:00 CST 2021, department_id=5, department=Department [department_id=5, department_name=Marketing Department, location=12 floor]]

第二种方法

EmployeeDao.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.course.dao;

import java.util.List;

import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.course.vo.Department;
import com.course.vo.Employee;

public interface EmployeeDao {

@Select("select * from employee e LEFT JOIN department d ON e.department_id = d.department_id")
@Results({@Result(property = "employee_id", column = "employee_id"),
@Result(property = "employee_name", column = "employee_name"),
@Result(property = "employee_gender", column = "employee_gender"),
@Result(property = "age", column = "age"),
@Result(property = "hire_date", column = "hire_date"),
@Result(property = "department_id", column = "department_id"),
@Result(property = "department", javaType = Department.class,
column = "department_id",
one = @One(select = "com.course.dao.DepartmentDao.getDepartmentById"))
})
public List<Employee> getAllEmployee2();

}

新建DepartmentDao.java

1
2
3
4
5
6
7
8
9
10
11
12
package com.course.dao;

import org.apache.ibatis.annotations.Select;

import com.course.vo.Department;

public interface DepartmentDao {

@Select("select * from department where department_id = #{value}")
public Department getDepartmentById(Integer departmentId);

}

mybatis.cfg.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">

<!-- MyBatis的整体配置 -->
<configuration>

<!-- 配置Mapper文件 -->
<mappers>
<!-- 使用注解的时候使用class属性 -->
<mapper class="com.course.dao.EmployeeDao"/>
<mapper class="com.course.dao.DepartmentDao"/>
</mappers>

</configuration>

test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.course.test;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import com.course.dao.EmployeeDao;
import com.course.util.MyBatisUtil;
import com.course.vo.Employee;

public class EmployeeTest {

private SqlSession sqlSession = MyBatisUtil.openSqlSession();
private EmployeeDao employeeDao = sqlSession.getMapper(EmployeeDao.class);

@Test
public void getAllEmployee2() {
List<Employee> employeelist = employeeDao.getAllEmployee2();
for (Employee employee : employeelist) {
System.out.println(employee);
}

MyBatisUtil.closeSqlSession(sqlSession);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
DEBUG [main] - ==>  Preparing: select * from employee e LEFT JOIN department d ON e.department_id = d.department_id 
DEBUG [main] - ==> Parameters:
DEBUG [main] - ====> Preparing: select * from department where department_id = ?
DEBUG [main] - ====> Parameters: 1(Integer)
DEBUG [main] - <==== Total: 1
DEBUG [main] - ====> Preparing: select * from department where department_id = ?
DEBUG [main] - ====> Parameters: 2(Integer)
DEBUG [main] - <==== Total: 1
DEBUG [main] - ====> Preparing: select * from department where department_id = ?
DEBUG [main] - ====> Parameters: 3(Integer)
DEBUG [main] - <==== Total: 1
DEBUG [main] - ====> Preparing: select * from department where department_id = ?
DEBUG [main] - ====> Parameters: 4(Integer)
DEBUG [main] - <==== Total: 1
DEBUG [main] - ====> Preparing: select * from department where department_id = ?
DEBUG [main] - ====> Parameters: 5(Integer)
DEBUG [main] - <==== Total: 1
DEBUG [main] - <== Total: 10
Employee [employee_id=1, employee_name=staff1, employee_gender=M, age=31, hire_date=Wed Sep 01 00:00:00 CST 2021, department_id=1, department=Department [department_id=1, department_name=Retail Department, location=5 floor]]
Employee [employee_id=2, employee_name=staff2, employee_gender=F, age=32, hire_date=Thu Sep 02 00:00:00 CST 2021, department_id=2, department=Department [department_id=2, department_name=Operations Management Department, location=6 floor]]
Employee [employee_id=3, employee_name=staff3, employee_gender=M, age=33, hire_date=Fri Sep 03 00:00:00 CST 2021, department_id=3, department=Department [department_id=3, department_name=Information technology department, location=9 floor]]
Employee [employee_id=4, employee_name=staff4, employee_gender=F, age=34, hire_date=Sat Sep 04 00:00:00 CST 2021, department_id=4, department=Department [department_id=4, department_name=accounting department, location=10 floor]]
Employee [employee_id=5, employee_name=staff5, employee_gender=M, age=35, hire_date=Sun Sep 05 00:00:00 CST 2021, department_id=5, department=Department [department_id=5, department_name=Marketing Department, location=12 floor]]
Employee [employee_id=6, employee_name=staff6, employee_gender=F, age=36, hire_date=Mon Sep 06 00:00:00 CST 2021, department_id=1, department=Department [department_id=1, department_name=Retail Department, location=5 floor]]
Employee [employee_id=7, employee_name=staff7, employee_gender=M, age=37, hire_date=Tue Sep 07 00:00:00 CST 2021, department_id=2, department=Department [department_id=2, department_name=Operations Management Department, location=6 floor]]
Employee [employee_id=8, employee_name=staff8, employee_gender=F, age=38, hire_date=Wed Sep 08 00:00:00 CST 2021, department_id=3, department=Department [department_id=3, department_name=Information technology department, location=9 floor]]
Employee [employee_id=9, employee_name=staff9, employee_gender=M, age=39, hire_date=Thu Sep 09 00:00:00 CST 2021, department_id=4, department=Department [department_id=4, department_name=accounting department, location=10 floor]]
Employee [employee_id=10, employee_name=staff10, employee_gender=F, age=40, hire_date=Fri Sep 10 00:00:00 CST 2021, department_id=5, department=Department [department_id=5, department_name=Marketing Department, location=12 floor]]

使用MyBatis注解实现一对多

Deparment.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.course.vo;

import java.util.Set;

public class Department {

private Integer department_id;
private String department_name;
private String location;

private Set<Employee> employees;

public Department() {
super();
}

public Department(String department_name, String location) {
super();
this.department_name = department_name;
this.location = location;
}

public Integer getDepartment_id() {
return department_id;
}
public void setDepartment_id(Integer department_id) {
this.department_id = department_id;
}
public String getDepartment_name() {
return department_name;
}
public void setDepartment_name(String department_name) {
this.department_name = department_name;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}

public Set<Employee> getEmployees() {
return employees;
}

public void setEmployees(Set<Employee> employees) {
this.employees = employees;
}

@Override
public String toString() {
return "Department [department_id=" + department_id + ", department_name=" + department_name + ", location="
+ location + ", employees=" + employees + "]";
}

}

DepartmentDao.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.course.dao;

import java.util.List;
import java.util.Set;

import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.course.vo.Department;

public interface DepartmentDao {

@Select("select * from department")
@Results({@Result(property = "department_id", column = "department_id"),
@Result(property = "department_name", column = "department_name"),
@Result(property = "location", column = "location"),
@Result(property = "employees", javaType = Set.class,
column = "department_id",
many = @Many(select = "com.course.dao.EmployeeDao.getEmployeeByDepartment"))})
public List<Department> getAllDepartment();

}

EmployeeDao.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package com.course.dao;

import java.util.List;

import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.course.vo.Department;
import com.course.vo.Employee;

public interface EmployeeDao {

@Select("select * from employee where department_id = #{value}")
public List<Employee> getEmployeeByDepartment(Integer departmentId);

}

test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.course.test;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import com.course.dao.DepartmentDao;
import com.course.util.MyBatisUtil;
import com.course.vo.Department;

public class DepartmentTest {

private SqlSession sqlSession = MyBatisUtil.openSqlSession();
private DepartmentDao departmentDao = sqlSession.getMapper(DepartmentDao.class);

@Test
public void getAllDepartment() {
List<Department> list = departmentDao.getAllDepartment();
for (Department department : list) {
System.out.println(department);
}

MyBatisUtil.closeSqlSession(sqlSession);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
DEBUG [main] - ==>  Preparing: select * from department 
DEBUG [main] - ==> Parameters:
DEBUG [main] - ====> Preparing: select * from employee where department_id = ?
DEBUG [main] - ====> Parameters: 1(Integer)
DEBUG [main] - <==== Total: 2
DEBUG [main] - ====> Preparing: select * from employee where department_id = ?
DEBUG [main] - ====> Parameters: 2(Integer)
DEBUG [main] - <==== Total: 2
DEBUG [main] - ====> Preparing: select * from employee where department_id = ?
DEBUG [main] - ====> Parameters: 3(Integer)
DEBUG [main] - <==== Total: 2
DEBUG [main] - ====> Preparing: select * from employee where department_id = ?
DEBUG [main] - ====> Parameters: 4(Integer)
DEBUG [main] - <==== Total: 2
DEBUG [main] - ====> Preparing: select * from employee where department_id = ?
DEBUG [main] - ====> Parameters: 5(Integer)
DEBUG [main] - <==== Total: 2
DEBUG [main] - ====> Preparing: select * from employee where department_id = ?
DEBUG [main] - ====> Parameters: 6(Integer)
DEBUG [main] - <==== Total: 0
DEBUG [main] - <== Total: 6
Department [department_id=1, department_name=Retail Department, location=5 floor, employees=[Employee [employee_id=6, employee_name=staff6, employee_gender=F, age=36, hire_date=Mon Sep 06 00:00:00 CST 2021, department_id=1, department=null], Employee [employee_id=1, employee_name=staff1, employee_gender=M, age=31, hire_date=Wed Sep 01 00:00:00 CST 2021, department_id=1, department=null]]]
Department [department_id=2, department_name=Operations Management Department, location=6 floor, employees=[Employee [employee_id=7, employee_name=staff7, employee_gender=M, age=37, hire_date=Tue Sep 07 00:00:00 CST 2021, department_id=2, department=null], Employee [employee_id=2, employee_name=staff2, employee_gender=F, age=32, hire_date=Thu Sep 02 00:00:00 CST 2021, department_id=2, department=null]]]
Department [department_id=3, department_name=Information technology department, location=9 floor, employees=[Employee [employee_id=8, employee_name=staff8, employee_gender=F, age=38, hire_date=Wed Sep 08 00:00:00 CST 2021, department_id=3, department=null], Employee [employee_id=3, employee_name=staff3, employee_gender=M, age=33, hire_date=Fri Sep 03 00:00:00 CST 2021, department_id=3, department=null]]]
Department [department_id=4, department_name=accounting department, location=10 floor, employees=[Employee [employee_id=9, employee_name=staff9, employee_gender=M, age=39, hire_date=Thu Sep 09 00:00:00 CST 2021, department_id=4, department=null], Employee [employee_id=4, employee_name=staff4, employee_gender=F, age=34, hire_date=Sat Sep 04 00:00:00 CST 2021, department_id=4, department=null]]]
Department [department_id=5, department_name=Marketing Department, location=12 floor, employees=[Employee [employee_id=5, employee_name=staff5, employee_gender=M, age=35, hire_date=Sun Sep 05 00:00:00 CST 2021, department_id=5, department=null], Employee [employee_id=10, employee_name=staff10, employee_gender=F, age=40, hire_date=Fri Sep 10 00:00:00 CST 2021, department_id=5, department=null]]]
Department [department_id=6, department_name=personnel department, location=15 floor, employees=[]]