1
2 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4 4.0.0
5
6 com
7 manager
8 0.0.1-SNAPSHOT
9 jar
10
11 manager
12 Demo project for Spring Boot
13
14
15 org.springframework.boot
16 spring-boot-starter-parent
17 2.0.4.RELEASE
18
19
20
21
22 UTF-8
23 UTF-8
24 1.8
25
26
27
28
29 org.springframework.boot
30 spring-boot-starter-jdbc
31
32
33 org.springframework.boot
34 spring-boot-starter-thymeleaf
35
36
37 org.springframework.boot
38 spring-boot-starter-web
39
40
41
42 org.mybatis.spring.boot
43 mybatis-spring-boot-starter
44 1.3.2
45
46
47 mysql
48 mysql-connector-java
49 runtime
50
51
52 org.springframework.boot
53 spring-boot-starter-test
54 test
55
56
57
58 com.alibaba
59 druid
60 1.1.9
61
62
63
64 com.alipay.sdk
65 alipay-sdk-java
66 3.0.0
67
68
69
70 commons-logging
71 commons-logging
72 1.1.1
73
74
75
76 com.alibaba
77 fastjson
78 1.2.47
79
80
81
82 javax.servlet
83 jstl
84 1.2
85
86
87
88
89
90
91 org.springframework.boot
92 spring-boot-maven-plugin
93
94
95
96
97
98
99 application.properties代码:
100
101 server.port=80
102 spring.mvc.view.prefix=classpath:/templates/
103 spring.mvc.view.suffix=.html
104 #thymeleaf start
105 spring.thymeleaf.mode=HTML5
106 spring.thymeleaf.encoding=UTF-8
107 #开发时关闭缓存,不然没法看到实时页面
108 spring.thymeleaf.cache=false
109 #thymeleaf end
110 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
111 spring.datasource.url=jdbc:mysql:// localhost:3306/ManageDB?useUnicode=true&characterEncoding=utf-8
112 spring.datasource.username=root
113 spring.datasource.password=994994
114 spring.datasource.driverClassName=com.mysql.jdbc.Driver
115 mybatis.mapper-locations=classpath:/mybatis/* .xml
116 mybatis.type-aliases-package=com.manager.pojo
117 mybatis.configuration.auto-mapping-behavior=full
118 mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
119 #logging.level.org.springframework=WARN
120 #logging.level.org.spring.springboot.dao=DEBUG
121 #logging.file=logs/spring-boot-logging.log
122 员工实体类代码:
123
124 package com.manager.pojo;
125
126
127 import com.fasterxml.jackson.annotation.JsonFormat;
128
129 import java.util.Date;
130
131 public class Employees {
132
133 private Integer e_Id;
134 private String e_Code;
135 private String e_LoginName;
136 private String e_Pwd;
137 private String e_RealName;
138 private Sex e_Sex;
139 private String e_Phone;
140 private Role e_Role;
141 private Dept e_DeptId;
142 private Employees e_Superior;
143 private Status e_Status;
144 @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
145 private Date e_CreateTime;
146 private Employees e_ModifyId;
147 @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
148 private Date e_ModifyTime;
149 private String e_Description;
150 private Date e_LastLoginTime;
151
152 public Sex getE_Sex() {
153 return e_Sex;
154 }
155
156 public void setE_Sex(Sex e_Sex) {
157 this.e_Sex = e_Sex;
158 }
159
160 public Status getE_Status() {
161 return e_Status;
162 }
163
164 public void setE_Status(Status e_Status) {
165 this.e_Status = e_Status;
166 }
167
168 public Employees getE_Superior() {
169 return e_Superior;
170 }
171
172 public void setE_Superior(Employees e_Superior) {
173 this.e_Superior = e_Superior;
174 }
175
176 public Employees(){}
177
178 public Employees(String loginName){
179 this.e_LoginName = loginName;
180 }
181
182 public Employees(Integer id){this.e_Id = id;}
183
184 public String getE_Code() {
185 return e_Code;
186 }
187
188 public void setE_Code(String e_Code) {
189 this.e_Code = e_Code;
190 }
191
192 public Date getE_LastLoginTime() {
193 return e_LastLoginTime;
194 }
195
196 public void setE_LastLoginTime(Date e_LastLoginTime) {
197 this.e_LastLoginTime = e_LastLoginTime;
198 }
199
200 public Integer getE_Id() {
201 return e_Id;
202 }
203
204 public void setE_Id(Integer e_Id) {
205 this.e_Id = e_Id;
206 }
207
208 public String getE_LoginName() {
209 return e_LoginName;
210 }
211
212 public void setE_LoginName(String e_LoginName) {
213 this.e_LoginName = e_LoginName;
214 }
215
216 public String getE_Pwd() {
217 return e_Pwd;
218 }
219
220 public void setE_Pwd(String e_Pwd) {
221 this.e_Pwd = e_Pwd;
222 }
223
224 public String getE_RealName() {
225 return e_RealName;
226 }
227
228 public void setE_RealName(String e_RealName) {
229 this.e_RealName = e_RealName;
230 }
231
232 public String getE_Phone() {
233 return e_Phone;
234 }
235
236 public void setE_Phone(String e_Phone) {
237 this.e_Phone = e_Phone;
238 }
239
240 public Role getE_Role() {
241 return e_Role;
242 }
243
244 public void setE_Role(Role e_Role) {
245 this.e_Role = e_Role;
246 }
247
248 public Dept getE_DeptId() {
249 return e_DeptId;
250 }
251
252 public void setE_DeptId(Dept e_DeptId) {
253 this.e_DeptId = e_DeptId;
254 }
255
256 public Date getE_CreateTime() {
257 return e_CreateTime;
258 }
259
260 public void setE_CreateTime(Date e_CreateTime) {
261 this.e_CreateTime = e_CreateTime;
262 }
263
264 public Employees getE_ModifyId() {
265 return e_ModifyId;
266 }
267
268 public void setE_ModifyId(Employees e_ModifyId) {
269 this.e_ModifyId = e_ModifyId;
270 }
271
272 public Date getE_ModifyTime() {
273 return e_ModifyTime;
274 }
275
276 public void setE_ModifyTime(Date e_ModifyTime) {
277 this.e_ModifyTime = e_ModifyTime;
278 }
279
280 public String getE_Description() {
281 return e_Description;
282 }
283
284 public void setE_Description(String e_Description) {
285 this.e_Description = e_Description;
286 }
287 }
288 部门实体类代码:
289
290 package com.manager.pojo;
291
292 public class Dept {
293
294 private Integer d_Id;
295 private String d_Name;
296 private String d_Intro;
297
298 public String getD_Intro() {
299 return d_Intro;
300 }
301
302 public void setD_Intro(String d_Intro) {
303 this.d_Intro = d_Intro;
304 }
305
306 public Integer getD_Id() {
307 return d_Id;
308 }
309
310 public void setD_Id(Integer d_Id) {
311 this.d_Id = d_Id;
312 }
313
314 public String getD_Name() {
315 return d_Name;
316 }
317
318 public void setD_Name(String d_Name) {
319 this.d_Name = d_Name;
320 }
321 }
322 角色表实体类代码:
323
324 package com.manager.pojo;
325 import com.fasterxml.jackson.annotation.JsonFormat;
326
327 import java.util.Date;
328
329 public class Role {
330
331 private Integer r_Id;
332 private String r_Code;
333 private String r_Name;
334 private Dept r_DeptNo;
335 private Employees r_ModifyId;
336 @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
337 private Date r_ModifyTime;
338 private String r_Description;
339
340 public Role(){
341
342 }
343
344 public Role(Integer id){
345 this.r_Id = id;
346 }
347
348 public Integer getR_Id() {
349 return r_Id;
350 }
351
352 public void setR_Id(Integer r_Id) {
353 this.r_Id = r_Id;
354 }
355
356 public String getR_Code() {
357 return r_Code;
358 }
359
360 public void setR_Code(String r_Code) {
361 this.r_Code = r_Code;
362 }
363
364 public String getR_Name() {
365 return r_Name;
366 }
367
368 public void setR_Name(String r_Name) {
369 this.r_Name = r_Name;
370 }
371
372 public Dept getR_DeptNo() {
373 return r_DeptNo;
374 }
375
376 public void setR_DeptNo(Dept r_DeptNo) {
377 this.r_DeptNo = r_DeptNo;
378 }
379
380 public Employees getR_ModifyId() {
381 return r_ModifyId;
382 }
383
384 public void setR_ModifyId(Employees r_ModifyId) {
385 this.r_ModifyId = r_ModifyId;
386 }
387
388 public Date getR_ModifyTime() {
389 return r_ModifyTime;
390 }
391
392 public void setR_ModifyTime(Date r_ModifyTime) {
393 this.r_ModifyTime = r_ModifyTime;
394 }
395
396 public String getR_Description() {
397 return r_Description;
398 }
399
400 public void setR_Description(String r_Description) {
401 this.r_Description = r_Description;
402 }
403 }
404 员工类xml代码:
405
406
407 408 " http://mybatis.org/dtd/mybatis-3-mapper.dtd ">
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435 select e.*,d.*,r.*,s.*,st.*,e1.e_realName e1_realName,e1.e_id e1_id from employees e,dept d, role r,sex s,status
436 st,employees e1
437
438 e.e_role = r.r_id and e.e_deptid = d.d_id and e.e_modifyId = e1.e_id and e.e_sex = s.sex_id and e.e_status =
439 st.st_id
440
441 and e.e_Superior = #{e_Id}
442
443
444
445
446
447 select e.*,d.*,r.*,s.*,st.*,e1.e_realName e1_realName,e1.e_id e1_id from employees e,dept d, role r,sex s,status
448 st,employees e1
449
450 e.e_role = r.r_id and e.e_deptid = d.d_id and e.e_modifyId = e1.e_id and e.e_sex = s.sex_id and e.e_status =
451 st.st_id
452
453 and e.e_loginName = #{e_LoginName}
454
455
456 and e.e_id = #{e_Id}
457
458
459
460
461
462 select e.*,d.*,r.*,s.*,st.*,e1.e_realName e1_realName,e1.e_id e1_id from employees e,dept d, role r,sex s,status
463 st,employees e1
464
465 e.e_role = r.r_id and e.e_deptid = d.d_id and e.e_modifyId = e1.e_id and e.e_sex = s.sex_id and e.e_status =
466 st.st_id
467
468 and e.e_RealName like concat('%',#{employee.e_RealName},'%')
469
470 limit #{begin},#{end}
471
472
473
474
475 select count(*) from employees e,dept d, role r,sex s,status st
476
477 e.e_role = r.r_id and e.e_deptid = d.d_id and e.e_modifyId = e.e_id and e.e_sex = s.sex_id and e.e_status =
478 st.st_id
479
480 and e.e_RealName like concat('%',#{e_RealName},'%')
481
482
483
484
485 update employees
486
487
488 e_lastLoginTime = #{e_LastLoginTime},
489
490
491 e_Phone = #{e_Phone},
492
493
494 e_Pwd = #{e_Pwd},
495
496
497 e_Code = #{e_Code},
498
499
500 e_RealName = #{e_RealName},
501
502
503 e_Description = #{e_Description},
504
505
506 e_Sex = #{e_Sex.sex_Id},
507
508
509 e_Status = #{e_Status.st_Id},
510
511
512 e_DeptId = #{e_DeptId.d_Id},
513
514
515
516
517
518 delete from employees where e_id = #{e_Id}
519
520
521
522 insert into employees values (default,#{e_Code},#{e_LoginName},#{e_Pwd},#{e_RealName},#{e_Sex.sex_Id},#{e_Phone},#{e_Role.r_Id},#{e_DeptId.d_Id},#{e_Superior.e_Id},#{e_Status.st_Id},#{e_CreateTime},#{e_ModifyId.e_Id},#{e_ModifyTime},#{e_LastLoginTime},#{e_Description})
523
524
525 select * from employees where 1=1
526
527 and e_Code = #{e_Code}
528
529
530
531
532 select * from employees where 1=1
533
534 and e_LoginName = #{e_LoginName}
535
536
537
538 部门xml代码:
539
540
541 542 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
543 " http://mybatis.org/dtd/mybatis-3-mapper.dtd ">
544
545
546
547 select * from dept
548
549
550
551 角色xml代码:
552
553
554 555 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
556 " http://mybatis.org/dtd/mybatis-3-mapper.dtd ">
557
558
559
560
561
562
563
564
565
566
567
568
569 SELECT r.*,e.*,d.* FROM role r,employees e,dept d
570
571 r.r_modifyId = e.e_id AND r.r_deptNo = d.d_id
572
573 and r_Name like concat('%',#{role.r_Name},'%')
574
575 limit #{begin},#{end}
576
577
578
579
580 select count(*) from role r,employees e,dept d
581
582 r.r_modifyId = e.e_id AND r.r_deptNo = d.d_id
583
584 and r_Name like concat('%',#{r_Name},'%')
585
586
587
588
589
590 SELECT r.*,e.*,d.* FROM role r,employees e,dept d
591
592 r.r_modifyId = e.e_id AND r.r_deptNo = d.d_id
593
594 and r_id = #{r_Id}
595
596
597
598
599
600 select * from role
601
602
603
604 update role
605
606
607 r_deptNo = #{r_DeptNo.d_Id},
608
609
610 r_ModifyId = #{r_ModifyId.e_Id},
611
612
613 r_ModifyTime = #{r_ModifyTime},
614
615
616 r_Description = #{r_Description},
617
618
619
620
621
622 delete from role where r_id = #{r_Id}
623
624
625
626 insert into role values(default,#{r_Code},#{r_Name},#{r_DeptNo.d_Id},#{r_ModifyId.e_Id},#{r_ModifyTime},#{r_Description})
627
628
629
630 select count(*) from role
631
632
633 and r_Code = #{r_Code}
634
635
636 and r_Name = #{r_Name}
637
638
639
640
641 员工Mapper层代码:
642
643 package com.manager.mapper;
644
645 import com.manager.pojo.Employees;
646
647 import java.util.List;
648 import java.util.Map;
649
650 public interface EmployeesMapper {
651 Employees getEmployees(Employees employees);
652
653 int alterEmployees(Employees employees);
654
655 List employeeList(Map map);
656
657 int count(Employees employees);
658
659 List lowerList(Employees employees);
660
661 int deleteEmployees(Employees employees);
662
663 int addEmployees(Employees employees);
664
665 Employees existEmployeeCode(Employees employees);
666
667 Employees existEmployeeLoginName(Employees employees);
668 }
669 部门Mapper层代码:
670
671 package com.manager.mapper;
672
673 import com.manager.pojo.Dept;
674
675 import java.util.List;
676
677 public interface DeptMapper {
678 List deptAll();
679 }
680 角色Mapper层代码:
681
682 package com.manager.mapper;
683
684 import com.manager.pojo.Role;
685
686 import java.util.List;
687 import java.util.Map;
688
689 public interface RoleMapper {
690 List roleList(Map map);
691
692 int count(Role role);
693
694 Role getRole(Role role);
695
696 List roleAll();
697
698 int modify(Role role);
699
700 int delRole(Role role);
701
702 int addRole(Role role);
703
704 int validationRole(Role role);
705 }
706 员工Service层代码:
707
708 package com.manager.service.users;
709
710 import com.manager.pojo.Employees;
711
712 import java.util.List;
713
714 public interface EmployeesService {
715 Employees getEmployees(Employees employees);
716
717 int alterEmployees(Employees employees);
718
719 List employeeList(Integer begin, Integer end, Employees employees);
720
721 int count(Employees employees);
722
723 List lowerList(Employees employees);
724
725 int deleteEmployees(Employees employees);
726
727 int addEmployees(Employees employees);
728
729 String existEmployeeCode(Employees employees);
730
731 String existEmployeeLoginName(Employees employees);
732 }
733 员工ServiceImpl代码:
734
735 package com.manager.service.users;
736
737 import com.alibaba.fastjson.JSON;
738 import com.manager.mapper.EmployeesMapper;
739 import com.manager.pojo.Employees;
740 import org.apache.ibatis.session.SqlSession;
741 import org.springframework.stereotype.Service;
742 import org.springframework.transaction.annotation.Transactional;
743
744 import javax.annotation.Resource;
745 import java.util.HashMap;
746 import java.util.List;
747 import java.util.Map;
748
749 @Service
750 public class EmployeesServiceImpl implements EmployeesService {
751 @Resource
752 private EmployeesMapper employeesMapper;
753
754 @Override
755 public Employees getEmployees(Employees employees) {
756 Employees newEmployees = employeesMapper.getEmployees(employees);
757 return newEmployees;
758 }
759
760 @Override
761 public List lowerList(Employees employees) {
762 return employeesMapper.lowerList(employees);
763 }
764
765 @Override
766 public int deleteEmployees(Employees employees) {
767 return employeesMapper.deleteEmployees(employees);
768 }
769
770 @Override
771 public int addEmployees(Employees employees) {
772 return employeesMapper.addEmployees(employees);
773 }
774
775 @Override
776 public String existEmployeeCode(Employees employees) {
777 return JSON.toJSONString(employeesMapper.existEmployeeCode(employees));
778 }
779
780 @Override
781 public String existEmployeeLoginName(Employees employees) {
782 return JSON.toJSONString(employeesMapper.existEmployeeLoginName(employees));
783 }
784
785 @Override
786 @Transactional
787 public int alterEmployees(Employees employees) {
788 return employeesMapper.alterEmployees(employees);
789 }
790
791 @Override
792 public List employeeList(Integer begin, Integer end, Employees employees) {
793 Map map = new HashMap<>();
794 map.put("begin", begin);
795 map.put("end", end);
796 map.put("employee", employees);
797 return employeesMapper.employeeList(map);
798 }
799
800 @Override
801 public int count(Employees employees) {
802 return employeesMapper.count(employees);
803 }
804 }
805 部门Service层代码:
806
807 package com.manager.service.dept;
808
809 import com.manager.pojo.Dept;
810
811 import java.util.List;
812
813 public interface DeptService {
814 List deptAll();
815 }
816 部门ServiceImpl代码:
817
818 package com.manager.service.dept;
819
820 import com.manager.mapper.DeptMapper;
821 import com.manager.pojo.Dept;
822 import org.springframework.stereotype.Service;
823
824 import javax.annotation.Resource;
825 import java.util.HashMap;
826 import java.util.List;
827 import java.util.Map;
828
829 @Service
830 public class DeptServiceImpl implements DeptService {
831 @Resource
832 private DeptMapper deptMapper;
833
834 @Override
835 public List deptAll() {
836 return deptMapper.deptAll();
837 }
838
839 }
840 角色Service层代码:
841
842 package com.manager.service.role;
843
844 import com.manager.pojo.Role;
845
846 import java.util.List;
847
848 public interface RoleService {
849 List roleList(Role role,Integer begin,Integer end);
850
851 int count(Role role);
852
853 Role getRole(Role role);
854
855 List roleAll();
856
857 int modify(Role role);
858
859 int delRole(Role role);
860
861 int addRole(Role role);
862
863 int validationRole(Role role);
864 }
865 角色ServiceImpl代码:
866
867 package com.manager.service.role;
868
869 import com.manager.mapper.RoleMapper;
870 import com.manager.pojo.Role;
871 import org.springframework.stereotype.Service;
872 import org.springframework.transaction.annotation.Transactional;
873
874 import javax.annotation.Resource;
875 import java.util.HashMap;
876 import java.util.List;
877 import java.util.Map;
878
879 @Service
880 public class RoleServiceImpl implements RoleService {
881 @Resource
882 private RoleMapper roleMapper;
883
884 @Override
885 public List roleList(Role role,Integer begin,Integer end) {
886 Map map = new HashMap();
887 map.put("role",role);
888 map.put("begin",begin);
889 map.put("end",end);
890 return roleMapper.roleList(map);
891 }
892
893 @Override
894 public int count(Role role) {
895 return roleMapper.count(role);
896 }
897
898 @Override
899 public Role getRole(Role role) {
900 return roleMapper.getRole(role);
901 }
902
903 @Override
904 public List roleAll() {
905 return roleMapper.roleAll();
906 }
907
908 @Override
909 @Transactional
910 public int modify(Role role) {
911 return roleMapper.modify(role);
912 }
913
914 @Override
915 @Transactional
916 public int delRole(Role role) {
917 return roleMapper.delRole(role);
918 }
919
920 @Override
921 public int addRole(Role role) {
922 return roleMapper.addRole(role);
923 }
924
925 @Override
926 public int validationRole(Role role) {
927 return roleMapper.validationRole(role);
928 }
929 }
930 员工Controller控制层代码:
931
932 package com.manager.control.employees;
933
934 import com.alibaba.fastjson.JSON;
935 import com.manager.pojo.Dept;
936 import com.manager.pojo.Employees;
937 import com.manager.pojo.Role;
938 import com.manager.service.dept.DeptService;
939 import com.manager.service.role.RoleService;
940 import com.manager.service.users.EmployeesService;
941 import com.manager.util.MD5Util;
942 import com.manager.util.PageUtil;
943 import com.manager.util.PwdUtil;
944 import org.springframework.stereotype.Controller;
945 import org.springframework.ui.Model;
946 import org.springframework.web.bind.annotation.*;
947 import org.springframework.web.servlet.ModelAndView;
948
949 import javax.annotation.Resource;
950 import javax.servlet.http.HttpSession;
951 import java.util.Date;
952 import java.util.HashMap;
953 import java.util.List;
954 import java.util.Map;
955
956 @Controller
957 public class EmployeesContorller {
958 @Resource
959 private EmployeesService employeesService;
960 @Resource
961 private DeptService deptService;
962 @Resource
963 private RoleService roleService;
964
965 @RequestMapping(value = "/login", method = RequestMethod.POST)
966 @ResponseBody
967 public Object loginajax(HttpSession session, Employees employees) {
968 Map map = new HashMap<>();
969 Employees employee = employeesService.getEmployees(employees);
970 if (employee != null) {
971 String pwd = MD5Util.EncoderByMd5(employees.getE_Pwd());
972 if (pwd.equals(employee.getE_Pwd())) {
973 session.setAttribute("loginEmployee", employee);//登陆成功保存会话
974 employee.setE_LastLoginTime(new Date());
975 employeesService.alterEmployees(employee);
976 } else {
977 map.put("msg", "false");
978 }
979 } else {
980 map.put("msg", "null");
981 }
982 return map;
983 }
984
985 @RequestMapping("/login.html")
986 public String login() {
987 return "login";
988 }
989
990 @RequestMapping("/userOut")
991 public String userOut(HttpSession session) {
992 session.invalidate();
993 return "login";
994 }
995
996 @RequestMapping(value = "/modifyEmployees")
997 @ResponseBody
998 public Object modifyEmployees(Employees employees) {
999 int i = employeesService.alterEmployees(employees);
1000 if (i == 1) {
1001 return "true";
1002 } else {
1003 return "false";
1004 }
1005 }
1006
1007 @RequestMapping("/JumpEmpAdd")
1008 public String jumpEmpAdd(Model model,Employees employees) {
1009 List depts = deptService.deptAll();
1010 List roles = roleService.roleAll();
1011 List employee = employeesService.employeeList(1,99,employees);
1012 model.addAttribute("depts",depts);
1013 model.addAttribute("roles",roles);
1014 model.addAttribute("employees",employee);
1015 return "sysemployeeAdd";
1016 }
1017
1018 @RequestMapping("/AddEmployees")
1019 @ResponseBody
1020 public Object addEmployees(Employees employees,HttpSession session) {
1021 employees.setE_CreateTime(new Date());
1022 employees.setE_LastLoginTime(new Date());
1023 employees.setE_ModifyTime(new Date());
1024 employees.setE_ModifyId((Employees) session.getAttribute("loginEmployee"));
1025 int i = employeesService.addEmployees(employees);
1026 if (i == 1) {
1027 return "true";
1028 } else {
1029 return "false";
1030 }
1031 }
1032
1033 @RequestMapping("/DeleteEmployees")
1034 @ResponseBody
1035 public Object deleteEmployee(Employees employees) {
1036 int i = employeesService.deleteEmployees(employees);
1037 if (i == 1) {
1038 return "true";
1039 } else {
1040 return "false";
1041 }
1042 }
1043
1044 @RequestMapping(value = "modifyPwd", method = RequestMethod.POST)
1045 @ResponseBody
1046 public Object modifyPwd(HttpSession session, PwdUtil pwd) {
1047 Map map = new HashMap<>();
1048 int result = 0;
1049 Employees employees = employeesService.getEmployees(new Employees(pwd.getLoginName()));
1050 if (employees.getE_Pwd().equals(MD5Util.EncoderByMd5(pwd.getOldPwd()))) {
1051 if (pwd.getNewPwd().equals(pwd.getConfirmNewPwd())) {
1052 employees.setE_Pwd(MD5Util.EncoderByMd5(pwd.getConfirmNewPwd()));
1053 result = employeesService.alterEmployees(employees);
1054 if (result == 1) {
1055 session.invalidate();
1056 map.put("msg", "true");
1057 } else {
1058 map.put("msg", "false");
1059 }
1060 } else {
1061 map.put("msg", "Don't match");
1062 }
1063 } else {
1064 map.put("msg", "error");
1065 }
1066 return map;
1067 }
1068
1069 @RequestMapping("/getEmployee")
1070 public ModelAndView getEmployee(HttpSession session) {
1071 ModelAndView mv = new ModelAndView();
1072 Employees employee = (Employees) session.getAttribute("loginEmployee");
1073 Employees newEmployee = employeesService.getEmployees(employee);
1074 mv.addObject("newEmployee", newEmployee);
1075 mv.setViewName("syspersonalInfo");
1076 return mv;
1077 }
1078
1079 @RequestMapping(value = "/employeeList", method = RequestMethod.POST)
1080 @ResponseBody
1081 public Object employeeList(@RequestParam(name = "draw", required = false, defaultValue = "0") int draw,
1082 @RequestParam(name = "start", required = false, defaultValue = "0") int start,
1083 @RequestParam(name = "length", required = false, defaultValue = "0") int length,
1084 Employees employees) {
1085 PageUtil pageUtil = new PageUtil<>();
1086 List employeesList = employeesService.employeeList(start, length, employees);
1087 int count = employeesService.count(employees);
1088 pageUtil.setData(employeesList);
1089 pageUtil.setDraw(draw);
1090 pageUtil.setRecordsTotal(count);
1091 pageUtil.setRecordsFiltered(count);
1092 return pageUtil;
1093 }
1094
1095 @RequestMapping("/getEmployee/{id}/{str}")
1096 public ModelAndView getEmployee(@PathVariable Integer id, @PathVariable String str) {
1097 ModelAndView mv = new ModelAndView();
1098 Employees employee = new Employees(id);
1099 Employees newEmployee = employeesService.getEmployees(employee);
1100 List depts = deptService.deptAll();
1101 mv.addObject("newEmployee", newEmployee);
1102 mv.addObject("depts", depts);
1103 if (str.equals("get")) {
1104 mv.setViewName("sysemployeeInfo");
1105 } else {
1106 mv.setViewName("sysemployeemodify");
1107 }
1108 return mv;
1109 }
1110
1111 @RequestMapping("/ExistCode")
1112 @ResponseBody
1113 public Object existCode(Employees employees){
1114 return JSON.toJSONString(employeesService.existEmployeeCode(employees));
1115 }
1116
1117 @RequestMapping("/ExistLoginName")
1118 @ResponseBody
1119 public Object existLoginName(Employees employees){
1120 return JSON.toJSONString(employeesService.existEmployeeLoginName(employees));
1121 }
1122 }
1123 部门Controller控制层代码:
1124
1125 package com.manager.control.dept;
1126
1127 import com.manager.pojo.Dept;
1128 import com.manager.service.dept.DeptService;
1129 import com.manager.util.PageUtil;
1130 import org.springframework.stereotype.Controller;
1131 import org.springframework.web.bind.annotation.*;
1132 import org.springframework.web.servlet.ModelAndView;
1133
1134 import javax.annotation.Resource;
1135 import java.util.List;
1136
1137 @Controller
1138 public class DeptContorller {
1139 @Resource
1140 private DeptService deptService;
1141
1142 @RequestMapping(value = "/deptAll",method = RequestMethod.POST)
1143 @ResponseBody
1144 public Object deptAll(){
1145 List depts = deptService.deptAll();
1146 return depts;
1147 }
1148 }
1149 角色Controller控制层代码:
1150
1151 package com.manager.control.role;
1152
1153 import com.manager.pojo.Dept;
1154 import com.manager.pojo.Employees;
1155 import com.manager.pojo.Role;
1156 import com.manager.service.dept.DeptService;
1157 import com.manager.service.role.RoleService;
1158 import com.manager.util.PageUtil;
1159 import org.springframework.stereotype.Controller;
1160 import org.springframework.web.bind.annotation.*;
1161 import org.springframework.web.servlet.ModelAndView;
1162
1163 import javax.annotation.Resource;
1164 import javax.servlet.http.HttpSession;
1165 import java.util.Date;
1166 import java.util.List;
1167
1168 @Controller
1169 public class RoleController {
1170 @Resource
1171 private RoleService roleService;
1172 @Resource
1173 private DeptService deptService;
1174
1175 @RequestMapping(value = "/roleList")
1176 @ResponseBody
1177 public Object roleList(@RequestParam(name = "draw",required = false,defaultValue = "0")int draw,
1178 @RequestParam(name = "start",required = false,defaultValue = "0")int start,
1179 @RequestParam(name = "length",required = false,defaultValue = "0")int length,
1180 Role role){
1181 PageUtil pageUtil = new PageUtil();
1182 int count = roleService.count(role);
1183 List roles = roleService.roleList(role,start,length);
1184 pageUtil.setData(roles);
1185 pageUtil.setDraw(draw);
1186 pageUtil.setRecordsFiltered(count);
1187 pageUtil.setRecordsTotal(count);
1188 return pageUtil;
1189 }
1190
1191 @RequestMapping("/getRole/{id}/{str}")
1192 public ModelAndView getRole(@PathVariable("id")Integer id, @PathVariable("str")String str){
1193 ModelAndView mv = new ModelAndView();
1194 mv.setViewName("sysroleInfo");
1195 List depts = null;
1196 Role role = new Role(id);
1197 Role newRole = roleService.getRole(role);
1198 if(str.equals("modify")){
1199 depts = deptService.deptAll();
1200 mv.setViewName("sysrolemodify");
1201 }
1202 mv.addObject("newRole",newRole);
1203 mv.addObject("depts",depts);
1204 return mv;
1205 }
1206
1207 @RequestMapping(value = "/modifyRole",method = RequestMethod.POST)
1208 @ResponseBody
1209 public Object modifyRole(HttpSession session,Role role){
1210 role.setR_ModifyTime(new Date());
1211 Employees employees = (Employees) session.getAttribute("loginEmployee");
1212 role.setR_ModifyId(employees);
1213 int modify = roleService.modify(role);
1214 if(modify==1){
1215 return "true";
1216 }
1217 return "false";
1218 }
1219
1220 @RequestMapping(value = "/delRole",method = RequestMethod.POST)
1221 @ResponseBody
1222 public Object delRole(Role role){
1223 int i = roleService.delRole(role);
1224 if(i==1){
1225 return "true";
1226 }
1227 return "false";
1228 }
1229
1230 @RequestMapping(value = "/addRole",method = RequestMethod.POST)
1231 @ResponseBody
1232 public Object addRole(HttpSession session,Role role){
1233 role.setR_ModifyTime(new Date());
1234 role.setR_ModifyId((Employees) session.getAttribute("loginEmployee"));
1235 int i = roleService.addRole(role);
1236 if(i==1){
1237 return "true";
1238 }
1239 return "false";
1240 }
1241
1242
1243 @RequestMapping(value = "/validationRole",method = RequestMethod.POST)
1244 @ResponseBody
1245 public Object validationRole(Role role){
1246 int i = roleService.validationRole(role);
1247 if(i==1){
1248 return "true";
1249 }
1250 return "false";
1251 }
1252 }
1253 员工前端页面代码:
1254
1255
1256
1257
1258
1259
1260 欢迎页面-X-admin2.0
1261
1262
1263 1264 content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
1265
1266
1267
1268
1269
1270
1271
1272
1276
1277
1278
1279
1289
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320 员工添加页面代码:
1321
1322
1323 http://www.thymeleaf.org ">
1324
1325
1326 欢迎页面-X-admin2.0
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340 员工信息添加
1341
1445
1446
1447
1448
1449
1450
1461
1462
1463 员工修改页面代码:
1464
1465
1466 http://www.thymeleaf.org ">
1467
1468
1469 欢迎页面-X-admin2.0
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483 员工信息修改
1484
1551
1552
1553
1554
1555
1556
1557
1558
1559
1570
1571
1572 员工详情页面代码:
1573
1574
1575 http://www.thymeleaf.org ">
1576
1577
1578 欢迎页面-X-admin2.0
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591 员工信息
1592
1593
1594
1595 员工编码
1596
1597
1598
1599 员工姓名
1600
1601
1602
1603 性别
1604
1605
1606
1607 状态
1608
1609
1610
1611 所属部门
1612
1613
1614
1615 角色身份
1616
1617
1618
1619 备注信息
1620
1621
1622
1623
1624
1625
1626
1627
1628
1639
1640
1641 员工sysemployees.js代码:
1642
1643 $(document).ready(function () {
1644 x();
1645 });
1646
1647 function x() {
1648 $('#employees').dataTable({
1649 "searching": false,
1650 "serverSide": true,//是否启用服务器处理数据源
1651 "language": {
1652 "lengthMenu": "每页 _MENU_ 条记录",
1653 "zeroRecords": "没有找到记录",
1654 "info": "第 _PAGE_ 页 ( 总共 _PAGES_ 页 )",
1655 "infoEmpty": "无记录",
1656 "infoFiltered": "(从 _MAX_ 条记录过滤)",
1657 "paginate": {
1658 "previous": "上一页",
1659 "next": "下一页",
1660 "processing": "正在处理中...."
1661 }
1662 },
1663 "columnDefs": [
1664 {"title": "员工姓名", "targets": 0},
1665 {"title": "性别", "targets": 1},
1666 {"title": "所在部门", "targets": 2},
1667 {"title": "角色", "targets": 3},
1668 {"title": "状态", "targets": 4},
1669 {"title": "最后修改时间", "targets": 5},
1670 {"title": "操作人", "targets": 6},
1671 {"title": "操作", "targets": 7}
1672 ],
1673 "ajax": {
1674 "url": "/employeeList",
1675 "type": "POST",
1676 "data":function (d) {
1677 d.e_RealName = $("#e_RealName").val();
1678 },
1679 "dataType": "json"
1680 },
1681 "columns": [
1682 {"data": "e_RealName"},
1683 {"data": "e_Sex.sex_Name"},
1684 {"data": "e_DeptId.d_Name"},
1685 {"data": "e_Role.r_Name"},
1686 {"data": "e_Status.st_Name"},
1687 {"data": "e_ModifyTime",defaultContent: ""},
1688 {"data": "e_ModifyId.e_RealName",defaultContent: ""},
1689 {
1690 "data": "e_Id","width":"200px", "render": function (data, type, full, meta) {
1691 return "\n" +
1692 " \n" +
1693 " \n" +
1694 " \n" +
1695 " \n" +
1696 " \n" +
1697 " \n" +
1698 " \n" +
1699 " \n" +
1700 " \n" +
1701 " \n" +
1702 " \n" +
1703 " \n" +
1704 " ";
1705 }
1706 }
1707 ]
1708 });
1709 $(".btn-success").on("click", function () {
1710 $("#employees").DataTable().ajax.reload();
1711 });
1712
1713 $("#employeesQuery").on("click", function () {
1714 $("#employees").DataTable().ajax.reload();
1715 });
1716 }
1717
1718 function delEmployees(id,name) {
1719 layer.confirm("确认删除员工:"+name, {icon: 3, title:'提示'},function () {
1720 $.ajax({
1721 type:"POST",
1722 url:"/DeleteEmployees",
1723 data:{e_Id:id},
1724 dataType:"JSON",
1725 success:function (data) {
1726 if(data == true){
1727 layer.msg("删除成功!");
1728 parent.$("#employees").DataTable().ajax.reload();
1729 return true;
1730 }else {
1731 layer.msg("删除失败!");
1732 return false;
1733 }
1734 }
1735 });
1736 });
1737 }
1738 员工sysemployeesadd.js代码:
1739
1740 function back() {
1741 parent.layer.closeAll();
1742 }
1743
1744 function addEmployee() {
1745 $.ajax({
1746 type: "POST",
1747 url: "/AddEmployees",
1748 data: $("#form1").serialize(),
1749 dataType: "JSON",
1750 success: function (data) {
1751 if (data = "true") {
1752 layer.msg("添加成功!");
1753 parent.$("#employees").DataTable().ajax.reload();
1754 } else {
1755 layer.msg("添加失败!");
1756 }
1757 }
1758 });
1759 }
1760
1761 $(function () {
1762 var e_Code = $("#e_Code");
1763 var e_LoginName = $("#e_LoginName");
1764
1765 e_Code.bind("blur", function () {
1766 $.ajax({
1767 type: "POST",//请求类型
1768 url: "/ExistCode",//请求的url
1769 data: {e_Code: e_Code.val()},//请求参数
1770 dataType: "json",//ajax接口(请求url)返回的数据类型
1771 success: function (data) {//data:返回数据(json对象)
1772 if (data == "null") {//账号可用,正确提示
1773 layer.msg("编号可用!");
1774 } else if (data == "") {//账号不可为空,错的提示
1775 layer.msg("编号不能为空!");
1776 } else {//账号已存在,错的提示
1777 layer.msg("编号已存在!");
1778 }
1779 }
1780 });
1781 });
1782
1783 e_LoginName.bind("blur", function () {
1784 $.ajax({
1785 type: "POST",//请求类型
1786 url: "/ExistLoginName",//请求的url
1787 data: {e_LoginName: e_LoginName.val()},//请求参数
1788 dataType: "json",//ajax接口(请求url)返回的数据类型
1789 success: function (data) {//data:返回数据(json对象)
1790 if (data == "null") {//账号可用,正确提示
1791 layer.msg("账号可用!");
1792 } else if (data == "") {//账号不可为空,错的提示
1793 layer.msg("账号不能为空!");
1794 } else {//账号已存在,错的提示
1795 layer.msg("账号已存在!");
1796 }
1797 }
1798 });
1799 });
1800 })
1801
1802 员工sysemployeesmodify.js代码:
1803
1804 function back() {
1805 parent.layer.closeAll();
1806 }
1807
1808 function updEmployees() {
1809 $.ajax({
1810 type:"POST",
1811 url:"/modifyEmployees",
1812 data:$("#form1").serialize(),
1813 dataType:"JSON",
1814 success:function (data) {
1815 if(data="true"){
1816 layer.msg("修改成功!");
1817 parent.$("#employees").DataTable().ajax.reload();
1818 }else{
1819 layer.msg("修改失败!");
1820 }
1821 }
1822 });
1823
1824 原文: https://blog.csdn.net/weixin_41595700/article/details/85079112
4.0.0 com manager 0.0.1-SNAPSHOT jar manager Demo project for Spring Boot org.springframework.boot spring-boot-starter-parent 2.0.4.RELEASE UTF-8 UTF-8 1.8 org.springframework.boot spring-boot-starter-jdbc org.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-starter-web org.mybatis.spring.boot mybatis-spring-boot-starter 1.3.2 mysql mysql-connector-java runtime org.springframework.boot spring-boot-starter-test test com.alibaba druid 1.1.9 com.alipay.sdk alipay-sdk-java 3.0.0 commons-logging commons-logging 1.1.1 com.alibaba fastjson 1.2.47 javax.servlet jstl 1.2 org.springframework.boot spring-boot-maven-plugin application.properties代码: server.port=80spring.mvc.view.prefix=classpath:/templates/spring.mvc.view.suffix=.html#thymeleaf startspring.thymeleaf.mode=HTML5spring.thymeleaf.encoding=UTF-8#开发时关闭缓存,不然没法看到实时页面spring.thymeleaf.cache=false#thymeleaf endspring.datasource.type=com.alibaba.druid.pool.DruidDataSourcespring.datasource.url=jdbc:mysql://localhost:3306/ManageDB?useUnicode=true&characterEncoding=utf-8spring.datasource.username=rootspring.datasource.password=994994spring.datasource.driverClassName=com.mysql.jdbc.Drivermybatis.mapper-locations=classpath:/mybatis/*.xmlmybatis.type-aliases-package=com.manager.pojomybatis.configuration.auto-mapping-behavior=fullmybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl#logging.level.org.springframework=WARN#logging.level.org.spring.springboot.dao=DEBUG#logging.file=logs/spring-boot-logging.log员工实体类代码: package com.manager.pojo; import com.fasterxml.jackson.annotation.JsonFormat; import java.util.Date; public class Employees { private Integer e_Id; private String e_Code; private String e_LoginName; private String e_Pwd; private String e_RealName; private Sex e_Sex; private String e_Phone; private Role e_Role; private Dept e_DeptId; private Employees e_Superior; private Status e_Status; @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") private Date e_CreateTime; private Employees e_ModifyId; @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") private Date e_ModifyTime; private String e_Description; private Date e_LastLoginTime; public Sex getE_Sex() { return e_Sex; } public void setE_Sex(Sex e_Sex) { this.e_Sex = e_Sex; } public Status getE_Status() { return e_Status; } public void setE_Status(Status e_Status) { this.e_Status = e_Status; } public Employees getE_Superior() { return e_Superior; } public void setE_Superior(Employees e_Superior) { this.e_Superior = e_Superior; } public Employees(){} public Employees(String loginName){ this.e_LoginName = loginName; } public Employees(Integer id){this.e_Id = id;} public String getE_Code() { return e_Code; } public void setE_Code(String e_Code) { this.e_Code = e_Code; } public Date getE_LastLoginTime() { return e_LastLoginTime; } public void setE_LastLoginTime(Date e_LastLoginTime) { this.e_LastLoginTime = e_LastLoginTime; } public Integer getE_Id() { return e_Id; } public void setE_Id(Integer e_Id) { this.e_Id = e_Id; } public String getE_LoginName() { return e_LoginName; } public void setE_LoginName(String e_LoginName) { this.e_LoginName = e_LoginName; } public String getE_Pwd() { return e_Pwd; } public void setE_Pwd(String e_Pwd) { this.e_Pwd = e_Pwd; } public String getE_RealName() { return e_RealName; } public void setE_RealName(String e_RealName) { this.e_RealName = e_RealName; } public String getE_Phone() { return e_Phone; } public void setE_Phone(String e_Phone) { this.e_Phone = e_Phone; } public Role getE_Role() { return e_Role; } public void setE_Role(Role e_Role) { this.e_Role = e_Role; } public Dept getE_DeptId() { return e_DeptId; } public void setE_DeptId(Dept e_DeptId) { this.e_DeptId = e_DeptId; } public Date getE_CreateTime() { return e_CreateTime; } public void setE_CreateTime(Date e_CreateTime) { this.e_CreateTime = e_CreateTime; } public Employees getE_ModifyId() { return e_ModifyId; } public void setE_ModifyId(Employees e_ModifyId) { this.e_ModifyId = e_ModifyId; } public Date getE_ModifyTime() { return e_ModifyTime; } public void setE_ModifyTime(Date e_ModifyTime) { this.e_ModifyTime = e_ModifyTime; } public String getE_Description() { return e_Description; } public void setE_Description(String e_Description) { this.e_Description = e_Description; }}部门实体类代码: package com.manager.pojo; public class Dept { private Integer d_Id; private String d_Name; private String d_Intro; public String getD_Intro() { return d_Intro; } public void setD_Intro(String d_Intro) { this.d_Intro = d_Intro; } public Integer getD_Id() { return d_Id; } public void setD_Id(Integer d_Id) { this.d_Id = d_Id; } public String getD_Name() { return d_Name; } public void setD_Name(String d_Name) { this.d_Name = d_Name; }}角色表实体类代码: package com.manager.pojo;import com.fasterxml.jackson.annotation.JsonFormat; import java.util.Date; public class Role { private Integer r_Id; private String r_Code; private String r_Name; private Dept r_DeptNo; private Employees r_ModifyId; @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") private Date r_ModifyTime; private String r_Description; public Role(){ } public Role(Integer id){ this.r_Id = id; } public Integer getR_Id() { return r_Id; } public void setR_Id(Integer r_Id) { this.r_Id = r_Id; } public String getR_Code() { return r_Code; } public void setR_Code(String r_Code) { this.r_Code = r_Code; } public String getR_Name() { return r_Name; } public void setR_Name(String r_Name) { this.r_Name = r_Name; } public Dept getR_DeptNo() { return r_DeptNo; } public void setR_DeptNo(Dept r_DeptNo) { this.r_DeptNo = r_DeptNo; } public Employees getR_ModifyId() { return r_ModifyId; } public void setR_ModifyId(Employees r_ModifyId) { this.r_ModifyId = r_ModifyId; } public Date getR_ModifyTime() { return r_ModifyTime; } public void setR_ModifyTime(Date r_ModifyTime) { this.r_ModifyTime = r_ModifyTime; } public String getR_Description() { return r_Description; } public void setR_Description(String r_Description) { this.r_Description = r_Description; }}员工类xml代码: select e.*,d.*,r.*,s.*,st.*,e1.e_realName e1_realName,e1.e_id e1_id from employees e,dept d, role r,sex s,status st,employees e1 e.e_role = r.r_id and e.e_deptid = d.d_id and e.e_modifyId = e1.e_id and e.e_sex = s.sex_id and e.e_status = st.st_id and e.e_Superior = #{e_Id} select e.*,d.*,r.*,s.*,st.*,e1.e_realName e1_realName,e1.e_id e1_id from employees e,dept d, role r,sex s,status st,employees e1 e.e_role = r.r_id and e.e_deptid = d.d_id and e.e_modifyId = e1.e_id and e.e_sex = s.sex_id and e.e_status = st.st_id and e.e_loginName = #{e_LoginName} and e.e_id = #{e_Id} select e.*,d.*,r.*,s.*,st.*,e1.e_realName e1_realName,e1.e_id e1_id from employees e,dept d, role r,sex s,status st,employees e1 e.e_role = r.r_id and e.e_deptid = d.d_id and e.e_modifyId = e1.e_id and e.e_sex = s.sex_id and e.e_status = st.st_id and e.e_RealName like concat('%',#{employee.e_RealName},'%') limit #{begin},#{end} select count(*) from employees e,dept d, role r,sex s,status st e.e_role = r.r_id and e.e_deptid = d.d_id and e.e_modifyId = e.e_id and e.e_sex = s.sex_id and e.e_status = st.st_id and e.e_RealName like concat('%',#{e_RealName},'%') update employees e_lastLoginTime = #{e_LastLoginTime}, e_Phone = #{e_Phone}, e_Pwd = #{e_Pwd}, e_Code = #{e_Code}, e_RealName = #{e_RealName}, e_Description = #{e_Description}, e_Sex = #{e_Sex.sex_Id}, e_Status = #{e_Status.st_Id}, e_DeptId = #{e_DeptId.d_Id}, delete from employees where e_id = #{e_Id} insert into employees values (default,#{e_Code},#{e_LoginName},#{e_Pwd},#{e_RealName},#{e_Sex.sex_Id},#{e_Phone},#{e_Role.r_Id},#{e_DeptId.d_Id},#{e_Superior.e_Id},#{e_Status.st_Id},#{e_CreateTime},#{e_ModifyId.e_Id},#{e_ModifyTime},#{e_LastLoginTime},#{e_Description}) select * from employees where 1=1 and e_Code = #{e_Code} select * from employees where 1=1 and e_LoginName = #{e_LoginName} 部门xml代码: select * from dept 角色xml代码: SELECT r.*,e.*,d.* FROM role r,employees e,dept d r.r_modifyId = e.e_id AND r.r_deptNo = d.d_id and r_Name like concat('%',#{role.r_Name},'%') limit #{begin},#{end} select count(*) from role r,employees e,dept d r.r_modifyId = e.e_id AND r.r_deptNo = d.d_id and r_Name like concat('%',#{r_Name},'%') SELECT r.*,e.*,d.* FROM role r,employees e,dept d r.r_modifyId = e.e_id AND r.r_deptNo = d.d_id and r_id = #{r_Id} select * from role update role r_deptNo = #{r_DeptNo.d_Id}, r_ModifyId = #{r_ModifyId.e_Id}, r_ModifyTime = #{r_ModifyTime}, r_Description = #{r_Description}, delete from role where r_id = #{r_Id} insert into role values(default,#{r_Code},#{r_Name},#{r_DeptNo.d_Id},#{r_ModifyId.e_Id},#{r_ModifyTime},#{r_Description}) select count(*) from role and r_Code = #{r_Code} and r_Name = #{r_Name} 员工Mapper层代码: package com.manager.mapper; import com.manager.pojo.Employees; import java.util.List;import java.util.Map; public interface EmployeesMapper { Employees getEmployees(Employees employees); int alterEmployees(Employees employees); List employeeList(Map map); int count(Employees employees); List lowerList(Employees employees); int deleteEmployees(Employees employees); int addEmployees(Employees employees); Employees existEmployeeCode(Employees employees); Employees existEmployeeLoginName(Employees employees);}部门Mapper层代码: package com.manager.mapper; import com.manager.pojo.Dept; import java.util.List; public interface DeptMapper { List deptAll();}角色Mapper层代码: package com.manager.mapper; import com.manager.pojo.Role; import java.util.List;import java.util.Map; public interface RoleMapper { List roleList(Map map); int count(Role role); Role getRole(Role role); List roleAll(); int modify(Role role); int delRole(Role role); int addRole(Role role); int validationRole(Role role);}员工Service层代码: package com.manager.service.users; import com.manager.pojo.Employees; import java.util.List; public interface EmployeesService { Employees getEmployees(Employees employees); int alterEmployees(Employees employees); List employeeList(Integer begin, Integer end, Employees employees); int count(Employees employees); List lowerList(Employees employees); int deleteEmployees(Employees employees); int addEmployees(Employees employees); String existEmployeeCode(Employees employees); String existEmployeeLoginName(Employees employees);}员工ServiceImpl代码: package com.manager.service.users; import com.alibaba.fastjson.JSON;import com.manager.mapper.EmployeesMapper;import com.manager.pojo.Employees;import org.apache.ibatis.session.SqlSession;import org.springframework.stereotype.Service;import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource;import java.util.HashMap;import java.util.List;import java.util.Map; @Servicepublic class EmployeesServiceImpl implements EmployeesService { @Resource private EmployeesMapper employeesMapper; @Override public Employees getEmployees(Employees employees) { Employees newEmployees = employeesMapper.getEmployees(employees); return newEmployees; } @Override public List lowerList(Employees employees) { return employeesMapper.lowerList(employees); } @Override public int deleteEmployees(Employees employees) { return employeesMapper.deleteEmployees(employees); } @Override public int addEmployees(Employees employees) { return employeesMapper.addEmployees(employees); } @Override public String existEmployeeCode(Employees employees) { return JSON.toJSONString(employeesMapper.existEmployeeCode(employees)); } @Override public String existEmployeeLoginName(Employees employees) { return JSON.toJSONString(employeesMapper.existEmployeeLoginName(employees)); } @Override @Transactional public int alterEmployees(Employees employees) { return employeesMapper.alterEmployees(employees); } @Override public List employeeList(Integer begin, Integer end, Employees employees) { Map map = new HashMap<>(); map.put("begin", begin); map.put("end", end); map.put("employee", employees); return employeesMapper.employeeList(map); } @Override public int count(Employees employees) { return employeesMapper.count(employees); }}部门Service层代码: package com.manager.service.dept; import com.manager.pojo.Dept; import java.util.List; public interface DeptService { List deptAll();}部门ServiceImpl代码: package com.manager.service.dept; import com.manager.mapper.DeptMapper;import com.manager.pojo.Dept;import org.springframework.stereotype.Service; import javax.annotation.Resource;import java.util.HashMap;import java.util.List;import java.util.Map; @Servicepublic class DeptServiceImpl implements DeptService { @Resource private DeptMapper deptMapper; @Override public List deptAll() { return deptMapper.deptAll(); } }角色Service层代码: package com.manager.service.role; import com.manager.pojo.Role; import java.util.List; public interface RoleService { List roleList(Role role,Integer begin,Integer end); int count(Role role); Role getRole(Role role); List roleAll(); int modify(Role role); int delRole(Role role); int addRole(Role role); int validationRole(Role role);}角色ServiceImpl代码: package com.manager.service.role; import com.manager.mapper.RoleMapper;import com.manager.pojo.Role;import org.springframework.stereotype.Service;import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource;import java.util.HashMap;import java.util.List;import java.util.Map; @Servicepublic class RoleServiceImpl implements RoleService { @Resource private RoleMapper roleMapper; @Override public List roleList(Role role,Integer begin,Integer end) { Map map = new HashMap(); map.put("role",role); map.put("begin",begin); map.put("end",end); return roleMapper.roleList(map); } @Override public int count(Role role) { return roleMapper.count(role); } @Override public Role getRole(Role role) { return roleMapper.getRole(role); } @Override public List roleAll() { return roleMapper.roleAll(); } @Override @Transactional public int modify(Role role) { return roleMapper.modify(role); } @Override @Transactional public int delRole(Role role) { return roleMapper.delRole(role); } @Override public int addRole(Role role) { return roleMapper.addRole(role); } @Override public int validationRole(Role role) { return roleMapper.validationRole(role); }}员工Controller控制层代码: package com.manager.control.employees; import com.alibaba.fastjson.JSON;import com.manager.pojo.Dept;import com.manager.pojo.Employees;import com.manager.pojo.Role;import com.manager.service.dept.DeptService;import com.manager.service.role.RoleService;import com.manager.service.users.EmployeesService;import com.manager.util.MD5Util;import com.manager.util.PageUtil;import com.manager.util.PwdUtil;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.*;import org.springframework.web.servlet.ModelAndView; import javax.annotation.Resource;import javax.servlet.http.HttpSession;import java.util.Date;import java.util.HashMap;import java.util.List;import java.util.Map; @Controllerpublic class EmployeesContorller { @Resource private EmployeesService employeesService; @Resource private DeptService deptService; @Resource private RoleService roleService; @RequestMapping(value = "/login", method = RequestMethod.POST) @ResponseBody public Object loginajax(HttpSession session, Employees employees) { Map map = new HashMap<>(); Employees employee = employeesService.getEmployees(employees); if (employee != null) { String pwd = MD5Util.EncoderByMd5(employees.getE_Pwd()); if (pwd.equals(employee.getE_Pwd())) { session.setAttribute("loginEmployee", employee);//登陆成功保存会话 employee.setE_LastLoginTime(new Date()); employeesService.alterEmployees(employee); } else { map.put("msg", "false"); } } else { map.put("msg", "null"); } return map; } @RequestMapping("/login.html") public String login() { return "login"; } @RequestMapping("/userOut") public String userOut(HttpSession session) { session.invalidate(); return "login"; } @RequestMapping(value = "/modifyEmployees") @ResponseBody public Object modifyEmployees(Employees employees) { int i = employeesService.alterEmployees(employees); if (i == 1) { return "true"; } else { return "false"; } } @RequestMapping("/JumpEmpAdd") public String jumpEmpAdd(Model model,Employees employees) { List depts = deptService.deptAll(); List roles = roleService.roleAll(); List employee = employeesService.employeeList(1,99,employees); model.addAttribute("depts",depts); model.addAttribute("roles",roles); model.addAttribute("employees",employee); return "sysemployeeAdd"; } @RequestMapping("/AddEmployees") @ResponseBody public Object addEmployees(Employees employees,HttpSession session) { employees.setE_CreateTime(new Date()); employees.setE_LastLoginTime(new Date()); employees.setE_ModifyTime(new Date()); employees.setE_ModifyId((Employees) session.getAttribute("loginEmployee")); int i = employeesService.addEmployees(employees); if (i == 1) { return "true"; } else { return "false"; } } @RequestMapping("/DeleteEmployees") @ResponseBody public Object deleteEmployee(Employees employees) { int i = employeesService.deleteEmployees(employees); if (i == 1) { return "true"; } else { return "false"; } } @RequestMapping(value = "modifyPwd", method = RequestMethod.POST) @ResponseBody public Object modifyPwd(HttpSession session, PwdUtil pwd) { Map map = new HashMap<>(); int result = 0; Employees employees = employeesService.getEmployees(new Employees(pwd.getLoginName())); if (employees.getE_Pwd().equals(MD5Util.EncoderByMd5(pwd.getOldPwd()))) { if (pwd.getNewPwd().equals(pwd.getConfirmNewPwd())) { employees.setE_Pwd(MD5Util.EncoderByMd5(pwd.getConfirmNewPwd())); result = employeesService.alterEmployees(employees); if (result == 1) { session.invalidate(); map.put("msg", "true"); } else { map.put("msg", "false"); } } else { map.put("msg", "Don't match"); } } else { map.put("msg", "error"); } return map; } @RequestMapping("/getEmployee") public ModelAndView getEmployee(HttpSession session) { ModelAndView mv = new ModelAndView(); Employees employee = (Employees) session.getAttribute("loginEmployee"); Employees newEmployee = employeesService.getEmployees(employee); mv.addObject("newEmployee", newEmployee); mv.setViewName("syspersonalInfo"); return mv; } @RequestMapping(value = "/employeeList", method = RequestMethod.POST) @ResponseBody public Object employeeList(@RequestParam(name = "draw", required = false, defaultValue = "0") int draw, @RequestParam(name = "start", required = false, defaultValue = "0") int start, @RequestParam(name = "length", required = false, defaultValue = "0") int length, Employees employees) { PageUtil pageUtil = new PageUtil<>(); List employeesList = employeesService.employeeList(start, length, employees); int count = employeesService.count(employees); pageUtil.setData(employeesList); pageUtil.setDraw(draw); pageUtil.setRecordsTotal(count); pageUtil.setRecordsFiltered(count); return pageUtil; } @RequestMapping("/getEmployee/{id}/{str}") public ModelAndView getEmployee(@PathVariable Integer id, @PathVariable String str) { ModelAndView mv = new ModelAndView(); Employees employee = new Employees(id); Employees newEmployee = employeesService.getEmployees(employee); List depts = deptService.deptAll(); mv.addObject("newEmployee", newEmployee); mv.addObject("depts", depts); if (str.equals("get")) { mv.setViewName("sysemployeeInfo"); } else { mv.setViewName("sysemployeemodify"); } return mv; } @RequestMapping("/ExistCode") @ResponseBody public Object existCode(Employees employees){ return JSON.toJSONString(employeesService.existEmployeeCode(employees)); } @RequestMapping("/ExistLoginName") @ResponseBody public Object existLoginName(Employees employees){ return JSON.toJSONString(employeesService.existEmployeeLoginName(employees)); }}部门Controller控制层代码: package com.manager.control.dept; import com.manager.pojo.Dept;import com.manager.service.dept.DeptService;import com.manager.util.PageUtil;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.*;import org.springframework.web.servlet.ModelAndView; import javax.annotation.Resource;import java.util.List; @Controllerpublic class DeptContorller { @Resource private DeptService deptService; @RequestMapping(value = "/deptAll",method = RequestMethod.POST) @ResponseBody public Object deptAll(){ List depts = deptService.deptAll(); return depts; }}角色Controller控制层代码: package com.manager.control.role; import com.manager.pojo.Dept;import com.manager.pojo.Employees;import com.manager.pojo.Role;import com.manager.service.dept.DeptService;import com.manager.service.role.RoleService;import com.manager.util.PageUtil;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.*;import org.springframework.web.servlet.ModelAndView; import javax.annotation.Resource;import javax.servlet.http.HttpSession;import java.util.Date;import java.util.List; @Controllerpublic class RoleController { @Resource private RoleService roleService; @Resource private DeptService deptService; @RequestMapping(value = "/roleList") @ResponseBody public Object roleList(@RequestParam(name = "draw",required = false,defaultValue = "0")int draw, @RequestParam(name = "start",required = false,defaultValue = "0")int start, @RequestParam(name = "length",required = false,defaultValue = "0")int length, Role role){ PageUtil pageUtil = new PageUtil(); int count = roleService.count(role); List roles = roleService.roleList(role,start,length); pageUtil.setData(roles); pageUtil.setDraw(draw); pageUtil.setRecordsFiltered(count); pageUtil.setRecordsTotal(count); return pageUtil; } @RequestMapping("/getRole/{id}/{str}") public ModelAndView getRole(@PathVariable("id")Integer id, @PathVariable("str")String str){ ModelAndView mv = new ModelAndView(); mv.setViewName("sysroleInfo"); List depts = null; Role role = new Role(id); Role newRole = roleService.getRole(role); if(str.equals("modify")){ depts = deptService.deptAll(); mv.setViewName("sysrolemodify"); } mv.addObject("newRole",newRole); mv.addObject("depts",depts); return mv; } @RequestMapping(value = "/modifyRole",method = RequestMethod.POST) @ResponseBody public Object modifyRole(HttpSession session,Role role){ role.setR_ModifyTime(new Date()); Employees employees = (Employees) session.getAttribute("loginEmployee"); role.setR_ModifyId(employees); int modify = roleService.modify(role); if(modify==1){ return "true"; } return "false"; } @RequestMapping(value = "/delRole",method = RequestMethod.POST) @ResponseBody public Object delRole(Role role){ int i = roleService.delRole(role); if(i==1){ return "true"; } return "false"; } @RequestMapping(value = "/addRole",method = RequestMethod.POST) @ResponseBody public Object addRole(HttpSession session,Role role){ role.setR_ModifyTime(new Date()); role.setR_ModifyId((Employees) session.getAttribute("loginEmployee")); int i = roleService.addRole(role); if(i==1){ return "true"; } return "false"; } @RequestMapping(value = "/validationRole",method = RequestMethod.POST) @ResponseBody public Object validationRole(Role role){ int i = roleService.validationRole(role); if(i==1){ return "true"; } return "false"; }}员工前端页面代码: 欢迎页面-X-admin2.0 员工添加页面代码: 欢迎页面-X-admin2.0 员工修改页面代码: 欢迎页面-X-admin2.0 员工详情页面代码: 欢迎页面-X-admin2.0 员工信息 员工编码 员工姓名 性别 状态 所属部门 角色身份 备注信息
员工sysemployees.js代码: $(document).ready(function () { x();}); function x() { $('#employees').dataTable({ "searching": false, "serverSide": true,//是否启用服务器处理数据源 "language": { "lengthMenu": "每页 _MENU_ 条记录", "zeroRecords": "没有找到记录", "info": "第 _PAGE_ 页 ( 总共 _PAGES_ 页 )", "infoEmpty": "无记录", "infoFiltered": "(从 _MAX_ 条记录过滤)", "paginate": { "previous": "上一页", "next": "下一页", "processing": "正在处理中...." } }, "columnDefs": [ {"title": "员工姓名", "targets": 0}, {"title": "性别", "targets": 1}, {"title": "所在部门", "targets": 2}, {"title": "角色", "targets": 3}, {"title": "状态", "targets": 4}, {"title": "最后修改时间", "targets": 5}, {"title": "操作人", "targets": 6}, {"title": "操作", "targets": 7} ], "ajax": { "url": "/employeeList", "type": "POST", "data":function (d) { d.e_RealName = $("#e_RealName").val(); }, "dataType": "json" }, "columns": [ {"data": "e_RealName"}, {"data": "e_Sex.sex_Name"}, {"data": "e_DeptId.d_Name"}, {"data": "e_Role.r_Name"}, {"data": "e_Status.st_Name"}, {"data": "e_ModifyTime",defaultContent: ""}, {"data": "e_ModifyId.e_RealName",defaultContent: ""}, { "data": "e_Id","width":"200px", "render": function (data, type, full, meta) { return ""; } } ] }); $(".btn-success").on("click", function () { $("#employees").DataTable().ajax.reload(); }); $("#employeesQuery").on("click", function () { $("#employees").DataTable().ajax.reload(); });} function delEmployees(id,name) { layer.confirm("确认删除员工:"+name, {icon: 3, title:'提示'},function () { $.ajax({ type:"POST", url:"/DeleteEmployees", data:{e_Id:id}, dataType:"JSON", success:function (data) { if(data == true){ layer.msg("删除成功!"); parent.$("#employees").DataTable().ajax.reload(); return true; }else { layer.msg("删除失败!"); return false; } } }); });}员工sysemployeesadd.js代码: function back() { parent.layer.closeAll();} function addEmployee() { $.ajax({ type: "POST", url: "/AddEmployees", data: $("#form1").serialize(), dataType: "JSON", success: function (data) { if (data = "true") { layer.msg("添加成功!"); parent.$("#employees").DataTable().ajax.reload(); } else { layer.msg("添加失败!"); } } });} $(function () { var e_Code = $("#e_Code"); var e_LoginName = $("#e_LoginName"); e_Code.bind("blur", function () { $.ajax({ type: "POST",//请求类型 url: "/ExistCode",//请求的url data: {e_Code: e_Code.val()},//请求参数 dataType: "json",//ajax接口(请求url)返回的数据类型 success: function (data) {//data:返回数据(json对象) if (data == "null") {//账号可用,正确提示 layer.msg("编号可用!"); } else if (data == "") {//账号不可为空,错的提示 layer.msg("编号不能为空!"); } else {//账号已存在,错的提示 layer.msg("编号已存在!"); } } }); }); e_LoginName.bind("blur", function () { $.ajax({ type: "POST",//请求类型 url: "/ExistLoginName",//请求的url data: {e_LoginName: e_LoginName.val()},//请求参数 dataType: "json",//ajax接口(请求url)返回的数据类型 success: function (data) {//data:返回数据(json对象) if (data == "null") {//账号可用,正确提示 layer.msg("账号可用!"); } else if (data == "") {//账号不可为空,错的提示 layer.msg("账号不能为空!"); } else {//账号已存在,错的提示 layer.msg("账号已存在!"); } } }); });}) 员工sysemployeesmodify.js代码: function back() { parent.layer.closeAll();} function updEmployees() { $.ajax({ type:"POST", url:"/modifyEmployees", data:$("#form1").serialize(), dataType:"JSON", success:function (data) { if(data="true"){ layer.msg("修改成功!"); parent.$("#employees").DataTable().ajax.reload(); }else{ layer.msg("修改失败!"); } } }); --------------------- 作者:Zartillery 来源:CSDN 原文:https://blog.csdn.net/weixin_41595700/article/details/85079112 版权声明:本文为博主原创文章,转载请附上博文链接!