ems-员工管理系统

一、项目搭建

1.1 初始化项目依赖

pom.xml

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <java.version>11</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.4</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.25</version>
        </dependency>

        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.7</version>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.14</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.2.5</version>
        </dependency>

    </dependencies>

banner.txt

    \▔\
    )..)
   /../▂▂▂
▂▂╱┈ ▕▂▂▂▏
▉┈-┈┈ ▕▂▂▂▏
▉┈-┈┈▕▂▂▂▏
▔▔╲▂▕▂▂▏
by coffeeMao

application.properties

server.port=80
#spring.favicon.enabled=false
spring.thymeleaf.cache=false
#server.servlet.context-path=/mao
spring.messages.basename=i18n.login
spring.mvc.format.date=yyyy-MM-hh

spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.url=jdbc:mysql://localhost:3306/ems?serverTimezone-UTC&useUnicode=true&characterEncoding=utf-8
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource

mybatis.type-aliases-package=com.mao.entity
mybatis.mapper-locations=classpath:mapper/*.xml

这里注意项目使用到了国际化功能,所以文件编码统一设置为UTF-8

二、ems的前端

common公共页面 侧边栏 + 导航栏的提取

<!DOCTYPE html>
<html lang="en">

<!--头部导航栏-->

<nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0" th:fragment="topbar">
  <a class="navbar-brand col-sm-3 col-md-2 mr-0" th:href="@{/user/logout}">[[${session.loginUser}]]</a>
<!--  <input class="form-control form-control-dark w-100" name="id" type="text" placeholder="Search" aria-label="Search">-->
  <form class="form-control form-control-dark w-100" th:action="@{/query}" method="get">
    <input class="form-control-dark" name="id" type="text" placeholder="Search" aria-label="Search">
    <input type="submit"  value="查询">
  </form>

  <ul class="navbar-nav px-3">
    <li class="nav-item text-nowrap">
      <a class="nav-link" th:href="@{/user/logout}">注销</a>
    </li>
  </ul>
</nav>

<!--侧边导航栏-->

<nav class="col-md-2 d-none d-md-block bg-light sidebar" th:fragment="sidebar">
  <div class="sidebar-sticky">
    <ul class="nav flex-column">
      <li class="nav-item">
        <a th:class="${active=='main.html' ? 'nav-link active' : 'nav-link'}" th:href="@{/index.html}">
          <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-home">
            <path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path>
            <polyline points="9 22 9 12 15 12 15 22"></polyline>
          </svg>
          主页<span class="sr-only">(current)</span>
        </a>
      </li>

      <li class="nav-item">
        <a th:class="${active=='list.html' ? 'nav-link active' : 'nav-link'}" th:href="@{/emps}">
          <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-users">
            <path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path>
            <circle cx="9" cy="7" r="4"></circle>
            <path d="M23 21v-2a4 4 0 0 0-3-3.87"></path>
            <path d="M16 3.13a4 4 0 0 1 0 7.75"></path>
          </svg>
          员工管理
        </a>
      </li>
    </ul>
  </div>
</nav>
</html>

index.html 登录界面

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<meta name="description" content="">
		<meta name="author" content="">
		<title>Signin Template for Bootstrap</title>
		<!-- Bootstrap core CSS -->
		<link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
		<!-- Custom styles for this template -->
		<link th:href="@{/css/signin.css}" rel="stylesheet">
	</head>

	<body class="text-center">
		<form class="form-signin" th:action="@{/user/login}">
			<img class="mb-4" th:src="@{/img/bootstrap-solid.svg}" alt="" width="72" height="72">
			<h1 class="h3 mb-3 font-weight-normal" th:text="#{login.btn}">Please sign in</h1>

			<p style="color: red" th:text="${msg}" th:if="${not #strings.isEmpty(msg)}"></p>
<!--			<label class="sr-only" th:text="#{login.username}">Username</label>-->
			<input type="text" name="username" class="form-control" th:placeholder="#{login.username}" required="" autofocus="">
<!--			<label class="sr-only"th:text="#{login.password}">Password</label>-->
			<input type="password" name="password" class="form-control" th:placeholder="#{login.password}" required="">
			<div class="checkbox mb-3">
				<label>
          <input type="checkbox" value="remember-me"> [[#{login.remember}]]
        </label>
			</div>
			<button class="btn btn-lg btn-primary btn-block" type="submit">[[#{login.btn}]]</button>
			<p class="mt-5 mb-3 text-muted">© 2022-至今</p>
			<a class="btn btn-sm" th:href="@{/index.html(mkt='zh-CN')}">中文</a>
			<a class="btn btn-sm" th:href="@{/index.html(mkt='en-US')}">English</a>
		</form>

	</body>

</html>

404错误页面,替换掉公共部分,定制自己的404页面

	<body>
		<div th:replace="~{commons/commons::topbar}"></div>

		<div class="container-fluid">
			<div class="row">
				<div th:replace="~{commons/commons::sidebar(active='list.html')}"></div>
				<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
					<h1>404</h1>
				</main>
			</div>
		</div>

list.html员工展示

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<meta name="description" content="">
		<meta name="author" content="">

		<title>Dashboard Template for Bootstrap</title>
		<!-- Bootstrap core CSS -->
		<link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">

		<!-- Custom styles for this template -->
		<link th:href="@{/css/dashboard.css}" rel="stylesheet">
		<style type="text/css">
			/* Chart.js */
			
			@-webkit-keyframes chartjs-render-animation {
				from {
					opacity: 0.99
				}
				to {
					opacity: 1
				}
			}
			
			@keyframes chartjs-render-animation {
				from {
					opacity: 0.99
				}
				to {
					opacity: 1
				}
			}
			
			.chartjs-render-monitor {
				-webkit-animation: chartjs-render-animation 0.001s;
				animation: chartjs-render-animation 0.001s;
			}
		</style>
	</head>

	<body>
