<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 https://maven.apache.org/xsd/maven-4.0.0.xsd”>
4.0.0
com.yusael
ems
0.0.1-SNAPSHOT
ems
springboot + mybatis + thymeleaf 的 ems
<java.version>1.8</java.version>
org.springframework.boot
spring-boot-starter-parent
2.2.7.RELEASE
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-thymeleaf
org.mybatis.spring.boot
mybatis-spring-boot-starter
2.1.2
mysql
mysql-connector-java
5.1.43
runtime
com.alibaba
druid
1.1.12
org.projectlombok
lombok
true
org.springframework.boot
spring-boot-maven-plugin
==============================================================================
需求分析:
-
既然做的员工管理系统,那肯定需要一个员工表(t_emp)来存储员工的信息,表的具体内容需要根据业务需求来决定,我们这里就做一个简易的管理系统,设的较为简单。
-
由于我们要做登录功能,因此我们需要一个用户表(t_user)来存储用户信息。
员工表的SQL:
CREATE TABLE t_emp
(
id
varchar(40) NOT NULL,
name
varchar(60) DEFAULT NULL,
salary
double(7,2) DEFAULT NULL,
age
int(3) DEFAULT NULL,
bir
date DEFAULT NULL,
PRIMARY KEY (id
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
用户表的SQL:
CREATE TABLE t_user
(
id
varchar(40) NOT NULL,
username
varchar(40) DEFAULT NULL,
realname
varchar(40) DEFAULT NULL,
password
varchar(40) DEFAULT NULL,
sex
varchar(8) DEFAULT NULL,
PRIMARY KEY (id
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
数据库建完表以后,还需要在 application.properties 中配置:
server.port=8989
server.servlet.context-path=/ems
##mysql配置
#指定连接池类型
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
#指定驱动
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#指定url
spring.datasource.url=jdbc:mysql://localhost:3306/ems?characterEncoding=UTF-8
#指定用户名
spring.datasource.username=root
#指定密码
spring.datasource.password=1234
##配置thymleaf(下面注释的是默认配置, 可以不设置)
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html
#spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.cache=false # 想让热部署生效必须配置这个
#spring.thymeleaf.servlet.content-type=text/html
默认无法直接访问templates下的页面, 需要设置
spring.resources.static-locations=classpath:/templates/, classpath:/static/
#指定mapper配置文件位置
mybatis.mapper-locations=classpath:/com/yusael/mapper/*.xml
#指定起别名了的类
mybatis.type-aliases-package=com.yusael.entity
在启动类中加上 @MapperScan("com.yusael.dao")
来扫描该目录。
package com.yusael;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan(“com.yusael.dao”)
public class EmsApplication {
public static void main(String[] args) {
SpringApplication.run(EmsApplication.class, args);
}
}
============&#