人事管理系统8

员工管理(分页查询、查看详情页、修改):

1. 分页查询
Staff.java中加入部门名和岗位名两个属性以及对应的getset方法。这两个属性没有数据库字段对应, 仅供前端显示用:
private String departname; //部门名属性没有数据库字段对应,仅供前端显示用
private String postname; //岗位名属性没有数据库字段对应,仅供前端显示用
加入前端页面staff-list.html,设置StaffController.java
@GetMapping("/staff")
public String list() {
return "admin/staff-list";
}
StaffController.java
@GetMapping("/staff/listall")
@ResponseBody
public Result listAll(@RequestParam Map<String, Object> params) {
int page = Integer.parseInt(params.get("page").toString());
int limit = Integer.parseInt(params.get("limit").toString());
int start = (page - 1) * limit;
return staffService.getStaffsList(start, limit);
}
StaffMapper.java
List<Staff> findStaffList(@Param("start") int start, @Param("limit") int
limit);
int getTotalStaffs();
StaffMapper.xml
<select id="findStaffList" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from staff
order by id desc
<if test="start!=null and limit!=null">
limit #{start},#{limit}
</if>
</select>
<select id="getTotalStaffs" resultType="int">
select count(*) from staff
</select>
StaffService.java
Result getStaffsList(int start, int limit);
StaffServiceImpl.java
public Result getStaffsList(int start, int limit) {
List<Staff> staffList = staffMapper.findStaffList(start, limit); //分页
查询到对应页的员工信息列表
for (Staff s : staffList) { //依次遍历员工列表
Department department =
departmentMapper.selectByPrimaryKey(s.getDepartId());
//根据每个员工的部门号确定对应的部门
s.setDepartname(department.getDname());
//把该部门的部门名设置到该员工的部门名属性
Post post = postMapper.selectByPrimaryKey(s.getPostId());
//根据每个员工的岗位号确定对应的岗位
s.setPostname(post.getPname());
//把该岗位的岗位名设置到该员工的岗位名属性
if (s.getEnddate().before(new Date())) { //如果试用期结束日期在当前日期
之前
s.setStatus("转正");
} else {
s.setStatus("试用期");
}
staffMapper.updateByPrimaryKeySelective(s);
}
Result result = new Result();
result.setCode(0);
result.setMsg("查询成功!");
result.setCount(staffMapper.getTotalStaffs());
result.setData(staffList);
return result;
}
2. 查看详情页
修改Staff.java中所有时间属性的格式:
import java.sql.Date; //时间类的包
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date birthday;
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date entrydate;
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date startdate;
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date enddate;
StaffService.java
Staff getStaffById(Integer id);
StaffServiceImpl.java
@Override
public Staff getStaffById(Integer id) {
return staffMapper.selectByPrimaryKey(id);
}
StaffController.java
@GetMapping("/staff/view")
public String staffView(@RequestParam Integer id, Model model) {
Staff staff = staffService.getStaffById(id); //查找对应id号的员工信息
Department department =
departmentService.getDepartmentById(staff.getDepartId());
//根据该员工的部门号确定对应的部门
staff.setDepartname(department.getDname());
//把该部门的部门名设置到该员工的部门名属性
Post post = postService.getPostById(staff.getPostId());
//根据该员工的岗位号确定对应的岗位
staff.setPostname(post.getPname());
//把该岗位的岗位名设置到该员工的岗位名属性
model.addAttribute("staffInfo", staff);
return "admin/staff-view";
}
3.
DepartmentService.java
List<Department> getDepartmentList();
DepartmentServiceImpl.java
@Override
public List<Department> getDepartmentList() {
return
departmentMapper.findDepartmentList(0,departmentMapper.getTotalDepartments());
}
PostService.java
List<Post> getPostsList();
PostServiceImpl.java
@Override
public List<Post> getPostsList() {
return postMapper.findPostList(0, postMapper.getTotalPosts());
}
StaffController.java中显示被改员工信息(后端往前端送数据):
@GetMapping("/staff/edit")
public String gotostaffEdit(@RequestParam Integer id, Model model) {
Staff staff = staffService.getStaffById(id);
Department department =
departmentService.getDepartmentById(staff.getDepartId());
staff.setDepartname(department.getDname()); //部门名
Post post = postService.getPostById(staff.getPostId());
staff.setPostname(post.getPname()); //岗位名
model.addAttribute("staffInfo", staff);
String sex[] = {"男", "女"};
String nation[] = {"汉族", "蒙古族", "回族", "藏族", "维吾尔族", "苗族", "彝
族", "壮族", "布依族", "朝鲜族", "满族", "侗族", "瑶族", "白族", "土家族",
"哈尼族", "哈萨克族", "傣族", "黎族", "傈僳族", "佤族", "畲族", "高山
族", "拉祜族", "水族", "东乡族", "纳西族", "景颇族", "柯尔克孜族",
"土族", "达斡尔族", "仫佬族", "羌族", "布朗族", "撒拉族", "毛南族", "仡
佬族", "锡伯族", "阿昌族", "普米族", "塔吉克族", "怒族", "乌孜别克族",
"俄罗斯族", "鄂温克族", "德昂族", "保安族", "裕固族", "京族", "塔塔尔
族", "独龙族", "鄂伦春族", "赫哲族", "门巴族", "珞巴族", "基诺族"};
String education[] = {"高中及以下", "大专", "本科", "研究生"};
String degree[] = {"无学位", "学士", "双学士", "硕士", "博士"};
model.addAttribute("sex", sex); //性别列表
model.addAttribute("nation", nation); //民族列表
model.addAttribute("education", education); //学历列表
model.addAttribute("degree", degree); //学位列表
model.addAttribute("departs", departmentService.getDepartmentList());
//部门列表
model.addAttribute("posts", postService.getPostsList()); //岗位列表
return "admin/staff-edit";
}
StaffService.java
Result saveStaff(Staff staff);
StaffServiceImpl.java
@Override
public Result saveStaff(Staff staff) {
Result result = new Result();
if (staffMapper.updateByPrimaryKeySelective(staff)) {
result.setCode(0);
result.setMsg("修改成功!");
} else {
result.setCode(1);
result.setMsg("修改失败!");
}
return result;
}
StaffController.java输入修改信息后提交(前端往后端送数据):
@PostMapping("/staff/edit")
@ResponseBody
public Result saveStaff(@RequestBody Map<String, Object> map) throws
ParseException {
Staff staff =
staffService.getStaffById(Integer.parseInt(map.get("id").toString()));
staff.setSname(map.get("sname").toString());
staff.setSex(map.get("sex").toString());
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date date = fmt.parse(map.get("birthday").toString());
java.sql.Date dayDateSql = new java.sql.Date(date.getTime());
staff.setBirthday(dayDateSql);
staff.setSid(map.get("sid").toString());
staff.setDepartId(Integer.parseInt(map.get("depart_id").toString()));
staff.setPostId(Integer.parseInt(map.get("post_id").toString()));
date = fmt.parse(map.get("entrydate").toString());
dayDateSql = new java.sql.Date(date.getTime());
staff.setEntrydate(dayDateSql);
staff.setNation(map.get("nation").toString());
staff.setNativeplace(map.get("nativeplace").toString());
staff.setStel(map.get("stel").toString());
staff.setSemail(map.get("semail").toString());
staff.setEducation(map.get("education").toString());
staff.setDegree(map.get("degree").toString());
staff.setUniversity(map.get("university").toString());
staff.setMajor(map.get("major").toString());
date = fmt.parse(map.get("startdate").toString());
dayDateSql = new java.sql.Date(date.getTime());
staff.setStartdate(dayDateSql);
date = fmt.parse(map.get("enddate").toString());
dayDateSql = new java.sql.Date(date.getTime());
staff.setEnddate(dayDateSql);
if (staff.getEnddate().before(new Date())) {
staff.setStatus("转正");
} else {
staff.setStatus("试用期");
}
return staffService.saveStaff(staff);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值