<!--	头部导航栏-->
		<div th:replace="~{commons/commons::topbar}"></div>

		<div class="container-fluid">
			<div class="row">
<!--				侧边栏-->
				<div th:replace="~{commons/commons::sidebar(active='list.html')}"></div>
				<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
<!--					点过去是get请求-->
					<h2><a class="btn btn-sm btn-success" th:href="@{/emp}">添加员工</a></h2>
<!--					<h2><a class="btn btn-sm btn-success" th:href="@{/emp}">添加员工</a></h2>-->
					<div class="table-responsive">
						<table class="table table-striped table-sm">
							<thead>
								<tr>
									<th>id</th>
									<th>姓名</th>
									<th>电子邮箱</th>
									<th>性别</th>
									<th>所属部门</th>
									<th>出生日期</th>
								</tr>
							</thead>
							<tbody>
								<tr th:each="emp:${emps}">
									<td th:text="${emp.getId()}"></td>
									<td th:text="${emp.getLastName()}"></td>
									<td th:text="${emp.getEmail()}"></td>
									<td th:text="${emp.getGender() == 0 ? '' : ''}"></td>
									<td th:text="${emp.department.getDepartmentName()}"></td>
									<td th:text="${#dates.format(emp.getBirth(),'yyyy-MM-dd')}"></td>

									<td>
										<a class="btn btn-sm btn-primary" th:href="@{/emp/}+${emp.getId()}">编辑</a>
										<a class="btn btn-sm btn-danger" th:href="@{/delemp/}+${emp.getId()}">删除</a>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
				</main>
			</div>
		</div>

		<!-- Bootstrap core JavaScript
    ================================================== -->
		<!-- Placed at the end of the document so the pages load faster -->
		<script type="text/javascript" src="asserts/js/jquery-3.2.1.slim.min.js"></script>
		<script type="text/javascript" src="asserts/js/popper.min.js"></script>
		<script type="text/javascript" src="asserts/js/bootstrap.min.js"></script>

		<!-- Icons -->
		<script type="text/javascript" src="asserts/js/feather.min.js"></script>
		<script>
			feather.replace()
		</script>

		<!-- Graphs -->
		<script type="text/javascript" src="asserts/js/Chart.min.js"></script>
		<script>
			var ctx = document.getElementById("myChart");
			var myChart = new Chart(ctx, {
				type: 'line',
				data: {
					labels: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
					datasets: [{
						data: [15339, 21345, 18483, 24003, 23489, 24092, 12034],
						lineTension: 0,
						backgroundColor: 'transparent',
						borderColor: '#007bff',
						borderWidth: 4,
						pointBackgroundColor: '#007bff'
					}]
				},
				options: {
					scales: {
						yAxes: [{
							ticks: {
								beginAtZero: false
							}
						}]
					},
					legend: {
						display: false,
					}
				}
			});
		</script>

	</body>

