diff --git a/mybaits_02/.gitignore b/mybaits_02/.gitignore
new file mode 100644
index 0000000..5ff6309
--- /dev/null
+++ b/mybaits_02/.gitignore
@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
\ No newline at end of file
diff --git a/mybaits_02/pom.xml b/mybaits_02/pom.xml
new file mode 100644
index 0000000..888c7ab
--- /dev/null
+++ b/mybaits_02/pom.xml
@@ -0,0 +1,60 @@
+
+
+ 4.0.0
+
+ com.msb.springmvc
+ mybaits_02
+ 1.0-SNAPSHOT
+
+
+
+ mysql
+ mysql-connector-java
+ 8.0.16
+
+
+
+ org.mybatis
+ mybatis
+ 3.5.3
+
+
+
+ junit
+ junit
+ 4.13.1
+ test
+
+
+
+ org.projectlombok
+ lombok
+ 1.18.12
+ provided
+
+
+
+
+ log4j
+ log4j
+ 1.2.17
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 8
+ 8
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mybaits_02/src/main/java/com/msb/mapper/DeptMapper.java b/mybaits_02/src/main/java/com/msb/mapper/DeptMapper.java
new file mode 100644
index 0000000..6ed638e
--- /dev/null
+++ b/mybaits_02/src/main/java/com/msb/mapper/DeptMapper.java
@@ -0,0 +1,16 @@
+package com.msb.mapper;
+
+import com.msb.pojo.Dept;
+import org.apache.ibatis.annotations.Param;
+
+public interface DeptMapper {
+
+ /**
+ * 添加部门同时返回自增id
+ * @param dept
+ * @return
+ */
+ int addDept(@Param("dept") Dept dept);
+
+ Dept findDeptJoinEmpByDeptno(@Param("deptno")int deptno);
+}
diff --git a/mybaits_02/src/main/java/com/msb/mapper/EmpMapper.java b/mybaits_02/src/main/java/com/msb/mapper/EmpMapper.java
new file mode 100644
index 0000000..61af857
--- /dev/null
+++ b/mybaits_02/src/main/java/com/msb/mapper/EmpMapper.java
@@ -0,0 +1,95 @@
+package com.msb.mapper;
+
+import com.msb.pojo.Emp;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+public interface EmpMapper {
+ /**
+ * 查找所有员工
+ * @return
+ */
+ ListfindAll();
+
+ /**
+ * 根据员工编号查询单个员工信息的方法
+ */
+ Emp findEmpByNo(int empno);
+
+ /**
+ * 根据部门编号和薪资下限去查询员工信息
+ */
+ List findEmpByEmpnoAndSal(@Param("deptno") int deptno, @Param("sal") double sal);
+
+ /**
+ * 根据部门编号和薪资下限去查询员工信息
+ * 参数使用 Emp实体对象
+ * @param emp
+ * @return
+ */
+ List findEmpByEmpnoAndSal2(@Param("emp") Emp emp);
+
+
+ /**
+ * 根据员工的名称进行模糊搜索
+ * @param ename
+ * @return
+ */
+ List findByName(@Param("ename")String ename);
+
+
+ /**
+ * 添加员工信息
+ * @param emp
+ * @return
+ */
+ int addEmp(@Param("emp")Emp emp);
+
+
+ /**
+ * 根据员工编号修改员工名称
+ * @param empno
+ * @param ename
+ * @return
+ */
+ int updateNameByNo(@Param("empno")int empno, @Param("ename")String ename);
+
+ /**
+ * 根据员工编号删除员工
+ * @param empno
+ * @return
+ */
+
+ int deleteByEmpno(@Param("empno")int empno);
+
+ /**
+ * 根据传入的参数的有无查询数据
+ * @param emp
+ * @return
+ */
+ List findByCondition(@Param("emp") Emp emp);
+
+ /**
+ * 根据给出的实体是否存在来更新员工信息
+ * @param emp
+ * @return
+ */
+ int updateEmpByCondition(@Param("emp")Emp emp);
+
+ /**
+ * 根据员工编号数组查询员工
+ * @param empnos
+ * @return
+ */
+ List findByEmpnosArr(int[] empnos);
+
+ /**
+ * 根据员工编号列表查询员工
+ * @param empnos
+ * @return
+ */
+ List findByEmpnosList(List empnos);
+
+ Emp findEmpJoinDeptByEmpno(@Param("empno") int empno);
+}
diff --git a/mybaits_02/src/main/java/com/msb/mapper/ProjectMapper.java b/mybaits_02/src/main/java/com/msb/mapper/ProjectMapper.java
new file mode 100644
index 0000000..b1fda31
--- /dev/null
+++ b/mybaits_02/src/main/java/com/msb/mapper/ProjectMapper.java
@@ -0,0 +1,8 @@
+package com.msb.mapper;
+
+import com.msb.pojo.Project;
+import org.apache.ibatis.annotations.Param;
+
+public interface ProjectMapper {
+ Project findProjectJoinEmpsByPid(@Param("pid") int pid);
+}
diff --git a/mybaits_02/src/main/java/com/msb/pojo/Dept.java b/mybaits_02/src/main/java/com/msb/pojo/Dept.java
new file mode 100644
index 0000000..00f143d
--- /dev/null
+++ b/mybaits_02/src/main/java/com/msb/pojo/Dept.java
@@ -0,0 +1,19 @@
+package com.msb.pojo;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class Dept {
+ private Integer deptno;
+ private String dname;
+ private String loc;
+
+ // 一对多的关系,部门的所有员工信息查到下面的属性
+ private List empList;
+}
diff --git a/mybaits_02/src/main/java/com/msb/pojo/Emp.java b/mybaits_02/src/main/java/com/msb/pojo/Emp.java
new file mode 100644
index 0000000..7df449b
--- /dev/null
+++ b/mybaits_02/src/main/java/com/msb/pojo/Emp.java
@@ -0,0 +1,26 @@
+package com.msb.pojo;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.Date;
+
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class Emp {
+ private Integer empno;
+ private String ename;
+ private String job;
+ private Integer mgr;
+ private Date hiredate;
+ private Double sal;
+ private Double comn;
+ private Integer deptno;
+
+ // 一对一的关系,部门信息填充到该属性下
+ private Dept dept;
+
+}
diff --git a/mybaits_02/src/main/java/com/msb/pojo/Project.java b/mybaits_02/src/main/java/com/msb/pojo/Project.java
new file mode 100644
index 0000000..fc45fae
--- /dev/null
+++ b/mybaits_02/src/main/java/com/msb/pojo/Project.java
@@ -0,0 +1,18 @@
+package com.msb.pojo;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class Project {
+ private Integer pid;
+ private String pname;
+ private Integer money;
+
+ private List projectRecordList;
+}
diff --git a/mybaits_02/src/main/java/com/msb/pojo/ProjectRecord.java b/mybaits_02/src/main/java/com/msb/pojo/ProjectRecord.java
new file mode 100644
index 0000000..a301551
--- /dev/null
+++ b/mybaits_02/src/main/java/com/msb/pojo/ProjectRecord.java
@@ -0,0 +1,15 @@
+package com.msb.pojo;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class ProjectRecord {
+ private Integer empno;
+ private Integer pid;
+
+ private Emp emp;
+}
diff --git a/mybaits_02/src/main/resources/com/msb/mapper/DeptMapper.xml b/mybaits_02/src/main/resources/com/msb/mapper/DeptMapper.xml
new file mode 100644
index 0000000..3b7eaa8
--- /dev/null
+++ b/mybaits_02/src/main/resources/com/msb/mapper/DeptMapper.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+ insert into dept values(DEFAULT, #{dept.dname}, #{dept.loc});
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mybaits_02/src/main/resources/com/msb/mapper/EmpMapper.xml b/mybaits_02/src/main/resources/com/msb/mapper/EmpMapper.xml
new file mode 100644
index 0000000..703fb6f
--- /dev/null
+++ b/mybaits_02/src/main/resources/com/msb/mapper/EmpMapper.xml
@@ -0,0 +1,135 @@
+
+
+
+ empno,ename,job,mgr,hiredate,sal,comm,deptno
+ select from emp
+
+
+
+
+
+
+
+
+
+
+
+
+ insert into emp values
+(DEFAULT, #{emp.ename}, #{emp.job}, #{emp.mgr}, #{emp.hiredate}, #{emp.sal},#{emp.comn},#{emp.deptno})
+
+
+
+ update emp set ename=#{ename} where empno=#{empno};
+
+
+
+ delete from emp where empno = #{empno}
+
+
+
+
+
+ update emp
+
+
+ ,ename = #{emp.ename}
+
+
+ ,job=#{emp.job}
+
+
+ ,mgr=#{emp.mgr}
+
+
+ ,hiredate=#{emp.hiredate}
+
+
+ ,sal=#{emp.sal}
+
+
+ ,comn=#{emp.comn}
+
+
+ ,deptno=#{emp.deptno}
+
+
+ where empno = #{emp.empno}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mybaits_02/src/main/resources/com/msb/mapper/ProjectMapper.xml b/mybaits_02/src/main/resources/com/msb/mapper/ProjectMapper.xml
new file mode 100644
index 0000000..e822210
--- /dev/null
+++ b/mybaits_02/src/main/resources/com/msb/mapper/ProjectMapper.xml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mybaits_02/src/main/resources/jdbc.properties b/mybaits_02/src/main/resources/jdbc.properties
new file mode 100644
index 0000000..7efc6bf
--- /dev/null
+++ b/mybaits_02/src/main/resources/jdbc.properties
@@ -0,0 +1,4 @@
+jdbc_driver=com.mysql.cj.jdbc.Driver
+jdbc_url=jdbc:mysql://localhost:3306/mydb?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
+jdbc_username=root
+jdbc_password=12345678
\ No newline at end of file
diff --git a/mybaits_02/src/main/resources/log4j.properties b/mybaits_02/src/main/resources/log4j.properties
new file mode 100644
index 0000000..964d98e
--- /dev/null
+++ b/mybaits_02/src/main/resources/log4j.properties
@@ -0,0 +1,11 @@
+# debug
+log4j.rootLogger=debug,stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.err
+log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
+
+log4j.appender.logfile=org.apache.log4j.FileAppender
+log4j.appender.logfile.File=d:/msb.log
+log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
+log4j.appender.logfile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %l %F %p %m%n
\ No newline at end of file
diff --git a/mybaits_02/src/main/resources/mybatis-config.xml b/mybaits_02/src/main/resources/mybatis-config.xml
new file mode 100644
index 0000000..bbbfbc9
--- /dev/null
+++ b/mybaits_02/src/main/resources/mybatis-config.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mybaits_02/src/test/java/com/msb/test/TestDept.java b/mybaits_02/src/test/java/com/msb/test/TestDept.java
new file mode 100644
index 0000000..a5dbbfb
--- /dev/null
+++ b/mybaits_02/src/test/java/com/msb/test/TestDept.java
@@ -0,0 +1,57 @@
+package com.msb.test;
+
+import com.msb.mapper.DeptMapper;
+import com.msb.mapper.EmpMapper;
+import com.msb.pojo.Dept;
+import com.msb.pojo.Emp;
+import org.apache.ibatis.io.Resources;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+public class TestDept {
+
+ private SqlSession sqlSession;
+
+ @Before
+ public void init() throws IOException {
+ SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
+ InputStream resource = Resources.getResourceAsStream("mybatis-config.xml");
+ SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(resource);
+ sqlSession = sqlSessionFactory.openSession();
+ }
+
+ @Test
+ public void testAddDept(){
+ DeptMapper deptMapper = sqlSession.getMapper(DeptMapper.class);
+ Dept dept = new Dept(null, "JAVA架构班", "深圳", null);
+ int rows = deptMapper.addDept(dept);
+ sqlSession.commit();
+ System.out.println(rows);
+ System.out.println(dept);
+ }
+ @Test
+ public void testFindDeptJoinEmpByDeptno(){
+ DeptMapper deptMapper = sqlSession.getMapper(DeptMapper.class);
+ Dept dept = deptMapper.findDeptJoinEmpByDeptno(20);
+ List empList = dept.getEmpList();
+ System.out.println(dept.getDeptno());
+ System.out.println(dept.getDname());
+ System.out.println(dept.getLoc());
+ empList.forEach(System.out::println);
+ }
+
+
+ @After
+ public void release(){
+ sqlSession.close();
+ }
+
+}
diff --git a/mybaits_02/src/test/java/com/msb/test/TestEmp.java b/mybaits_02/src/test/java/com/msb/test/TestEmp.java
new file mode 100644
index 0000000..e82ff14
--- /dev/null
+++ b/mybaits_02/src/test/java/com/msb/test/TestEmp.java
@@ -0,0 +1,136 @@
+package com.msb.test;
+
+import com.msb.mapper.EmpMapper;
+import com.msb.pojo.Emp;
+import org.apache.ibatis.io.Resources;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.*;
+
+public class TestEmp {
+
+ private SqlSession sqlSession;
+
+ @Before
+ public void init() throws IOException {
+ SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
+ InputStream resource = Resources.getResourceAsStream("mybatis-config.xml");
+ SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(resource);
+ sqlSession = sqlSessionFactory.openSession(true);
+ }
+
+ @Test
+ public void testFindAll(){
+ EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
+ List empList = empMapper.findAll();
+ empList.forEach(System.out::println);
+ }
+ @Test
+ public void testFindEmpByNo(){
+ EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
+ Emp emp = empMapper.findEmpByNo(7936);
+ System.out.println(emp);
+ }
+
+ @Test
+ public void testFindEmpByEmpnoAndSal(){
+ EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
+ List empList = empMapper.findEmpByEmpnoAndSal(20, 3000.0);
+ empList.forEach(System.out::println);
+ }
+
+ @Test
+ public void testFindEmpByEmpnoAndSal2(){
+ EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
+ Emp emp = new Emp();
+ emp.setDeptno(20);
+ emp.setSal(3000.0);
+ List empList = empMapper.findEmpByEmpnoAndSal2(emp);
+ empList.forEach(System.out::println);
+ }
+
+ @Test
+ public void testFindByName(){
+ EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
+ List empList = empMapper.findByName("A");
+ empList.forEach(System.out::println);
+ }
+
+ @Test
+ public void testAddEmp(){
+ EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
+ Emp emp = new Emp(null, "小明", "java", 7833, new Date(), 18000.0, 2000.0, 20, null);
+ int row = empMapper.addEmp(emp);
+ System.out.println(row);
+ System.out.println(emp);
+ }
+
+ @Test
+ public void testUpdateNameByNo(){
+ EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
+ int row = empMapper.updateNameByNo(7936, "小黑");
+ System.out.println(row);
+ }
+ @Test
+ public void testDeleteByEmpno(){
+ EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
+ int row = empMapper.deleteByEmpno(7936);
+ System.out.println(row);
+ }
+
+ @Test
+ public void testFindByCondition(){
+ EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
+ Emp emp = new Emp();
+ emp.setDeptno(20);
+ emp.setEname("A");
+ List empList = empMapper.findByCondition(emp);
+ for(Emp empItem : empList){
+ System.out.println(empItem);
+ }
+ }
+ @Test
+ public void testUpdateEmpByCondition(){
+ EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
+ Emp emp = new Emp();
+ emp.setEmpno(7939);
+ emp.setDeptno(20);
+ emp.setEname("A");
+ int rows = empMapper.updateEmpByCondition(emp);
+ System.out.println(rows);
+ }
+ @Test
+ public void testFindByEmpnosArr(){
+ EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
+ int[] empnos = {7902, 7934, 7939};
+ List empList = empMapper.findByEmpnosArr(empnos);
+ empList.forEach(System.out::println);
+ }
+ @Test
+ public void testFindByEmpnosList(){
+ EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
+ List empnos = new ArrayList<>();
+ Collections.addAll(empnos, 7902, 7934, 7939);
+ List empList = empMapper.findByEmpnosList(empnos);
+ empList.forEach(System.out::println);
+ }
+ @Test
+ public void testFindEmpJoinDeptByEmpno(){
+ EmpMapper empMapper = sqlSession.getMapper(EmpMapper.class);
+ Emp emp = empMapper.findEmpJoinDeptByEmpno(7934);
+ System.out.println(emp);
+ }
+
+ @After
+ public void release(){
+ sqlSession.close();
+ }
+
+}
diff --git a/mybaits_02/src/test/java/com/msb/test/TestProject.java b/mybaits_02/src/test/java/com/msb/test/TestProject.java
new file mode 100644
index 0000000..f7b6fdf
--- /dev/null
+++ b/mybaits_02/src/test/java/com/msb/test/TestProject.java
@@ -0,0 +1,50 @@
+package com.msb.test;
+
+import com.msb.mapper.DeptMapper;
+import com.msb.mapper.ProjectMapper;
+import com.msb.pojo.Dept;
+import com.msb.pojo.Emp;
+import com.msb.pojo.Project;
+import com.msb.pojo.ProjectRecord;
+import org.apache.ibatis.io.Resources;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+public class TestProject {
+
+ private SqlSession sqlSession;
+
+ @Before
+ public void init() throws IOException {
+ SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
+ InputStream resource = Resources.getResourceAsStream("mybatis-config.xml");
+ SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(resource);
+ sqlSession = sqlSessionFactory.openSession();
+ }
+ @Test
+ public void testFindDeptJoinEmpByDeptno(){
+ ProjectMapper projectMapper = sqlSession.getMapper(ProjectMapper.class);
+ Project project = projectMapper.findProjectJoinEmpsByPid(2);
+ System.out.println(project.getPid());
+ System.out.println(project.getPname());
+ System.out.println(project.getMoney());
+ List projectRecordList = project.getProjectRecordList();
+ projectRecordList.forEach(System.out::println);
+
+ }
+
+
+ @After
+ public void release(){
+ sqlSession.close();
+ }
+
+}
diff --git a/mybatis_01/.gitignore b/mybatis_01/.gitignore
new file mode 100644
index 0000000..5ff6309
--- /dev/null
+++ b/mybatis_01/.gitignore
@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
\ No newline at end of file
diff --git a/mybatis_01/pom.xml b/mybatis_01/pom.xml
new file mode 100644
index 0000000..8b6f262
--- /dev/null
+++ b/mybatis_01/pom.xml
@@ -0,0 +1,48 @@
+
+
+ 4.0.0
+
+ com.msb.springmvc
+ mybatis_01
+ 1.0-SNAPSHOT
+
+
+
+ mysql
+ mysql-connector-java
+ 8.0.16
+
+
+
+ org.mybatis
+ mybatis
+ 3.5.3
+
+
+
+ junit
+ junit
+ 4.13.1
+ test
+
+
+
+ org.projectlombok
+ lombok
+ 1.18.12
+ provided
+
+
+
+
+ log4j
+ log4j
+ 1.2.17
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mybatis_01/src/main/java/com/msb/pojo/Dept.java b/mybatis_01/src/main/java/com/msb/pojo/Dept.java
new file mode 100644
index 0000000..42adf2d
--- /dev/null
+++ b/mybatis_01/src/main/java/com/msb/pojo/Dept.java
@@ -0,0 +1,14 @@
+package com.msb.pojo;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class Dept {
+ private Integer deptno;
+ private String dname;
+ private String loc;
+}
diff --git a/mybatis_01/src/main/java/com/msb/pojo/Emp.java b/mybatis_01/src/main/java/com/msb/pojo/Emp.java
new file mode 100644
index 0000000..3fac0e5
--- /dev/null
+++ b/mybatis_01/src/main/java/com/msb/pojo/Emp.java
@@ -0,0 +1,23 @@
+package com.msb.pojo;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.Date;
+
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class Emp {
+ private Integer empno;
+ private String ename;
+ private String job;
+ private Integer mgr;
+ private Date hiredate;
+ private Double sal;
+ private Double comn;
+ private Integer deptno;
+
+}
diff --git a/mybatis_01/src/main/resources/com/msb/mapper/DeptMapper.xml b/mybatis_01/src/main/resources/com/msb/mapper/DeptMapper.xml
new file mode 100644
index 0000000..021dbaf
--- /dev/null
+++ b/mybatis_01/src/main/resources/com/msb/mapper/DeptMapper.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/mybatis_01/src/main/resources/com/msb/mapper/DmlEmpMapper.xml b/mybatis_01/src/main/resources/com/msb/mapper/DmlEmpMapper.xml
new file mode 100644
index 0000000..3b02d68
--- /dev/null
+++ b/mybatis_01/src/main/resources/com/msb/mapper/DmlEmpMapper.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+ insert into emp values (DEFAULT, #{ename}, #{job}, #{mgr}, #{hiredate}, #{sal}, #{comn}, #{deptno});
+
+
+
+
+ update emp set ename = #{ename} where empno = #{empno}
+
+
+
+
+ delete from emp where empno=#{empno}
+
+
+
\ No newline at end of file
diff --git a/mybatis_01/src/main/resources/com/msb/mapper/EmpMapper.xml b/mybatis_01/src/main/resources/com/msb/mapper/EmpMapper.xml
new file mode 100644
index 0000000..6499f4f
--- /dev/null
+++ b/mybatis_01/src/main/resources/com/msb/mapper/EmpMapper.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mybatis_01/src/main/resources/com/msb/mapper/ParamEmpMapper.xml b/mybatis_01/src/main/resources/com/msb/mapper/ParamEmpMapper.xml
new file mode 100644
index 0000000..74d62b2
--- /dev/null
+++ b/mybatis_01/src/main/resources/com/msb/mapper/ParamEmpMapper.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mybatis_01/src/main/resources/jdbc.properties b/mybatis_01/src/main/resources/jdbc.properties
new file mode 100644
index 0000000..7efc6bf
--- /dev/null
+++ b/mybatis_01/src/main/resources/jdbc.properties
@@ -0,0 +1,4 @@
+jdbc_driver=com.mysql.cj.jdbc.Driver
+jdbc_url=jdbc:mysql://localhost:3306/mydb?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
+jdbc_username=root
+jdbc_password=12345678
\ No newline at end of file
diff --git a/mybatis_01/src/main/resources/log4j.properties b/mybatis_01/src/main/resources/log4j.properties
new file mode 100644
index 0000000..964d98e
--- /dev/null
+++ b/mybatis_01/src/main/resources/log4j.properties
@@ -0,0 +1,11 @@
+# debug
+log4j.rootLogger=debug,stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.err
+log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
+
+log4j.appender.logfile=org.apache.log4j.FileAppender
+log4j.appender.logfile.File=d:/msb.log
+log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
+log4j.appender.logfile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %l %F %p %m%n
\ No newline at end of file
diff --git a/mybatis_01/src/main/resources/mybatis-config.xml b/mybatis_01/src/main/resources/mybatis-config.xml
new file mode 100644
index 0000000..3006107
--- /dev/null
+++ b/mybatis_01/src/main/resources/mybatis-config.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mybatis_01/src/test/java/com/msb/test/DemoTest.java b/mybatis_01/src/test/java/com/msb/test/DemoTest.java
new file mode 100644
index 0000000..407a38b
--- /dev/null
+++ b/mybatis_01/src/test/java/com/msb/test/DemoTest.java
@@ -0,0 +1,41 @@
+package com.msb.test;
+
+import com.msb.pojo.Dept;
+import org.apache.ibatis.io.Resources;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+public class DemoTest {
+
+ private SqlSession sqlSession;
+
+ @Before
+ public void init() throws IOException {
+ SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
+ InputStream stream = Resources.getResourceAsStream("mybatis-config.xml");
+ SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(stream);
+ sqlSession = sqlSessionFactory.openSession();
+ }
+
+
+ @Test
+ public void testDeptFindAll(){
+ List deptList = sqlSession.selectList("findAll");
+ for (Dept dept: deptList) {
+ System.out.println(dept);
+ }
+ }
+
+ @After
+ public void release(){
+ sqlSession.close();
+ }
+}
diff --git a/mybatis_01/src/test/java/com/msb/test/DmlEmpTest.java b/mybatis_01/src/test/java/com/msb/test/DmlEmpTest.java
new file mode 100644
index 0000000..9fef7df
--- /dev/null
+++ b/mybatis_01/src/test/java/com/msb/test/DmlEmpTest.java
@@ -0,0 +1,63 @@
+package com.msb.test;
+
+import com.msb.pojo.Emp;
+import org.apache.ibatis.io.Resources;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class DmlEmpTest {
+
+ private SqlSession sqlSession;
+
+ @Before
+ public void init() throws IOException {
+ SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
+ InputStream stream = Resources.getResourceAsStream("mybatis-config.xml");
+ SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(stream);
+ sqlSession = sqlSessionFactory.openSession(true);
+ }
+
+
+ @Test
+ public void testAddEmp() {
+ // insert方法
+ Emp emp = new Emp(null, "demo", "java", 7899, new Date(), 20000.0, 1000.0, 20);
+ int rows = sqlSession.insert("addEmp", emp);
+ System.out.println(rows);
+
+ // sqlSession 在增删改操作的时候默认开启事务处理,如果没有手动提交事务,会自动回滚事务
+// sqlSession.commit(); // 手动提交事务
+ // 也可以设置自动提交事务操作
+ // sqlSession = sqlSessionFactory.openSession(true);
+ }
+
+ @Test
+ public void testUpdateEmpName(){
+ Emp emp = new Emp();
+ emp.setEmpno(7937);
+ emp.setEname("了不起的Java");
+ int row = sqlSession.update("updateEmpName", emp);
+ System.out.println(row);
+ }
+ @Test
+ public void testDeleteByEmpno(){
+ int row = sqlSession.delete("deleteByEmpno", 7937);
+ System.out.println(row);
+ }
+
+ @After
+ public void release(){
+ sqlSession.close();
+ }
+}
diff --git a/mybatis_01/src/test/java/com/msb/test/EmpTest.java b/mybatis_01/src/test/java/com/msb/test/EmpTest.java
new file mode 100644
index 0000000..3f3a505
--- /dev/null
+++ b/mybatis_01/src/test/java/com/msb/test/EmpTest.java
@@ -0,0 +1,60 @@
+package com.msb.test;
+
+import com.msb.pojo.Dept;
+import com.msb.pojo.Emp;
+import org.apache.ibatis.io.Resources;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class EmpTest {
+
+ private SqlSession sqlSession;
+
+ @Before
+ public void init() throws IOException {
+ SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
+ InputStream stream = Resources.getResourceAsStream("mybatis-config.xml");
+ SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(stream);
+ sqlSession = sqlSessionFactory.openSession();
+ }
+
+
+ @Test
+ public void testFindAll() {
+ // selectList
+ List empList = sqlSession.selectList("EmpMapper.findAll");
+ empList.forEach(System.out::println);
+ }
+
+ @Test
+ public void testFindOne() {
+ // selectOne
+ Emp emp = sqlSession.selectOne("EmpMapper.findOne");
+ System.out.println(emp);
+ }
+
+ @Test
+ public void testFindEmpMap() {
+ // selectMap
+ Map empMap = sqlSession.selectMap("findEmpMap", "EMPNO");
+ Set keys = empMap.keySet();
+ for(Integer key: keys){
+ System.out.println( key+ " :" +empMap.get(key));
+ }
+ }
+
+ @After
+ public void release(){
+ sqlSession.close();
+ }
+}
diff --git a/mybatis_01/src/test/java/com/msb/test/ParamEmpTest.java b/mybatis_01/src/test/java/com/msb/test/ParamEmpTest.java
new file mode 100644
index 0000000..bcd0603
--- /dev/null
+++ b/mybatis_01/src/test/java/com/msb/test/ParamEmpTest.java
@@ -0,0 +1,62 @@
+package com.msb.test;
+
+import com.msb.pojo.Emp;
+import org.apache.ibatis.io.Resources;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class ParamEmpTest {
+
+ private SqlSession sqlSession;
+
+ @Before
+ public void init() throws IOException {
+ SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
+ InputStream stream = Resources.getResourceAsStream("mybatis-config.xml");
+ SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(stream);
+ sqlSession = sqlSessionFactory.openSession();
+ }
+
+
+ @Test
+ public void testFindEmpByNo() {
+ // selectOne, 传入参数的方式
+ Emp emp = sqlSession.selectOne("findEmpByNo", 7369);
+ System.out.println(emp);
+ }
+ @Test
+ public void testFindEmpByDeptnoAndSal() {
+ // 多个参数传递,使用map传递的方式
+ Map args = new HashMap<>();
+ args.put("deptno", 20);
+ args.put("sal", 2000.0);
+
+ List empList = sqlSession.selectList("findEmpByDeptnoAndSal", args);
+ empList.forEach(System.out::println);
+ }
+ @Test
+ public void testFindEmpByObj() {
+ // 多个参数,使用实体对象传递
+ Emp emp = new Emp();
+ emp.setDeptno(20);
+ emp.setSal(2000.0);
+ List empList = sqlSession.selectList("findEmpByObj", emp);
+ empList.forEach(System.out::println);
+ }
+
+ @After
+ public void release(){
+ sqlSession.close();
+ }
+}