在ssm框架下对数据库表单的增查删改操作(分页查询)
一.编写流程
配置ssm整合——创建Java实体类——创建服务方法service接口——创建方法与参数的映射关系Mapper接口——创建实体类方法实现类Impl实现service接口中的方法——设置方法与数据库逻辑的Mapper.xml配置——编写逻辑控制层control类
二样例
建立公司员工库,并对员工库进行增查删改以及分页操作
1创建员工实体类、分页page类
员工类
- public class Employee {
- /**
- * 员工测试类
- */
- private int id; //编号
- private String name; //姓名
- private String email; //邮箱
- private String phone; //电话
- private Date add_date; //创建日期
- private String position; //职位
- 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 String getEmail() {
- return email;
- }
- public void setEmail(String email) {
- this.email = email;
- }
- public String getPhone() {
- return phone;
- }
- public void setPhone(String phone) {
- this.phone = phone;
- }
- public Date getAdd_date() {
- return add_date;
- }
- public void setAdd_date(Date add_date) {
- this.add_date = add_date;
- }
- public String getPosition() {
- return position;
- }
- public void setPosition(String position) {
- this.position = position;
- }
- @Override
- public String toString() {
- return "Employee [id=" + id + ", name=" + name + ", email=" + email + ", phone=" + phone + ", add_date="
- + add_date + ", position=" + position + "]";
- }
- }
页面类
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 |
|
来自CODE的代码片
Page.java
2.创建服务方法service接口
1 2 3 4 5 6 7 8 9 10 11 |
|
来自CODE的代码片
EmployeeService.java
3.创建方法与参数的映射关系Mapper接口
1 2 3 4 5 6 7 8 9 10 11 |
|
来自CODE的代码片
EmployeeMapper.java
4.创建实体类方法实现类Impl实现service接口中的方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
来自CODE的代码片
EmployeeImpl.java
5.设置方法与数据库逻辑的Mapper.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 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 |
|
来自CODE的代码片
EmployMapper.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 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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|