</html>

add.html员工修改页面

<!--	头部导航栏-->
		<div th:replace="~{commons/commons::topbar}"></div>

		<div class="container-fluid">
			<div class="row">
<!--				侧边栏-->
				<div th:replace="~{commons/commons::sidebar(active='list.html')}"></div>
				<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
					<form th:action="@{/emp}" method="post">
						<div class="form-group">
							<label>姓名</label>
							<input type="text" name="lastName" class="form-control" placeholder="姓名">
						</div>
						<div class="form-group">
							<label>电子邮箱</label>
							<input type="email" name="email" class="form-control" placeholder="邮箱">
						</div>
						<div class="form-group">
							<label>性别</label><br>
							<div class="form-check form-check-inline">
								<label class="form-check-label">
									<input class="form-check-input" type="radio" checked name="gender" value="1"></label>
							</div>
							<div class="form-check form-check-inline">
								<label class="form-check-label">
									<input class="form-check-input" type="radio" name="gender" value="0"></label>
							</div>
						</div>
						<div class="form-group">
							<label>所属部门</label>
							<select class="form-control" name="department.id">
								<option value="none" selected disabled hidden>------</option>
								<option th:each="department:${departments}" th:text="${department.getDepartmentName()}" th:value="${department.getId()}"></option>
							</select>
						</div>
						<div class="form-group">
							<label>出生日期</label>
<!--							<input type="text" name="birth" class="form-control" placeholder="birth:yyyy/MM/dd">-->
							<input type="date" name="birth" class="form-control">

						</div>
						<button type="submit" class="btn btn-primary">添加</button>
					</form>
				</main>
			</div>
		</div>

update.html修改员工的页面

<!--	头部导航栏-->
		<div th:replace="~{commons/commons::topbar}"></div>

		<div class="container-fluid">
			<div class="row">
<!--				侧边栏-->
				<div th:replace="~{commons/commons::sidebar(active='list.html')}"></div>
				<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
					<form th:action="@{/updateEmp}" method="post">
						<input type="hidden" name="id" th:value="${emp.getId()}">
						<div class="form-group">
							<label>姓名</label>
							<input th:value="${emp.getLastName()}" name="lastName" class="form-control" placeholder="姓名">
						</div>
						<div class="form-group">
							<label>电子邮箱</label>
							<input th:value="${emp.getEmail()}" name="email" class="form-control" placeholder="邮箱">
						</div>
						<div class="form-group">
							<label>性别</label><br/>
							<div class="form-check form-check-inline">
								<label class="form-check-label"><input th:checked= "${emp.getGender()==1}" class="form-check-input" type="radio" name="gender" value="1"></label>
							</div>
							<div class="form-check form-check-inline">
								<label class="form-check-label"><input th:checked= "${emp.getGender()==0}" class="form-check-input" type="radio" name="gender" value="0"></label>
							</div>
						</div>
						<div class="form-group">
							<label>所属部门</label>
							<!--注意这里的name是department.id,因为传入的参数为id-->
							<select class="form-control" name="department.id">
								<option th:selected="${department.getId()==emp.getDepartment().getId()}" th:each="department:${departments}" th:text="${department.getDepartmentName()}" th:value="${department.getId()}"></option>
							</select>
						</div>
						<div class="form-group">
							<label>出生日期</label>
							<input th:value="${#dates.format(emp.getBirth(),'yyyy-MM-dd')}" name="birth" type="date" class="form-control">
						</div>
						<button type="submit" class="btn btn-primary">修改</button>
					</form>
				</main>

			</div>
		</div>

