Mybatis-plus的使用
MyBatis-Plus(简称 MP)是一个 MyBatis的增强工具-在 MyBatis 的基础上只做增强不做改变-为简化开发、提高效率而生。
特性:
1、mybatis-plus环境搭建
Emp.java
``java
package com.mashibing.bean;import java.util.Date;public class Emp { private Integer empno; private String eName; private String job; private Integer mgr; private Date hiredate; private Double sal; private Double comm; private Integer deptno; public Emp() { } public Integer getEmpno() { return empno; } public void setEmpno(Integer empno) { this.empno = empno; } public String geteName() { return eName; } public void seteName(String eName) { this.eName = eName; } public String getJob() { return job; } public void setJob(String job) { this.job = job; } public Integer getMgr() { return mgr; } public void setMgr(Integer mgr) { this.mgr = mgr; } public Date getHiredate() { return hiredate; } public void setHiredate(Date hiredate) { this.hiredate = hiredate; } public Double getSal() { return sal; } public void setSal(Double sal) { this.sal = sal; } public Double getComm() { return comm; } public void setComm(Double comm) { this.comm = comm; } public Integer getDeptno() { return deptno; } public void setDeptno(Integer deptno) { this.deptno = deptno; } @Override public String toString() { return "Emp{" + "empno=" + empno + ", ename='" + eName + ''' + ", job='" + job + ''' + ", mgr=" + mgr + ", hiredate=" + hiredate + ", sal=" + sal + ", comm=" + comm + ", deptno=" + deptno + '}'; }}
`
数据库表sql语句
`sql
CREATE TABLE tbl_emp ( EMPNO int(4) NOT NULL AUTO_INCREMENT, E_NAME varchar(10) DEFAULT NULL, JOB varchar(9) DEFAULT NULL, MGR int(4) DEFAULT NULL, HIREDATE date DEFAULT NULL, SAL double(7,2) DEFAULT NULL, COMM double(7,2) DEFAULT NULL, DEPTNO int(4) DEFAULT NULL, PRIMARY KEY (EMPNO)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
`
pom.xml
`xml
4.0.0 com.mashibing mybatis_plus 1.0-SNAPSHOT com.baomidou mybatis-plus 3.3.1 junit junit 4.13 test log4j log4j 1.2.17 com.alibaba druid 1.1.21 mysql mysql-connector-java 8.0.19 org.springframework spring-context 5.2.3.RELEASE org.springframework spring-orm 5.2.3.RELEASE
`
mybatis-config.xml
log4j.properties
`properties
`全局日志配置log4j.rootLogger=INFO, stdout# MyBatis 日志配置log4j.logger.com.mashibing=truce# 控制台输出log4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
db.properties
`properties
driverClassname=com.mysql.cj.jdbc.Driverusername=rootpassword=123456url=jdbc:mysql://192.168.85.111:3306/demo?serverTimezone=UTC
`
spring.xml
MyTest.java
`java
package com.mashibing;import com.alibaba.druid.pool.DruidDataSource;import org.junit.Test;import org.springframework.context.ApplicationContext;import org.springframework.context.suppor