首先导入所需jar包,再连接数据库:
<?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=80
spring.mvc.view.prefix=classpath:/templates/
spring.mvc.view.suffix=.html
#thymeleaf start
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
#开发时关闭缓存,不然没法看到实时页面
spring.thymeleaf.cache=false
#thymeleaf end
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.url=jdbc:mysql://localhost:3306/ManageDB?useUnicode=true&characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=994994
spring.datasource.driverClassName=com.mysql.jdbc.Driver
mybatis.mapper-locations=classpath:/mybatis/*.xml
mybatis.type-aliases-package=com.manager.pojo
mybatis.configuration.auto-mapping-behavior=full
mybatis.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;
@Service
public 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;
@Service
public 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;
@Service
public 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;
@Controller
public 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;
@Controller
public 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;
@Controller
public 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-\z\A-\Z0-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-\z\A-\Z0-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-\z\A-\Z0-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-Z\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\a-zA-Z\u4E00-\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\">\n" +
" <a class=\"layui-btn layui-btn-sm\" onclick=\"x_admin_show(null,'/getEmployee/"+data+"/get',600,400)\">\n" +
" <i class=\"layui-icon\"></i>\n" +
" </a>\n" +
" <a class=\"layui-btn layui-btn-sm\" onclick=\"x_admin_show(null,'/getEmployee/"+data+"/modify',600,600,true)\">\n" +
" <i class=\"layui-icon\"></i>\n" +
" </a>\n" +
" <a class=\"layui-btn layui-btn-sm\" onclick=\"x_admin_show(null,'/getRole/"+data+"/modify',600,450,true)\">\n" +
" <i class=\"layui-icon\"></i>\n" +
" </a>\n" +
" <a class=\"layui-btn layui-btn-sm\" onclick=\"delEmployees("+data+",'"+full.e_RealName+"')\">\n" +
" <i class=\"layui-icon\"></i>\n" +
" </a>\n" +
"</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("修改失败!");
}
}
});
}