query.html查询员工的页面

<!--	头部导航栏-->
<div th:replace="~{commons/commons::topbar}"></div>

<div class="container-fluid">
	<div class="row">
		<!--				侧边栏-->
		<div th:replace="~{commons/commons::sidebar(active='list.html')}"></div>
		<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
			<div class="table-responsive">
				<table class="table table-striped table-sm">
					<thead>
					<tr>
						<th>id</th>
						<th>姓名</th>
						<th>电子邮箱</th>
						<th>性别</th>
						<th>所属部门</th>
						<th>出生日期</th>
					</tr>
					</thead>
					<tbody>
					<tr th:each="emp:${emp}">
						<td th:text="${emp.getId()}"></td>
						<td th:text="${emp.getLastName()}"></td>
						<td th:text="${emp.getEmail()}"></td>
						<td th:text="${emp.getGender() == 0 ? '' : ''}"></td>
<!--						后端SQL 查询出来的是 id-->
						<td th:text="${emp.department.getDepartmentName()}"></td>
						<td th:text="${#dates.format(emp.getBirth(),'yyyy-MM-dd')}"></td>
						<td>
							<a class="btn btn-sm btn-primary" th:href="@{/emp/}+${emp.getId()}">编辑</a>
							<a class="btn btn-sm btn-danger" th:href="@{/delemp/}+${emp.getId()}">删除</a>
						</td>
					</tr>
					</tbody>
				</table>
			</div>
		</main>
	</div>
</div>

国际化文件就是建立一个资源包,login_en_US.propertieslogin_zh_CN.propertieslogin.properties三个资源文件,自己翻译好写入文件就行
在这里插入图片描述

三、ems的后端

config

LoginHandlerInterceptor.java 手动的登录拦截器

public class LoginHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object loginUser = request.getSession().getAttribute("loginUser");
        if (loginUser == null){
            request.setAttribute("msg","没有权限,请先登录!");
            request.getRequestDispatcher("/index.html").forward(request,response);
            return false;
        }else {
            return true;
        }
    }
}

MyLocaleResolver.java 自定义的国际化处理文件

public class MyLocaleResolver implements LocaleResolver {
    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        String language = request.getParameter("mkt");
        Locale locale = Locale.getDefault();
        if (!StringUtils.isEmpty(language)){
            String[] split = language.split("-");
            locale= new Locale(split[0], split[1]);

        }
        return locale;
    }

    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {

    }
}

