1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0</modelVersion> 5 6 <groupId>com</groupId> 7 <artifactId>manager</artifactId> 8 <version>0.0.1-SNAPSHOT</version> 9 <packaging>jar</packaging> 10 11 <name>manager</name> 12 <description>Demo project for Spring Boot</description> 13 14 <parent> 15 <groupId>org.springframework.boot</groupId> 16 <artifactId>spring-boot-starter-parent</artifactId> 17 <version>2.0.4.RELEASE</version> 18 <relativePath/> <!-- lookup parent from repository --> 19 </parent> 20 21 <properties> 22 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 23 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 24 <java.version>1.8</java.version> 25 </properties> 26 27 <dependencies> 28 <dependency> 29 <groupId>org.springframework.boot</groupId> 30 <artifactId>spring-boot-starter-jdbc</artifactId> 31 </dependency> 32 <dependency> 33 <groupId>org.springframework.boot</groupId> 34 <artifactId>spring-boot-starter-thymeleaf</artifactId> 35 </dependency> 36 <dependency> 37 <groupId>org.springframework.boot</groupId> 38 <artifactId>spring-boot-starter-web</artifactId> 39 </dependency> 40 41 <dependency> 42 <groupId>org.mybatis.spring.boot</groupId> 43 <artifactId>mybatis-spring-boot-starter</artifactId> 44 <version>1.3.2</version> 45 </dependency> 46 <dependency> 47 <groupId>mysql</groupId> 48 <artifactId>mysql-connector-java</artifactId> 49 <scope>runtime</scope> 50 </dependency> 51 <dependency> 52 <groupId>org.springframework.boot</groupId> 53 <artifactId>spring-boot-starter-test</artifactId> 54 <scope>test</scope> 55 </dependency> 56 <!-- 数据源 --> 57 <dependency> 58 <groupId>com.alibaba</groupId> 59 <artifactId>druid</artifactId> 60 <version>1.1.9</version> 61 </dependency> 62 <!-- https://mvnrepository.com/artifact/com.alipay.sdk/alipay-sdk-java --> 63 <dependency> 64 <groupId>com.alipay.sdk</groupId> 65 <artifactId>alipay-sdk-java</artifactId> 66 <version>3.0.0</version> 67 </dependency> 68 <!-- https://mvnrepository.com/artifact/commons-logging/commons-logging --> 69 <dependency> 70 <groupId>commons-logging</groupId> 71 <artifactId>commons-logging</artifactId> 72 <version>1.1.1</version> 73 </dependency> 74 <!--json转换工具包--> 75 <dependency> 76 <groupId>com.alibaba</groupId> 77 <artifactId>fastjson</artifactId> 78 <version>1.2.47</version> 79 </dependency> 80 81 <dependency> 82 <groupId>javax.servlet</groupId> 83 <artifactId>jstl</artifactId> 84 <version>1.2</version> 85 </dependency> 86 </dependencies> 87 88 <build> 89 <plugins> 90 <plugin> 91 <groupId>org.springframework.boot</groupId> 92 <artifactId>spring-boot-maven-plugin</artifactId> 93 </plugin> 94 </plugins> 95 </build> 96 97 98 </project> 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 <?xml version="1.0" encoding="UTF-8"?> 407 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 408 "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 409 <mapper namespace="com.manager.mapper.EmployeesMapper"> 410 <resultMap id="EmployeesMap" type="Employees"> 411 <id column="e_id" property="e_Id"/> 412 <association property="e_ModifyId" javaType="Employees"> 413 <id column="e1_id" property="e_Id"/> 414 <result column="e1_realName" property="e_RealName"/> 415 </association> 416 <association property="e_Role" javaType="Role"> 417 <id column="r_id" property="r_Id"/> 418 </association> 419 <association property="e_DeptId" javaType="Dept"> 420 <id column="d_id" property="d_Id"/> 421 </association> 422 <association property="e_Superior" javaType="Employees"> 423 <id column="e1_id" property="e_Id"/> 424 <result column="e1_realName" property="e_RealName"/> 425 </association> 426 <association property="e_Sex" javaType="Sex"> 427 <id column="sex_id" property="sex_Id"/> 428 </association> 429 <association property="e_Status" javaType="Status"> 430 <id column="st_id" property="st_Id"/> 431 </association> 432 </resultMap> 433 434 <select id="lowerList" resultMap="EmployeesMap"> 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 <trim prefix="where" prefixOverrides="and"> 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 <if test="e_Id != null"> 441 and e.e_Superior = #{e_Id} 442 </if> 443 </trim> 444 </select> 445 446 <select id="getEmployees" resultMap="EmployeesMap"> 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 <trim prefix="where" prefixOverrides="and"> 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 <if test="e_LoginName != null and e_LoginName != ''"> 453 and e.e_loginName = #{e_LoginName} 454 </if> 455 <if test="e_Id != null"> 456 and e.e_id = #{e_Id} 457 </if> 458 </trim> 459 </select> 460 461 <select id="employeeList" resultMap="EmployeesMap"> 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 <trim prefix="where" prefixOverrides="and"> 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 <if test="employee.e_RealName != null and employee.e_RealName != ''"> 468 and e.e_RealName like concat('%',#{employee.e_RealName},'%') 469 </if> 470 limit #{begin},#{end} 471 </trim> 472 </select> 473 474 <select id="count" resultType="int"> 475 select count(*) from employees e,dept d, role r,sex s,status st 476 <trim prefix="where" prefixOverrides="and"> 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 <if test="e_RealName != null and e_RealName != ''"> 480 and e.e_RealName like concat('%',#{e_RealName},'%') 481 </if> 482 </trim> 483 </select> 484 <update id="alterEmployees"> 485 update employees 486 <trim prefix="set" suffixOverrides="," suffix="where e_Id = #{e_Id}"> 487 <if test="e_LastLoginTime != null"> 488 e_lastLoginTime = #{e_LastLoginTime}, 489 </if> 490 <if test="e_Phone != null"> 491 e_Phone = #{e_Phone}, 492 </if> 493 <if test="e_Pwd != null"> 494 e_Pwd = #{e_Pwd}, 495 </if> 496 <if test="e_Code != null"> 497 e_Code = #{e_Code}, 498 </if> 499 <if test="e_RealName != null"> 500 e_RealName = #{e_RealName}, 501 </if> 502 <if test="e_Description != null"> 503 e_Description = #{e_Description}, 504 </if> 505 <if test="e_Sex != null"> 506 e_Sex = #{e_Sex.sex_Id}, 507 </if> 508 <if test="e_Status != null"> 509 e_Status = #{e_Status.st_Id}, 510 </if> 511 <if test="e_DeptId != null"> 512 e_DeptId = #{e_DeptId.d_Id}, 513 </if> 514 </trim> 515 </update> 516 517 <delete id="deleteEmployees"> 518 delete from employees where e_id = #{e_Id} 519 </delete> 520 521 <insert id="addEmployees"> 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 </insert> 524 <select id="existEmployeeCode" resultType="Employees"> 525 select * from employees where 1=1 526 <if test="e_Code!=null"> 527 and e_Code = #{e_Code} 528 </if> 529 </select> 530 531 <select id="existEmployeeLoginName" resultType="Employees"> 532 select * from employees where 1=1 533 <if test="e_LoginName!=null"> 534 and e_LoginName = #{e_LoginName} 535 </if> 536 </select> 537 </mapper> 538 部门xml代码: 539 540 <?xml version="1.0" encoding="UTF-8"?> 541 <!DOCTYPE mapper 542 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 543 "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 544 <mapper namespace="com.manager.mapper.DeptMapper"> 545 546 <select id="deptAll" resultType="Dept"> 547 select * from dept 548 </select> 549 550 </mapper> 551 角色xml代码: 552 553 <?xml version="1.0" encoding="UTF-8"?> 554 <!DOCTYPE mapper 555 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 556 "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 557 <mapper namespace="com.manager.mapper.RoleMapper"> 558 <resultMap id="roleMap" type="Role"> 559 <id column="r_id" property="r_Id"/> 560 <association property="r_DeptNo" javaType="Dept"> 561 <id column="d_id" property="d_Id"/> 562 </association> 563 <association property="r_ModifyId" javaType="Employees"> 564 <id column="e_id" property="e_Id"/> 565 </association> 566 </resultMap> 567 568 <select id="roleList" resultMap="roleMap"> 569 SELECT r.*,e.*,d.* FROM role r,employees e,dept d 570 <trim prefix="where" prefixOverrides="and"> 571 r.r_modifyId = e.e_id AND r.r_deptNo = d.d_id 572 <if test="role.r_Name != null and role.r_Name != ''"> 573 and r_Name like concat('%',#{role.r_Name},'%') 574 </if> 575 limit #{begin},#{end} 576 </trim> 577 </select> 578 579 <select id="count" resultType="int"> 580 select count(*) from role r,employees e,dept d 581 <trim prefix="where" prefixOverrides="and"> 582 r.r_modifyId = e.e_id AND r.r_deptNo = d.d_id 583 <if test="r_Name != null and r_Name != ''"> 584 and r_Name like concat('%',#{r_Name},'%') 585 </if> 586 </trim> 587 </select> 588 589 <select id="getRole" resultMap="roleMap"> 590 SELECT r.*,e.*,d.* FROM role r,employees e,dept d 591 <trim prefix="where" prefixOverrides="and"> 592 r.r_modifyId = e.e_id AND r.r_deptNo = d.d_id 593 <if test="r_Id != null and r_Id != ''"> 594 and r_id = #{r_Id} 595 </if> 596 </trim> 597 </select> 598 599 <select id="roleAll" resultType="Role"> 600 select * from role 601 </select> 602 603 <update id="modify"> 604 update role 605 <trim prefix="set" suffixOverrides="," suffix="where r_code = #{r_Code}"> 606 <if test="r_DeptNo.d_Id != null and r_DeptNo.d_Id != 0"> 607 r_deptNo = #{r_DeptNo.d_Id}, 608 </if> 609 <if test="r_ModifyId != null"> 610 r_ModifyId = #{r_ModifyId.e_Id}, 611 </if> 612 <if test="r_ModifyTime != null"> 613 r_ModifyTime = #{r_ModifyTime}, 614 </if> 615 <if test="r_Description != null"> 616 r_Description = #{r_Description}, 617 </if> 618 </trim> 619 </update> 620 621 <delete id="delRole"> 622 delete from role where r_id = #{r_Id} 623 </delete> 624 625 <insert id="addRole"> 626 insert into role values(default,#{r_Code},#{r_Name},#{r_DeptNo.d_Id},#{r_ModifyId.e_Id},#{r_ModifyTime},#{r_Description}) 627 </insert> 628 629 <select id="validationRole" resultType="int"> 630 select count(*) from role 631 <trim prefix="where" prefixOverrides="and"> 632 <if test="r_Code != null and r_Code != ''"> 633 and r_Code = #{r_Code} 634 </if> 635 <if test="r_Name != null and r_Name != ''"> 636 and r_Name = #{r_Name} 637 </if> 638 </trim> 639 </select> 640 </mapper> 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<Employees> employeeList(Map map); 656 657 int count(Employees employees); 658 659 List<Employees> 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<Dept> 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<Role> roleList(Map map); 691 692 int count(Role role); 693 694 Role getRole(Role role); 695 696 List<Role> 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<Employees> employeeList(Integer begin, Integer end, Employees employees); 720 721 int count(Employees employees); 722 723 List<Employees> 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<Employees> 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<Employees> employeeList(Integer begin, Integer end, Employees employees) { 793 Map<String, Object> 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<Dept> 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<Dept> 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<Role> roleList(Role role,Integer begin,Integer end); 850 851 int count(Role role); 852 853 Role getRole(Role role); 854 855 List<Role> 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<Role> roleList(Role role,Integer begin,Integer end) { 886 Map<String,Object> map = new HashMap<String,Object>(); 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<Role> 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<String, String> 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<Dept> depts = deptService.deptAll(); 1010 List<Role> roles = roleService.roleAll(); 1011 List<Employees> 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<String, String> 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<Employees> pageUtil = new PageUtil<>(); 1086 List<Employees> 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<Dept> 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<Dept> 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<Role> pageUtil = new PageUtil<Role>(); 1182 int count = roleService.count(role); 1183 List<Role> 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<Dept> 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 <!DOCTYPE html> 1256 <html> 1257 1258 <head> 1259 <meta charset="UTF-8"> 1260 <title>欢迎页面-X-admin2.0</title> 1261 <meta name="renderer" content="webkit"> 1262 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 1263 <meta name="viewport" 1264 content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/> 1265 <!--<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>--> 1266 <link rel="stylesheet" href="/static/css/font.css"> 1267 <link rel="stylesheet" href="/static/css/xadmin.css"> 1268 <script type="text/javascript" src="/static/lib/jquery/dist/jquery.min.js"></script> 1269 <script type="text/javascript" src="/static/lib/layui/layui.js" charset="utf-8"></script> 1270 <script type="text/javascript" src="/static/js/xadmin.js"></script> 1271 <!-- 让IE8/9支持媒体查询,从而兼容栅格 --> 1272 <!--[if lt IE 9]> 1273 <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script> 1274 <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script> 1275 <![endif]--> 1276 </head> 1277 1278 <body class="layui-anim layui-anim-up"> 1279 <div class="x-nav"> 1280 <span class="layui-breadcrumb"> 1281 <a> 1282 <cite>系统管理>></cite> 1283 <cite>员工管理</cite></a> 1284 </span> 1285 <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" 1286 href="javascript:location.replace(location.href);" title="刷新"> 1287 <i class="layui-icon" style="line-height:30px">ဂ</i></a> 1288 </div> 1289 <div class="x-body"> 1290 <div class="layui-row"> 1291 <div class="layui-form layui-col-md12 x-so layui-col-md-offset1"> 1292 员工姓名:<input type="text" id="e_RealName" placeholder="请输入员工姓名" autocomplete="off" class="layui-input"> 1293 <button class="layui-btn" id="employeesQuery"><i class="layui-icon"></i></button> 1294 <button class="layui-btn" type="button" onclick="x_admin_show(null,'/JumpEmpAdd',600,525,true)"><i 1295 class="layui-icon"></i> 1296 </button> 1297 </div> 1298 </div> 1299 1300 <div class="col-md-12 col-sm-12 col-xs-12"> 1301 <div class="x_panel"> 1302 <div class="x_content"> 1303 <table id="employees" class="table table-striped table-bordered"> 1304 </table> 1305 </div> 1306 </div> 1307 </div> 1308 </div> 1309 </body> 1310 1311 </html> 1312 <!-- Bootstrap --> 1313 <link href="/static/vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"> 1314 <!-- Datatables --> 1315 <script src="/static/vendors/datatables.net/js/jquery.dataTables.min.js"></script> 1316 <script src="/static/vendors/datatables.net-bs/js/dataTables.bootstrap.min.js"></script> 1317 <!-- Custom Theme Style --> 1318 <link href="/static/build/css/custom.min.css" rel="stylesheet"> 1319 <script src="/static/js/sysemployees.js"></script> 1320 员工添加页面代码: 1321 1322 <!DOCTYPE html> 1323 <html xmlns:th="http://www.thymeleaf.org"> 1324 <head> 1325 <meta charset="UTF-8"> 1326 <title>欢迎页面-X-admin2.0</title> 1327 <meta name="renderer" content="webkit"> 1328 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 1329 <!--<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>--> 1330 <link rel="stylesheet" href="/static/css/font.css"> 1331 <link rel="stylesheet" href="/static/css/xadmin.css"> 1332 <script type="text/javascript" src="/static/lib/jquery/dist/jquery.min.js"></script> 1333 1334 <script src="/static/lib/layui/layui.js" charset="utf-8"></script> 1335 <script type="text/javascript" src="/static/js/xadmin.js"></script> 1336 </head> 1337 <body> 1338 <div class="x-body layui-anim layui-anim-up"> 1339 <fieldset class="layui-elem-field"> 1340 <legend>员工信息添加</legend> 1341 <div class="layui-field-box"> 1342 <form class="layui-form" onsubmit="return addEmployee()" id="form1"> 1343 <table class="layui-table"> 1344 <tr style="border: 0px"> 1345 <td>员工编码</td> 1346 <td> 1347 <input class="layui-input" id="e_Code" name="e_Code" type="text" onblur="" 1348 onkeyup="value=value.replace(/[^a-zA-0-9\_]/g,'')" /> 1349 </td> 1350 </tr> 1351 <tr> 1352 <td>员工账号</td> 1353 <td> 1354 <input class="layui-input" id="e_LoginName" name="e_LoginName" type="text" onblur="" 1355 onkeyup="value=value.replace(/[^a-zA-0-9\_]/g,'')"/> 1356 </td> 1357 </tr> 1358 <tr> 1359 <td>员工密码</td> 1360 <td> 1361 <input class="layui-input" id="e_Pwd" name="e_Pwd" type="password" 1362 onkeyup="value=value.replace(/[^a-zA-0-9\_]/g,'')"/> 1363 </td> 1364 </tr> 1365 <tr> 1366 <td>员工姓名</td> 1367 <td> 1368 <input class="layui-input" id="e_RealName" name="e_RealName" type="text" 1369 onkeyup="value=value.replace(/[^a-zA-Zu4E00-u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^a-zA-Zu4E00-u9FA5]/g,''))" 1370 /> 1371 </td> 1372 </tr> 1373 <tr> 1374 <td>员工电话</td> 1375 <td> 1376 <input class="layui-input" id="e_Phone" name="e_Phone" type="text" 1377 onkeyup="value=value.replace(/[^d]/g,'')" 1378 onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))" 1379 onblur="ePhone()"/> 1380 </td> 1381 </tr> 1382 <tr> 1383 <td>性别</td> 1384 <td> 1385 <input type="radio" name="e_Sex.sex_Id" value="1" id="male"/> 1386 <label for="male">男</label> 1387 <input type="radio" name="e_Sex.sex_Id" value="2" id="female"/> 1388 <label for="female">女</label> 1389 </td> 1390 </tr> 1391 <tr> 1392 <td>状态</td> 1393 <td> 1394 <input type="radio" name="e_Status.st_Id" value="1" id="normal"/> 1395 <label for="normal">正常</label> 1396 <input type="radio" name="e_Status.st_Id" value="2" id="disable"/> 1397 <label for="disable">禁用</label> 1398 </td> 1399 </tr> 1400 <tr> 1401 <td>所属部门</td> 1402 <td> 1403 <select name="e_DeptId.d_Id" class="layui-select"> 1404 <option value="0">--请选择--</option> 1405 <option th:each="dept:${depts}" th:value="${dept.d_Id}" 1406 th:text="${dept.d_Name}"></option> 1407 </select> 1408 </td> 1409 </tr> 1410 <tr> 1411 <td>所属上级</td> 1412 <td> 1413 <select name="e_Superior.e_Id" class="layui-select"> 1414 <option value="0">--请选择--</option> 1415 <option th:each="employee:${employees}" th:value="${employee.e_Id}" 1416 th:text="${employee.e_RealName}"></option> 1417 </select> 1418 </td> 1419 </tr> 1420 <tr> 1421 <td>角色身份</td> 1422 <td> 1423 <select name="e_Role.r_Id" class="layui-select"> 1424 <option value="0">--请选择--</option> 1425 <option th:each="role:${roles}" th:value="${role.r_Id}" 1426 th:text="${role.r_Name}"></option> 1427 </select> 1428 </td> 1429 </tr> 1430 <tr> 1431 <td>备注信息</td> 1432 <td> 1433 <textarea name="e_Description" id="e_Description" class="layui-textarea"></textarea> 1434 </td> 1435 </tr> 1436 <tr> 1437 <td colspan="2" style="text-align: center"> 1438 <input type="submit" value="提交" class="layui-btn layui-bg-blue"/> 1439 <input type="button" value="返回" class="layui-btn layui-bg-blue" onclick="back()"/> 1440 </td> 1441 </tr> 1442 </table> 1443 </form> 1444 </div> 1445 </fieldset> 1446 </div> 1447 <!-- jQuery --> 1448 <script src="/static/lib/jquery/dist/jquery.min.js"></script> 1449 <script src="/static/js/sysemployeesadd.js"></script> 1450 <script th:inline="javascript"> 1451 1452 var _hmt = _hmt || []; 1453 (function () { 1454 var hm = document.createElement("script"); 1455 hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190"; 1456 var s = document.getElementsByTagName("script")[0]; 1457 s.parentNode.insertBefore(hm, s); 1458 })(); 1459 1460 </script> 1461 </body> 1462 </html> 1463 员工修改页面代码: 1464 1465 <!DOCTYPE html> 1466 <html xmlns:th="http://www.thymeleaf.org"> 1467 <head> 1468 <meta charset="UTF-8"> 1469 <title>欢迎页面-X-admin2.0</title> 1470 <meta name="renderer" content="webkit"> 1471 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 1472 <!--<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>--> 1473 <link rel="stylesheet" href="/static/css/font.css"> 1474 <link rel="stylesheet" href="/static/css/xadmin.css"> 1475 <script type="text/javascript" src="/static/lib/jquery/dist/jquery.min.js"></script> 1476 1477 <script src="/static/lib/layui/layui.js" charset="utf-8"></script> 1478 <script type="text/javascript" src="/static/js/xadmin.js"></script> 1479 </head> 1480 <body> 1481 <div class="x-body layui-anim layui-anim-up"> 1482 <fieldset class="layui-elem-field"> 1483 <legend>员工信息修改</legend> 1484 <div class="layui-field-box"> 1485 <form class="layui-form" onsubmit="return updEmployees()" id="form1"> 1486 <input type="hidden" name="e_Id" th:value="${newEmployee.e_Id}"> 1487 <table class="layui-table"> 1488 <tr style="border: 0px"> 1489 <td>员工编码</td> 1490 <td> 1491 <input class="layui-input" name="e_Code" type="text" th:value="${newEmployee.e_Code}"/> 1492 </td> 1493 </tr> 1494 <tr> 1495 <td>员工姓名</td> 1496 <td> 1497 <input class="layui-input" name="e_RealName" type="text" th:value="${newEmployee.e_RealName}"/> 1498 </td> 1499 </tr> 1500 <tr> 1501 <td>性别</td> 1502 <td> 1503 <input type="radio" name="e_Sex.sex_Id" value="1" id="male" 1504 th:checked="${newEmployee.e_Sex.sex_Id eq 1}"/> 1505 <label for="male">男</label> 1506 <input type="radio" name="e_Sex.sex_Id" value="2" id="female" 1507 th:checked="${newEmployee.e_Sex.sex_Id eq 2}"/> 1508 <label for="female">女</label> 1509 </td> 1510 </tr> 1511 <tr> 1512 <td>状态</td> 1513 <td> 1514 <input type="radio" name="e_Status.st_Id" value="1" id="normal" 1515 th:checked="${newEmployee.e_Status.st_Id eq 1}"/> 1516 <label for="normal">正常</label> 1517 <input type="radio" name="e_Status.st_Id" value="2" id="disable" 1518 th:checked="${newEmployee.e_Status.st_Id eq 2}"/> 1519 <label for="disable">禁用</label> 1520 </td> 1521 </tr> 1522 <tr> 1523 <td>所属部门</td> 1524 <td> 1525 <select name="e_DeptId.d_Id" class="layui-select"> 1526 <option value="0">--请选择--</option> 1527 <option th:selected="${newEmployee.e_DeptId.d_Id eq dept.d_Id}" th:each="dept:${depts}" 1528 th:value="${dept.d_Id}" th:text="${dept.d_Name}"></option> 1529 </select> 1530 </td> 1531 </tr> 1532 <tr> 1533 <td>角色身份</td> 1534 <td th:text="${newEmployee.e_Role.r_Name}"></td> 1535 </tr> 1536 <tr> 1537 <td>备注信息</td> 1538 <td> 1539 <textarea name="e_Description" class="layui-textarea" th:text="${newEmployee.e_Description}"></textarea> 1540 </td> 1541 </tr> 1542 <tr> 1543 <td colspan="2" style="text-align: center"> 1544 <input type="submit" value="提交" class="layui-btn layui-bg-blue"/> 1545 <input type="button" value="返回" class="layui-btn layui-bg-blue" onclick="back()"/> 1546 </td> 1547 </tr> 1548 </table> 1549 </form> 1550 </div> 1551 </fieldset> 1552 </div> 1553 <!-- jQuery --> 1554 <script src="/static/lib/jquery/dist/jquery.min.js"></script> 1555 <!-- Datatables --> 1556 <script src="/static/vendors/datatables.net/js/jquery.dataTables.min.js"></script> 1557 <script src="/static/vendors/datatables.net-bs/js/dataTables.bootstrap.min.js"></script> 1558 <script src="/static/js/sysemployeesmodify.js"></script> 1559 <script th:inline="javascript"> 1560 1561 var _hmt = _hmt || []; 1562 (function () { 1563 var hm = document.createElement("script"); 1564 hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190"; 1565 var s = document.getElementsByTagName("script")[0]; 1566 s.parentNode.insertBefore(hm, s); 1567 })(); 1568 1569 </script> 1570 </body> 1571 </html> 1572 员工详情页面代码: 1573 1574 <!DOCTYPE html> 1575 <html xmlns:th="http://www.thymeleaf.org"> 1576 <head> 1577 <meta charset="UTF-8"> 1578 <title>欢迎页面-X-admin2.0</title> 1579 <meta name="renderer" content="webkit"> 1580 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 1581 <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/> 1582 <link rel="stylesheet" href="/static/css/font.css"> 1583 <link rel="stylesheet" href="/static/css/xadmin.css"> 1584 <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> 1585 <script src="/static/lib/layui/layui.js" charset="utf-8"></script> 1586 <script type="text/javascript" src="/static/js/xadmin.js"></script> 1587 </head> 1588 <body> 1589 <div class="x-body layui-anim layui-anim-up"> 1590 <fieldset class="layui-elem-field"> 1591 <legend>员工信息</legend> 1592 <div class="layui-field-box"> 1593 <table class="layui-table" lay-skin="nob"> 1594 <tr style="border: 0px"> 1595 <td>员工编码</td> 1596 <td th:text="${newEmployee.e_Code}"></td> 1597 </tr> 1598 <tr> 1599 <td>员工姓名</td> 1600 <td th:text="${newEmployee.e_RealName}"></td> 1601 </tr> 1602 <tr> 1603 <td>性别</td> 1604 <td th:text="${newEmployee.e_Sex.sex_Name}"></td> 1605 </tr> 1606 <tr> 1607 <td>状态</td> 1608 <td th:text="${newEmployee.e_Status.st_Name}"></td> 1609 </tr> 1610 <tr> 1611 <td>所属部门</td> 1612 <td th:text="${newEmployee.e_DeptId.d_Name}"></td> 1613 </tr> 1614 <tr> 1615 <td>角色身份</td> 1616 <td th:text="${newEmployee.e_Role.r_Name}"></td> 1617 </tr> 1618 <tr> 1619 <td>备注信息</td> 1620 <td th:text="${newEmployee.e_Description}"></td> 1621 </tr> 1622 </table> 1623 </div> 1624 </fieldset> 1625 </div> 1626 <!-- jQuery --> 1627 <script src="/static/lib/jquery/dist/jquery.min.js"></script> 1628 <script th:inline="javascript"> 1629 1630 var _hmt = _hmt || []; 1631 (function () { 1632 var hm = document.createElement("script"); 1633 hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190"; 1634 var s = document.getElementsByTagName("script")[0]; 1635 s.parentNode.insertBefore(hm, s); 1636 })(); 1637 1638 </script> 1639 </body> 1640 </html> 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 "<div class="layui-btn-group"> " + 1692 " <a class="layui-btn layui-btn-sm" onclick="x_admin_show(null,'/getEmployee/"+data+"/get',600,400)"> " + 1693 " <i class="layui-icon"></i> " + 1694 " </a> " + 1695 " <a class="layui-btn layui-btn-sm" onclick="x_admin_show(null,'/getEmployee/"+data+"/modify',600,600,true)"> " + 1696 " <i class="layui-icon"></i> " + 1697 " </a> " + 1698 " <a class="layui-btn layui-btn-sm" onclick="x_admin_show(null,'/getRole/"+data+"/modify',600,450,true)"> " + 1699 " <i class="layui-icon"></i> " + 1700 " </a> " + 1701 " <a class="layui-btn layui-btn-sm" onclick="delEmployees("+data+",'"+full.e_RealName+"')"> " + 1702 " <i class="layui-icon"></i> " + 1703 " </a> " + 1704 "</div>"; 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
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com</groupId> <artifactId>manager</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>manager</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.2</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- 数据源 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.9</version> </dependency> <!-- https://mvnrepository.com/artifact/com.alipay.sdk/alipay-sdk-java --> <dependency> <groupId>com.alipay.sdk</groupId> <artifactId>alipay-sdk-java</artifactId> <version>3.0.0</version> </dependency> <!-- https://mvnrepository.com/artifact/commons-logging/commons-logging --> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.1</version> </dependency> <!--json转换工具包--> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.47</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>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代码:
<?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.manager.mapper.EmployeesMapper"> <resultMap id="EmployeesMap" type="Employees"> <id column="e_id" property="e_Id"/> <association property="e_ModifyId" javaType="Employees"> <id column="e1_id" property="e_Id"/> <result column="e1_realName" property="e_RealName"/> </association> <association property="e_Role" javaType="Role"> <id column="r_id" property="r_Id"/> </association> <association property="e_DeptId" javaType="Dept"> <id column="d_id" property="d_Id"/> </association> <association property="e_Superior" javaType="Employees"> <id column="e1_id" property="e_Id"/> <result column="e1_realName" property="e_RealName"/> </association> <association property="e_Sex" javaType="Sex"> <id column="sex_id" property="sex_Id"/> </association> <association property="e_Status" javaType="Status"> <id column="st_id" property="st_Id"/> </association> </resultMap> <select id="lowerList" resultMap="EmployeesMap"> 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 <trim prefix="where" prefixOverrides="and"> 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 <if test="e_Id != null"> and e.e_Superior = #{e_Id} </if> </trim> </select> <select id="getEmployees" resultMap="EmployeesMap"> 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 <trim prefix="where" prefixOverrides="and"> 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 <if test="e_LoginName != null and e_LoginName != ''"> and e.e_loginName = #{e_LoginName} </if> <if test="e_Id != null"> and e.e_id = #{e_Id} </if> </trim> </select> <select id="employeeList" resultMap="EmployeesMap"> 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 <trim prefix="where" prefixOverrides="and"> 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 <if test="employee.e_RealName != null and employee.e_RealName != ''"> and e.e_RealName like concat('%',#{employee.e_RealName},'%') </if> limit #{begin},#{end} </trim> </select> <select id="count" resultType="int"> select count(*) from employees e,dept d, role r,sex s,status st <trim prefix="where" prefixOverrides="and"> 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 <if test="e_RealName != null and e_RealName != ''"> and e.e_RealName like concat('%',#{e_RealName},'%') </if> </trim> </select> <update id="alterEmployees"> update employees <trim prefix="set" suffixOverrides="," suffix="where e_Id = #{e_Id}"> <if test="e_LastLoginTime != null"> e_lastLoginTime = #{e_LastLoginTime}, </if> <if test="e_Phone != null"> e_Phone = #{e_Phone}, </if> <if test="e_Pwd != null"> e_Pwd = #{e_Pwd}, </if> <if test="e_Code != null"> e_Code = #{e_Code}, </if> <if test="e_RealName != null"> e_RealName = #{e_RealName}, </if> <if test="e_Description != null"> e_Description = #{e_Description}, </if> <if test="e_Sex != null"> e_Sex = #{e_Sex.sex_Id}, </if> <if test="e_Status != null"> e_Status = #{e_Status.st_Id}, </if> <if test="e_DeptId != null"> e_DeptId = #{e_DeptId.d_Id}, </if> </trim> </update> <delete id="deleteEmployees"> delete from employees where e_id = #{e_Id} </delete> <insert id="addEmployees"> 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}) </insert> <select id="existEmployeeCode" resultType="Employees"> select * from employees where 1=1 <if test="e_Code!=null"> and e_Code = #{e_Code} </if> </select> <select id="existEmployeeLoginName" resultType="Employees"> select * from employees where 1=1 <if test="e_LoginName!=null"> and e_LoginName = #{e_LoginName} </if> </select></mapper>部门xml代码:
<?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.manager.mapper.DeptMapper"> <select id="deptAll" resultType="Dept"> select * from dept </select> </mapper>角色xml代码:
<?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.manager.mapper.RoleMapper"> <resultMap id="roleMap" type="Role"> <id column="r_id" property="r_Id"/> <association property="r_DeptNo" javaType="Dept"> <id column="d_id" property="d_Id"/> </association> <association property="r_ModifyId" javaType="Employees"> <id column="e_id" property="e_Id"/> </association> </resultMap> <select id="roleList" resultMap="roleMap"> SELECT r.*,e.*,d.* FROM role r,employees e,dept d <trim prefix="where" prefixOverrides="and"> r.r_modifyId = e.e_id AND r.r_deptNo = d.d_id <if test="role.r_Name != null and role.r_Name != ''"> and r_Name like concat('%',#{role.r_Name},'%') </if> limit #{begin},#{end} </trim> </select> <select id="count" resultType="int"> select count(*) from role r,employees e,dept d <trim prefix="where" prefixOverrides="and"> r.r_modifyId = e.e_id AND r.r_deptNo = d.d_id <if test="r_Name != null and r_Name != ''"> and r_Name like concat('%',#{r_Name},'%') </if> </trim> </select> <select id="getRole" resultMap="roleMap"> SELECT r.*,e.*,d.* FROM role r,employees e,dept d <trim prefix="where" prefixOverrides="and"> r.r_modifyId = e.e_id AND r.r_deptNo = d.d_id <if test="r_Id != null and r_Id != ''"> and r_id = #{r_Id} </if> </trim> </select> <select id="roleAll" resultType="Role"> select * from role </select> <update id="modify"> update role <trim prefix="set" suffixOverrides="," suffix="where r_code = #{r_Code}"> <if test="r_DeptNo.d_Id != null and r_DeptNo.d_Id != 0"> r_deptNo = #{r_DeptNo.d_Id}, </if> <if test="r_ModifyId != null"> r_ModifyId = #{r_ModifyId.e_Id}, </if> <if test="r_ModifyTime != null"> r_ModifyTime = #{r_ModifyTime}, </if> <if test="r_Description != null"> r_Description = #{r_Description}, </if> </trim> </update> <delete id="delRole"> delete from role where r_id = #{r_Id} </delete> <insert id="addRole"> insert into role values(default,#{r_Code},#{r_Name},#{r_DeptNo.d_Id},#{r_ModifyId.e_Id},#{r_ModifyTime},#{r_Description}) </insert> <select id="validationRole" resultType="int"> select count(*) from role <trim prefix="where" prefixOverrides="and"> <if test="r_Code != null and r_Code != ''"> and r_Code = #{r_Code} </if> <if test="r_Name != null and r_Name != ''"> and r_Name = #{r_Name} </if> </trim> </select></mapper>员工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<Employees> employeeList(Map map); int count(Employees employees); List<Employees> 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<Dept> deptAll();}角色Mapper层代码:
package com.manager.mapper; import com.manager.pojo.Role; import java.util.List;import java.util.Map; public interface RoleMapper { List<Role> roleList(Map map); int count(Role role); Role getRole(Role role); List<Role> 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<Employees> employeeList(Integer begin, Integer end, Employees employees); int count(Employees employees); List<Employees> 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<Employees> 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<Employees> employeeList(Integer begin, Integer end, Employees employees) { Map<String, Object> 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<Dept> 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<Dept> deptAll() { return deptMapper.deptAll(); } }角色Service层代码:
package com.manager.service.role; import com.manager.pojo.Role; import java.util.List; public interface RoleService { List<Role> roleList(Role role,Integer begin,Integer end); int count(Role role); Role getRole(Role role); List<Role> 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<Role> roleList(Role role,Integer begin,Integer end) { Map<String,Object> map = new HashMap<String,Object>(); 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<Role> 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<String, String> 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<Dept> depts = deptService.deptAll(); List<Role> roles = roleService.roleAll(); List<Employees> 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<String, String> 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<Employees> pageUtil = new PageUtil<>(); List<Employees> 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<Dept> 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<Dept> 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<Role> pageUtil = new PageUtil<Role>(); int count = roleService.count(role); List<Role> 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<Dept> 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"; }}员工前端页面代码:
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>欢迎页面-X-admin2.0</title> <meta name="renderer" content="webkit"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/> <!--<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>--> <link rel="stylesheet" href="/static/css/font.css"> <link rel="stylesheet" href="/static/css/xadmin.css"> <script type="text/javascript" src="/static/lib/jquery/dist/jquery.min.js"></script> <script type="text/javascript" src="/static/lib/layui/layui.js" charset="utf-8"></script> <script type="text/javascript" src="/static/js/xadmin.js"></script> <!-- 让IE8/9支持媒体查询,从而兼容栅格 --> <!--[if lt IE 9]> <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script> <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script> <![endif]--></head> <body class="layui-anim layui-anim-up"><div class="x-nav"> <span class="layui-breadcrumb"> <a> <cite>系统管理>></cite> <cite>员工管理</cite></a> </span> <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新"> <i class="layui-icon" style="line-height:30px">ဂ</i></a></div><div class="x-body"> <div class="layui-row"> <div class="layui-form layui-col-md12 x-so layui-col-md-offset1"> 员工姓名:<input type="text" id="e_RealName" placeholder="请输入员工姓名" autocomplete="off" class="layui-input"> <button class="layui-btn" id="employeesQuery"><i class="layui-icon"></i></button> <button class="layui-btn" type="button" onclick="x_admin_show(null,'/JumpEmpAdd',600,525,true)"><i class="layui-icon"></i> </button> </div> </div> <div class="col-md-12 col-sm-12 col-xs-12"> <div class="x_panel"> <div class="x_content"> <table id="employees" class="table table-striped table-bordered"> </table> </div> </div> </div></div></body> </html><!-- Bootstrap --><link href="/static/vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"><!-- Datatables --><script src="/static/vendors/datatables.net/js/jquery.dataTables.min.js"></script><script src="/static/vendors/datatables.net-bs/js/dataTables.bootstrap.min.js"></script><!-- Custom Theme Style --><link href="/static/build/css/custom.min.css" rel="stylesheet"><script src="/static/js/sysemployees.js"></script>员工添加页面代码:
<!DOCTYPE html><html xmlns:th="http://www.thymeleaf.org"><head> <meta charset="UTF-8"> <title>欢迎页面-X-admin2.0</title> <meta name="renderer" content="webkit"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <!--<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>--> <link rel="stylesheet" href="/static/css/font.css"> <link rel="stylesheet" href="/static/css/xadmin.css"> <script type="text/javascript" src="/static/lib/jquery/dist/jquery.min.js"></script> <script src="/static/lib/layui/layui.js" charset="utf-8"></script> <script type="text/javascript" src="/static/js/xadmin.js"></script></head><body><div class="x-body layui-anim layui-anim-up"> <fieldset class="layui-elem-field"> <legend>员工信息添加</legend> <div class="layui-field-box"> <form class="layui-form" onsubmit="return addEmployee()" id="form1"> <table class="layui-table"> <tr style="border: 0px"> <td>员工编码</td> <td> <input class="layui-input" id="e_Code" name="e_Code" type="text" onblur="" onkeyup="value=value.replace(/[^a-zA-0-9\_]/g,'')" /> </td> </tr> <tr> <td>员工账号</td> <td> <input class="layui-input" id="e_LoginName" name="e_LoginName" type="text" onblur="" onkeyup="value=value.replace(/[^a-zA-0-9\_]/g,'')"/> </td> </tr> <tr> <td>员工密码</td> <td> <input class="layui-input" id="e_Pwd" name="e_Pwd" type="password" onkeyup="value=value.replace(/[^a-zA-0-9\_]/g,'')"/> </td> </tr> <tr> <td>员工姓名</td> <td> <input class="layui-input" id="e_RealName" name="e_RealName" type="text" onkeyup="value=value.replace(/[^a-zA-Zu4E00-u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^a-zA-Zu4E00-u9FA5]/g,''))" /> </td> </tr> <tr> <td>员工电话</td> <td> <input class="layui-input" id="e_Phone" name="e_Phone" type="text" onkeyup="value=value.replace(/[^d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))" onblur="ePhone()"/> </td> </tr> <tr> <td>性别</td> <td> <input type="radio" name="e_Sex.sex_Id" value="1" id="male"/> <label for="male">男</label> <input type="radio" name="e_Sex.sex_Id" value="2" id="female"/> <label for="female">女</label> </td> </tr> <tr> <td>状态</td> <td> <input type="radio" name="e_Status.st_Id" value="1" id="normal"/> <label for="normal">正常</label> <input type="radio" name="e_Status.st_Id" value="2" id="disable"/> <label for="disable">禁用</label> </td> </tr> <tr> <td>所属部门</td> <td> <select name="e_DeptId.d_Id" class="layui-select"> <option value="0">--请选择--</option> <option th:each="dept:${depts}" th:value="${dept.d_Id}" th:text="${dept.d_Name}"></option> </select> </td> </tr> <tr> <td>所属上级</td> <td> <select name="e_Superior.e_Id" class="layui-select"> <option value="0">--请选择--</option> <option th:each="employee:${employees}" th:value="${employee.e_Id}" th:text="${employee.e_RealName}"></option> </select> </td> </tr> <tr> <td>角色身份</td> <td> <select name="e_Role.r_Id" class="layui-select"> <option value="0">--请选择--</option> <option th:each="role:${roles}" th:value="${role.r_Id}" th:text="${role.r_Name}"></option> </select> </td> </tr> <tr> <td>备注信息</td> <td> <textarea name="e_Description" id="e_Description" class="layui-textarea"></textarea> </td> </tr> <tr> <td colspan="2" style="text-align: center"> <input type="submit" value="提交" class="layui-btn layui-bg-blue"/> <input type="button" value="返回" class="layui-btn layui-bg-blue" onclick="back()"/> </td> </tr> </table> </form> </div> </fieldset></div><!-- jQuery --><script src="/static/lib/jquery/dist/jquery.min.js"></script><script src="/static/js/sysemployeesadd.js"></script><script th:inline="javascript"> var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script></body></html>员工修改页面代码:
<!DOCTYPE html><html xmlns:th="http://www.thymeleaf.org"><head> <meta charset="UTF-8"> <title>欢迎页面-X-admin2.0</title> <meta name="renderer" content="webkit"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <!--<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>--> <link rel="stylesheet" href="/static/css/font.css"> <link rel="stylesheet" href="/static/css/xadmin.css"> <script type="text/javascript" src="/static/lib/jquery/dist/jquery.min.js"></script> <script src="/static/lib/layui/layui.js" charset="utf-8"></script> <script type="text/javascript" src="/static/js/xadmin.js"></script></head><body><div class="x-body layui-anim layui-anim-up"> <fieldset class="layui-elem-field"> <legend>员工信息修改</legend> <div class="layui-field-box"> <form class="layui-form" onsubmit="return updEmployees()" id="form1"> <input type="hidden" name="e_Id" th:value="${newEmployee.e_Id}"> <table class="layui-table"> <tr style="border: 0px"> <td>员工编码</td> <td> <input class="layui-input" name="e_Code" type="text" th:value="${newEmployee.e_Code}"/> </td> </tr> <tr> <td>员工姓名</td> <td> <input class="layui-input" name="e_RealName" type="text" th:value="${newEmployee.e_RealName}"/> </td> </tr> <tr> <td>性别</td> <td> <input type="radio" name="e_Sex.sex_Id" value="1" id="male" th:checked="${newEmployee.e_Sex.sex_Id eq 1}"/> <label for="male">男</label> <input type="radio" name="e_Sex.sex_Id" value="2" id="female" th:checked="${newEmployee.e_Sex.sex_Id eq 2}"/> <label for="female">女</label> </td> </tr> <tr> <td>状态</td> <td> <input type="radio" name="e_Status.st_Id" value="1" id="normal" th:checked="${newEmployee.e_Status.st_Id eq 1}"/> <label for="normal">正常</label> <input type="radio" name="e_Status.st_Id" value="2" id="disable" th:checked="${newEmployee.e_Status.st_Id eq 2}"/> <label for="disable">禁用</label> </td> </tr> <tr> <td>所属部门</td> <td> <select name="e_DeptId.d_Id" class="layui-select"> <option value="0">--请选择--</option> <option th:selected="${newEmployee.e_DeptId.d_Id eq dept.d_Id}" th:each="dept:${depts}" th:value="${dept.d_Id}" th:text="${dept.d_Name}"></option> </select> </td> </tr> <tr> <td>角色身份</td> <td th:text="${newEmployee.e_Role.r_Name}"></td> </tr> <tr> <td>备注信息</td> <td> <textarea name="e_Description" class="layui-textarea" th:text="${newEmployee.e_Description}"></textarea> </td> </tr> <tr> <td colspan="2" style="text-align: center"> <input type="submit" value="提交" class="layui-btn layui-bg-blue"/> <input type="button" value="返回" class="layui-btn layui-bg-blue" onclick="back()"/> </td> </tr> </table> </form> </div> </fieldset></div><!-- jQuery --><script src="/static/lib/jquery/dist/jquery.min.js"></script><!-- Datatables --><script src="/static/vendors/datatables.net/js/jquery.dataTables.min.js"></script><script src="/static/vendors/datatables.net-bs/js/dataTables.bootstrap.min.js"></script><script src="/static/js/sysemployeesmodify.js"></script><script th:inline="javascript"> var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script></body></html>员工详情页面代码:
<!DOCTYPE html><html xmlns:th="http://www.thymeleaf.org"><head> <meta charset="UTF-8"> <title>欢迎页面-X-admin2.0</title> <meta name="renderer" content="webkit"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/> <link rel="stylesheet" href="/static/css/font.css"> <link rel="stylesheet" href="/static/css/xadmin.css"> <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> <script src="/static/lib/layui/layui.js" charset="utf-8"></script> <script type="text/javascript" src="/static/js/xadmin.js"></script></head><body><div class="x-body layui-anim layui-anim-up"> <fieldset class="layui-elem-field"> <legend>员工信息</legend> <div class="layui-field-box"> <table class="layui-table" lay-skin="nob"> <tr style="border: 0px"> <td>员工编码</td> <td th:text="${newEmployee.e_Code}"></td> </tr> <tr> <td>员工姓名</td> <td th:text="${newEmployee.e_RealName}"></td> </tr> <tr> <td>性别</td> <td th:text="${newEmployee.e_Sex.sex_Name}"></td> </tr> <tr> <td>状态</td> <td th:text="${newEmployee.e_Status.st_Name}"></td> </tr> <tr> <td>所属部门</td> <td th:text="${newEmployee.e_DeptId.d_Name}"></td> </tr> <tr> <td>角色身份</td> <td th:text="${newEmployee.e_Role.r_Name}"></td> </tr> <tr> <td>备注信息</td> <td th:text="${newEmployee.e_Description}"></td> </tr> </table> </div> </fieldset></div><!-- jQuery --><script src="/static/lib/jquery/dist/jquery.min.js"></script><script th:inline="javascript"> var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script></body></html>员工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 "<div class="layui-btn-group">
" + " <a class="layui-btn layui-btn-sm" onclick="x_admin_show(null,'/getEmployee/"+data+"/get',600,400)">
" + " <i class="layui-icon"></i>
" + " </a>
" + " <a class="layui-btn layui-btn-sm" onclick="x_admin_show(null,'/getEmployee/"+data+"/modify',600,600,true)">
" + " <i class="layui-icon"></i>
" + " </a>
" + " <a class="layui-btn layui-btn-sm" onclick="x_admin_show(null,'/getRole/"+data+"/modify',600,450,true)">
" + " <i class="layui-icon"></i>
" + " </a>
" + " <a class="layui-btn layui-btn-sm" onclick="delEmployees("+data+",'"+full.e_RealName+"')">
" + " <i class="layui-icon"></i>
" + " </a>
" + "</div>"; } } ] }); $(".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 版权声明:本文为博主原创文章,转载请附上博文链接!