# 员工管理系统(SpringBoot+Mybatis+Thymeleaf)
SpringBoot整合CRUD实现员工管理案例,将Mybatis整合到原项目中,加入了数据库,添加了日期选项的控件。
#### 环境要求
- JDK8以上
- IDEA
- MySQL8
- Maven3
- 需要熟练掌握MySQL数据库,SpringBoot及MyBatis知识,简单的前端知识;
#### 数据库环境
创建案例所使用的数据库
```sql
CREATE DATABASE `employee`;
USE `employee`;
```
创建登陆用户数据表
```sql
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int(10) NOT NULL,
`user_name` varchar(255) NOT NULL COMMENT '用户名',
`password` varchar(255) NOT NULL COMMENT '密码',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
INSERT INTO `user` VALUES (1, 'admin', '123456');
```
创建部门信息的数据库表
```sql
DROP TABLE IF EXISTS `department`;
CREATE TABLE `department` (
`id` int(10) NOT NULL,
`department_name` varchar(255) NOT NULL COMMENT '部门名称',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
BEGIN;
INSERT INTO `department` VALUES (1, '市场部');
INSERT INTO `department` VALUES (2, '技术部');
INSERT INTO `department` VALUES (3, '销售部');
INSERT INTO `department` VALUES (4, '客服部');
INSERT INTO `department` VALUES (5, '公关部');
COMMIT;
```
创建存放员工信息的数据库表
```sql
DROP TABLE IF EXISTS `employee`;
CREATE TABLE `employee` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`employee_name` varchar(255) NOT NULL COMMENT '员工姓名',
`email` varchar(255) NOT NULL COMMENT '员工邮箱',
`gender` int(2) NOT NULL COMMENT '员工性别',
`department_id` int(10) NOT NULL COMMENT '部门编号',
`date` date NOT NULL COMMENT '入职日期',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8;
BEGIN;
INSERT INTO `employee` VALUES (1, '张三', 'zhangsan@gmail.com', 0, 1, '2020-05-12');
INSERT INTO `employee` VALUES (2, '李四', 'lisi@qq.com', 1, 2, '2020-05-05');
INSERT INTO `employee` VALUES (3, '王五', 'wangwu@126.com', 0, 3, '2020-05-15');
INSERT INTO `employee` VALUES (4, '赵六', 'zhaoliu@163.com', 1, 4, '2020-04-21');
INSERT INTO `employee` VALUES (5, '田七', 'tianqi@foxmail.com', 0, 3, '2020-05-14');
INSERT INTO `employee` VALUES (10, '王伟', 'wangwei@gmail.com', 1, 3, '2020-05-08');
INSERT INTO `employee` VALUES (11, '张伟', 'zhangwei@gmail.com', 1, 2, '2020-05-11');
INSERT INTO `employee` VALUES (12, '李伟', 'liwei@gmail.com', 1, 3, '2020-05-18');
COMMIT;
```
#### 基本环境搭建
1. 新建Spring项目, 添加Lombok,Spring Web,Thymeleaf,Mybatis,MySQL Driver的支持
2. 相关的pom依赖
```xml
<dependencies>
<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>2.1.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
```
3. 建立基本结构和配置框架
`com/`
`|-- godfrey
|-- config
|-- controller
|-- dto
|-- mapper
|-- pojo
|-- service`
4. application.yml里配置数据库连接信息及Mapper映射文件信息
```yml
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/employee?useSSL=true&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
username: employee
password: employee123
thymeleaf:
cache: false
messages:
basename: i18n.login
mybatis:
type-aliases-package: com.godfrey.pojo
mapper-locations: classpath:com.godfrey.mapper/*Mapper.xml
configuration:
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
```
5. 测试数据库连接
```java
package com.godfrey;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
@SpringBootTest
class ApplicationTests {
@Autowired
DataSource dataSource;
@Test
void contextLoads() throws SQLException {
System.out.println("数据源>>>>>>" + dataSource.getClass());
Connection connection = dataSource.getConnection();
System.out.println("连接>>>>>>>>>" + connection);
System.out.println("连接地址>>>>>" + connection.getMetaData().getURL());
connection.close();
}
}
```
**查看输出结果,数据库配置ok**
#### 创建pojo实体类
1. 创建User实体
```java
package com.godfrey.pojo;
import lombok.Data;
/**
* description : 登录验证实体类
*
* @author godfrey
* @since 2020-05-26
*/
@Data
public class User {
private Integer id;
private String userName;
private String password;
}
```
2. 创建Department实体
```java
package com.godfrey.pojo;
import lombok.Data;
/**
* description : 部门实体类
*
* @author godfrey
* @since 2020-05-26
*/
@Data
public class Department {
private Integer id;
private String departmentName;
}
```
3. 创建Employee实体
```java
package com.godfrey.pojo;
import lombok.Data;
import java.sql.Date;
/**
* description : 员工实体类
*
* @author godfrey
* @since 2020-05-26
*/
@Data
public class Employee {
private Integer id;
private String employeeName;
private String email;
private Integer gender; //0:女 1:男
private Date date;
private Integer departmentId;
}
```
4. 创建EmployeeDTO实体
```java
package com.godfrey.dto;
import lombok.Data;
import java.sql.Date;
/**
* description : EmployeeDTO
*
* @author godfrey
* @since 2020-05-26
*/
@Data
public class EmployeeDTO {
private Integer id;
private String employeeName;
private String email;
private Integer gender;
private String departmentName;
private Date date;
}
```
#### Mapper层
文件存放目录:
com.godfrey.mapper 相关接口
resources/com.godfrey.mapper 相关mapper.xml
1. 编写User的Mapper接口:UserMapper
```java
package com.godfrey.mapper;
import com.godfrey.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
/**
* description : 登录验证查询Mapper
*
* @author godfrey
* @since 2020-05-26
*/
@Mapper
@Repository
public interface UserMapper {
User selectPasswordByName(@Param("userName") String userName, @Param("password") String password);
}
```
2. 编写接口对应的Mapper.xml文件:UserMapper.xml
```xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.godfrey.mapper.UserMapper">
<select id="selectPasswordByName" resultType="User">
select * from employee.user where user_name = #{userName} and password = #{password};
</select>
</mapper>
```
3. 编写Department的Mapper接口:DepaertmentMapper
```java
pac
没有合适的资源?快使用搜索试试~ 我知道了~
基于SpringBoot+Mybatis+Thymeleaf架构实现的员工管理系统(源码+数据库).zip
共53个文件
java:20个
html:7个
js:6个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 167 浏览量
2023-08-09
22:23:11
上传
评论
收藏 185KB ZIP 举报
温馨提示
用Java写的项目,项目真实可靠,可用作本科毕业设计,欢迎大家下载学习。用Java写的项目,项目真实可靠,可用作本科毕业设计,欢迎大家下载学习。用Java写的项目,项目真实可靠,可用作本科毕业设计,欢迎大家下载学习。用Java写的项目,项目真实可靠,可用作本科毕业设计,欢迎大家下载学习。用Java写的项目,项目真实可靠,可用作本科毕业设计,欢迎大家下载学习。
资源推荐
资源详情
资源评论
收起资源包目录
基于SpringBoot+Mybatis+Thymeleaf架构实现的员工管理系统(源码+数据库).zip (53个子文件)
project_code
pom.xml 2KB
src
test
java
com
godfrey
ApplicationTests.java 3KB
main
resources
templates
main.html 4KB
error
404.html 10KB
common
commons.html 2KB
emp
list.html 3KB
update.html 4KB
add.html 4KB
index.html 2KB
i18n
login_en_US.properties 119B
login.properties 147B
login_zh_CN.properties 147B
static
laydate
laydate.js 27KB
theme
default
font
iconfont.ttf 2KB
iconfont.svg 3KB
iconfont.eot 2KB
iconfont.woff 1KB
laydate.css 8KB
js
bootstrap.min.js 48KB
popper.min.js 19KB
jquery-3.2.1.slim.min.js 68KB
feather.min.js 70KB
Chart.min.js 154KB
img
bootstrap-solid.svg 1KB
css
bootstrap.min.css 141KB
dashboard.css 2KB
signin.css 906B
application.yml 521B
com
godfrey
mapper
UserMapper.xml 389B
EmployeeMapper.xml 2KB
DepartmentMapper.xml 340B
java
com
godfrey
Application.java 304B
mapper
UserMapper.java 447B
DepartmentMapper.java 369B
EmployeeMapper.java 799B
controller
EmployeeController.java 3KB
LoginController.java 2KB
pojo
Department.java 226B
Employee.java 370B
User.java 248B
service
UserService.java 241B
EmployeeService.java 613B
impl
UserServiceImpl.java 615B
DepartmentServiceImpl.java 655B
EmployeeServiceImpl.java 1KB
DepartmentService.java 260B
dto
EmployeeDTO.java 353B
config
MyHandlerInterceptor.java 874B
MyLocaleResolver.java 1023B
MyWebMvcConfig.java 1KB
.gitignore 333B
README.md 44KB
db
springboot.sql 3KB
共 53 条
- 1
资源评论
c++服务器开发
- 粉丝: 3045
- 资源: 4463
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功