MyMvcConfig.java 自定义的MVC配置,添加了视图控制器自定义的拦截器,国际化对象

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
        registry.addViewController("/main.html").setViewName("dashboard");
    }

    @Bean
    public LocaleResolver localeResolver(){
        return new MyLocaleResolver();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/index.html","/","/img/*","/user/login","/css/*","/js/**");
    }
}

pojo

Department.java

public class Department {

    private Integer id;

    private String departmentName;

    public String getDepartmentName() {
        return departmentName;
    }

}

Employee.java

public class Employee {

    private Integer id;

    private String lastName;

    private String email;

    private Integer gender;

    private Department department;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date birth;

}

Controller

LoginController.java

@Controller
public class LoginController {

    @RequestMapping("/user/login")
    public String login(@RequestParam("username") String username,
                        @RequestParam("password") String password,
                        Model model,
                        HttpSession session){
        if (!StringUtils.isEmpty(username) && password.equals("123456")){
            session.setAttribute("loginUser",username);
            return "redirect:/main.html";
        }else {
            model.addAttribute("msg", "用户名或者密码错误!");
            return "index";
        }
    }

    @RequestMapping("/user/logout")
    public String login(HttpSession session){
        session.invalidate();
        return "redirect:/index.html";
    }
}

EmployeeController.java 员工控制器,负责员工的CRU的控制

@Controller
public class EmployeeController {

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private EmployeeService employeeService;

    // 查询所有员工之后进行展示

    @RequestMapping("/emps")
    public String list(Model model){
        Collection<Employee> employees = employeeService.getAll();
        model.addAttribute("emps",employees);
        return "emp/list";
    }

    @GetMapping("/emp")
    public String addPage(Model model){
        Collection<Department> departments = departmentService.getDepartments();
        model.addAttribute("departments", departments);
        return "emp/add";
    }
    @PostMapping("/emp")
    public String addEmp(Employee employee){
        // 调用底层业务方法保存员工信息
        employeeService.addEmployee(employee);
        System.out.println(employee.toString());
        // 重定向到/emps,刷新列表,返回到list页面
        return "redirect:/emps";
    }

    @GetMapping("/emp/{id}")
    public String toUpdateEmp(@PathVariable("id")Integer id, Model model){
        Employee employee = employeeService.getEmployeeById(id);
        model.addAttribute("emp",employee);

        //查出所有部门的信息
        Collection<Department> departments = departmentService.getDepartments();
        model.addAttribute("departments", departments);
        return "emp/update";
    }

    @PostMapping("/updateEmp")
    public String updateEmp(Employee employee){
        employeeService.update(employee);
        return "redirect:/emps";
    }

    // 删除员工
    @GetMapping("/delemp/{id}")
    public String deleteEmp(@PathVariable("id") int id){
        employeeService.remove(id);
        return "redirect:/emps";
    }

    @GetMapping("/query")
    public String queryPage(@RequestParam( required = false,value = "id") Integer id, Model model){
        if (employeeService.queryIds().contains(id)){
            Employee employee = employeeService.getEmployeeById(id);
            model.addAttribute("emp",employee);
            return "emp/query";
        }else{
            return "redirect:/emps";
        }
    }
}

server

public interface EmployeeService {

    Collection<Employee> getAll();

    void update(Employee employee);

    void addEmployee(Employee employee);

    Employee getEmployeeById(Integer id);

    void remove(Integer id);

    List<Integer> queryIds();
}



public interface DepartmentService {

    Collection<Department> getDepartments();

    Department getDepartmentById(Integer id);
}

server.impl

@Service
public class DepartmentServiceImpl implements DepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;


    @Override
    public Collection<Department> getDepartments(){
        return departmentMapper.getDepartments();
    }

    @Override
    public Department getDepartmentById(Integer id){
        return departmentMapper.getDepartmentById(id);
    }
}



@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public Collection<Employee> getAll(){
        return employeeMapper.getAll();
    }

    @Override
    public void update(Employee employee){
        employeeMapper.update(employee);
    }


    @Override
    public void addEmployee(Employee employee){
        employeeMapper.addEmployee(employee);
    }

    @Override
    public Employee getEmployeeById(Integer id){
        return employeeMapper.getEmployeeById(id);
    }

    @Override
    public void remove(Integer id){
        employeeMapper.remove(id);
    }

    @Override
    public List<Integer> queryIds(){
        return employeeMapper.queryIds();
    }
}

mapper

DepartmentMapper.java

@Mapper
@Repository
public interface DepartmentMapper {

    /**
     * 获取全部的部门
     * @return
     */
    Collection<Department> getDepartments();

    /**
     * 根据 id 获取部门
     * @param id
     * @return
     */
    Department  getDepartmentById(Integer id);
}

EmployeeMapper.java

@Mapper
@Repository
public interface EmployeeMapper {

    void update(Employee employee);

    void addEmployee(Employee employee);

    /**
     * 查询所有的员工
     * @return
     */
    Collection<Employee> getAll();

    Employee getEmployeeById(Integer id);

    void remove(Integer id);

    List<Integer> queryIds();
}

mapper.xml

DepartmentMapper.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.mao.mapper.DepartmentMapper">

    <select id="getDepartments" resultType="com.mao.entity.Department">
        select * from department;
    </select>

    <select id="getDepartmentById" resultType="com.mao.entity.Department">
        select * from department where id=#{id};
    </select>

</mapper>

EmployeeMapper.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">
<!--suppress MybatisXMapperXmlInspection -->
<mapper namespace="com.mao.mapper.EmployeeMapper">

    <resultMap id="EmployeeResultMap" type="Employee">
        <id property="id" column="id"/>
        <result property="lastName" column="lastname"/>
        <result property="email" column="email"/>
        <result property="gender" column="gender"/>
        <result property="department.id" column="departmentId"/>
        <result property="department.departmentName" column="departmentName"/>
        <result property="birth" column="birth"/>
    </resultMap>

    <select id="getAll" resultMap="EmployeeResultMap">
        SELECT * FROM employee,department WHERE employee.departmentId=department.id and employee.deleted = 0;
    </select>

    <!-- 增加员工 -->
    <insert id="addEmployee" parameterType="Employee">
        INSERT INTO employee (lastname,email,gender,departmentId,birth) values ( #{lastName},#{email},#{gender},#{department.id},#{birth})
    </insert>

    <!-- 通过员工id获得员工信息 联表查询  SELECT * FROM employee 查出来只是 id,联表 将id 转 name-->
    <select id="getEmployeeById" parameterType="int" resultMap="EmployeeResultMap">
        SELECT * FROM employee, department WHERE employee.id=#{id} and employee.departmentId=department.id
    </select>

    <select id="queryIds" resultType="java.lang.Integer">
        select id from employee where deleted = 0;
    </select>

    <!-- 更新员工 -->
    <update id="update" parameterType="Employee">
        UPDATE employee
        <set>
            <if test="lastName != null">
                lastname = #{lastName},
            </if>
            <if test="email != null">
                email = #{email},
            </if>
            <if test="gender != null">
                gender = #{gender},
            </if>
            <if test="department.id != null">
                departmentId = #{department.id},
            </if>
            <if test="birth != null">
                birth = #{birth},
            </if>
        </set>
        <where>
            id=#{id}
        </where>
    </update>
    <!-- 删除员工 -->
    <update id="remove" parameterType="Employee">
        update employee set deleted = 1 where id=#{id};
    </update>
</mapper>

结果演示

在这里插入图片描述
学习网址链接
https://www.bilibili.com/video/BV1PE411i7CV?p=20

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
EMS管理系统是一种用于对企业的员工进行管理和监控的电子化系统。它通过集成信息技术,实现了对员工的考勤、薪资、绩效评估、培训和福利等方面的管理。该系统的源码是指实现该系统所需的程序代码。 EMS管理系统的源码通常包括前端和后端两部分。前端源码负责实现用户界面,包括登录界面、主页面、员工信息展示等功能。后端源码则负责实现业务逻辑和数据处理方面的功能,包括员工信息的存储、查询和更新、考勤记录的统计和计算、薪资表的生成等。 根据实际需求,EMS管理系统的源码可能使用不同的开发语言和技术,比如Java、PHP、Python等。开发人员可以根据具体情况选择适合的开发工具和框架,比如Spring框架、Django框架等。 对于企业来说,获得EMS管理系统的源码意味着可以根据自身需求进行定制开发和修改。可以根据公司的规模和组织架构调整系统的功能和界面,添加特定的功能模块,并对业务流程进行优化。同时,拥有源码还意味着可以根据需要进行维护和升级,确保系统的正常运行和安全性。 然而,需要注意的是,EMS管理系统的源码只是系统的一部分,搭建和使用该系统还需要服务器、数据库和网络等基础设施的支持。此外,为了保护系统的安全性,源码的分发和使用需要遵循相关法律法规,并进行合理的权限管理和数据保护。 总而言之,EMS管理系统的源码是实现该系统所需的程序代码,它可以根据企业的需求进行定制开发和修改,提升员工管理的效率和准确性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值