From 1f710543bc270d41a96a3e71f3475df532252b5b Mon Sep 17 00:00:00 2001
From: zyx <1029606625@qq.com>
Date: Fri, 19 May 2023 10:57:01 +0800
Subject: [PATCH] 5/19 10:56
---
.idea/compiler.xml | 1 +
.idea/encodings.xml | 2 +
.idea/misc.xml | 1 +
mybatis519/pom.xml | 51 +++++++++
.../main/java/cn/czyx007/bean/Computers.java | 51 +++++++++
.../cn/czyx007/mapper/ComputersMapper.java | 46 ++++++++
.../java/cn/czyx007/utils/SqlSessionUtil.java | 32 ++++++
.../cn/czyx007/mapper/ComputersMapper.xml | 101 ++++++++++++++++++
mybatis519/src/main/resources/jdbc.properties | 4 +
mybatis519/src/main/resources/log4j.xml | 21 ++++
.../src/main/resources/mybatis-config.xml | 50 +++++++++
mybatis519/src/test/java/TestComputers.java | 43 ++++++++
mybatis519/src/test/java/TestWife.java | 15 +++
13 files changed, 418 insertions(+)
create mode 100644 mybatis519/pom.xml
create mode 100644 mybatis519/src/main/java/cn/czyx007/bean/Computers.java
create mode 100644 mybatis519/src/main/java/cn/czyx007/mapper/ComputersMapper.java
create mode 100644 mybatis519/src/main/java/cn/czyx007/utils/SqlSessionUtil.java
create mode 100644 mybatis519/src/main/resources/cn/czyx007/mapper/ComputersMapper.xml
create mode 100644 mybatis519/src/main/resources/jdbc.properties
create mode 100644 mybatis519/src/main/resources/log4j.xml
create mode 100644 mybatis519/src/main/resources/mybatis-config.xml
create mode 100644 mybatis519/src/test/java/TestComputers.java
create mode 100644 mybatis519/src/test/java/TestWife.java
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index d9d6f1e..2c035a1 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -11,6 +11,7 @@
+
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
index 4293575..b2c2558 100644
--- a/.idea/encodings.xml
+++ b/.idea/encodings.xml
@@ -9,5 +9,7 @@
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index e9735ca..fe581c9 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -12,6 +12,7 @@
+
diff --git a/mybatis519/pom.xml b/mybatis519/pom.xml
new file mode 100644
index 0000000..cf3b154
--- /dev/null
+++ b/mybatis519/pom.xml
@@ -0,0 +1,51 @@
+
+
+ 4.0.0
+
+ cn.czyx007
+ mybatis519
+ 1.0-SNAPSHOT
+
+
+ 11
+ 11
+ UTF-8
+
+
+
+
+ mysql
+ mysql-connector-java
+ 8.0.31
+ runtime
+
+
+ org.projectlombok
+ lombok
+ 1.18.20
+
+
+ org.mybatis
+ mybatis
+ 3.5.10
+
+
+ junit
+ junit
+ 4.13.2
+ test
+
+
+ log4j
+ log4j
+ 1.2.17
+
+
+ com.github.pagehelper
+ pagehelper
+ 5.2.0
+
+
+
\ No newline at end of file
diff --git a/mybatis519/src/main/java/cn/czyx007/bean/Computers.java b/mybatis519/src/main/java/cn/czyx007/bean/Computers.java
new file mode 100644
index 0000000..e95bc9c
--- /dev/null
+++ b/mybatis519/src/main/java/cn/czyx007/bean/Computers.java
@@ -0,0 +1,51 @@
+package cn.czyx007.bean;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+/**
+ * (Computers)实体类
+ *
+ * @author 张宇轩
+ * @since 2023-05-18 14:50:06
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class Computers implements Serializable {
+ private static final long serialVersionUID = 943332959360147693L;
+ /**
+ * 主键
+ */
+ private Long id;
+ /**
+ * 名牌
+ */
+ private String brand;
+ /**
+ * 价格
+ */
+ private Float price;
+ /**
+ * 内存
+ */
+ private Float runmem;
+ /**
+ * cpu类型
+ */
+ private String cpu;
+ /**
+ * 显卡
+ */
+ private Float xianka;
+ /**
+ * 1 显示 0隐藏
+ */
+ private String status;
+
+ private Float startPrice;
+ private Float endPrice;
+}
diff --git a/mybatis519/src/main/java/cn/czyx007/mapper/ComputersMapper.java b/mybatis519/src/main/java/cn/czyx007/mapper/ComputersMapper.java
new file mode 100644
index 0000000..10bb7e8
--- /dev/null
+++ b/mybatis519/src/main/java/cn/czyx007/mapper/ComputersMapper.java
@@ -0,0 +1,46 @@
+package cn.czyx007.mapper;
+
+import cn.czyx007.bean.Computers;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+
+/**
+ * @author : 张宇轩
+ * @createTime : 2023/5/18 - 14:55
+ */
+public interface ComputersMapper {
+ List getComputers();
+
+ @Select("")
+ List queryByConditionIf(Computers computers);
+
+ int updateByConditionSet(Computers computers);
+ List queryByConditionChoose(Computers computers);
+ List queryByConditionTrim(Computers computers);
+ int updateByConditionTrim(Computers computers);
+
+ List queryByForEach(long[] ids);
+}
\ No newline at end of file
diff --git a/mybatis519/src/main/java/cn/czyx007/utils/SqlSessionUtil.java b/mybatis519/src/main/java/cn/czyx007/utils/SqlSessionUtil.java
new file mode 100644
index 0000000..fdf0ccf
--- /dev/null
+++ b/mybatis519/src/main/java/cn/czyx007/utils/SqlSessionUtil.java
@@ -0,0 +1,32 @@
+package cn.czyx007.utils;
+
+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 java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * @author : 张宇轩
+ * @createTime : 2023/5/16 - 14:08
+ */
+public class SqlSessionUtil {
+ public static SqlSession getSqlSession(){
+ SqlSession sqlSession = null;
+ InputStream is;
+ try {
+ //1.获取核心配置文件的输入流
+ is = Resources.getResourceAsStream("mybatis-config.xml");
+ //2.获取SqlSessionFactoryBuilder对象
+ SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
+ //3.获取SqlSessionFactory对象
+ SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(is);
+ sqlSession = sqlSessionFactory.openSession(true);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return sqlSession;
+ }
+}
diff --git a/mybatis519/src/main/resources/cn/czyx007/mapper/ComputersMapper.xml b/mybatis519/src/main/resources/cn/czyx007/mapper/ComputersMapper.xml
new file mode 100644
index 0000000..57bcfb5
--- /dev/null
+++ b/mybatis519/src/main/resources/cn/czyx007/mapper/ComputersMapper.xml
@@ -0,0 +1,101 @@
+
+
+
+
+
+
+ update person_info.computers
+
+
+ price = #{price},
+
+
+ xianka = #{xianka}
+
+
+ where id = #{id}
+
+
+ update person_info.computers
+
+
+ price = #{price},
+
+
+ xianka = #{xianka}
+
+
+ where id = #{id}
+
+
+
+ id,brand,price,cpu,xianka
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mybatis519/src/main/resources/jdbc.properties b/mybatis519/src/main/resources/jdbc.properties
new file mode 100644
index 0000000..0058fcd
--- /dev/null
+++ b/mybatis519/src/main/resources/jdbc.properties
@@ -0,0 +1,4 @@
+jdbc.driver=com.mysql.cj.jdbc.Driver
+jdbc.url=jdbc:mysql://localhost:3306/person_info?serverTimezone=Asia/Shanghai
+jdbc.username=root
+jdbc.password=zyx007
\ No newline at end of file
diff --git a/mybatis519/src/main/resources/log4j.xml b/mybatis519/src/main/resources/log4j.xml
new file mode 100644
index 0000000..b19fad6
--- /dev/null
+++ b/mybatis519/src/main/resources/log4j.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mybatis519/src/main/resources/mybatis-config.xml b/mybatis519/src/main/resources/mybatis-config.xml
new file mode 100644
index 0000000..099aee1
--- /dev/null
+++ b/mybatis519/src/main/resources/mybatis-config.xml
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mybatis519/src/test/java/TestComputers.java b/mybatis519/src/test/java/TestComputers.java
new file mode 100644
index 0000000..39addcf
--- /dev/null
+++ b/mybatis519/src/test/java/TestComputers.java
@@ -0,0 +1,43 @@
+import cn.czyx007.bean.Brand;
+import cn.czyx007.bean.Computers;
+import cn.czyx007.mapper.BrandMapper;
+import cn.czyx007.mapper.ComputersMapper;
+import cn.czyx007.utils.SqlSessionUtil;
+import com.github.pagehelper.PageInfo;
+import org.junit.Test;
+
+import java.util.List;
+
+/**
+ * @author : 张宇轩
+ * @createTime : 2023/5/19 - 8:53
+ */
+public class TestComputers {
+ @Test
+ public void test1(){
+ ComputersMapper mapper = SqlSessionUtil.getSqlSession().getMapper(ComputersMapper.class);
+ mapper.queryByForEach(new long[]{1,2}).forEach(System.out::println);
+ }
+
+ @Test
+ public void test2(){
+ int pageNum=1;
+ int pageSize=3;
+ com.github.pagehelper.PageHelper.startPage(pageNum, pageSize);
+ BrandMapper brandMapper = SqlSessionUtil.getSqlSession().getMapper(BrandMapper.class);
+ List brandList = brandMapper.getBrandAll();
+ PageInfo pageInfo = new PageInfo<>(brandList);
+ System.out.println("总页数: " + pageInfo.getPages());
+ System.out.println("总条数: " + pageInfo.getTotal());
+ System.out.println("分页数据: " + pageInfo.getList());
+ }
+
+ @Test
+ public void testQueryByConditionIf(){
+ ComputersMapper mapper = SqlSessionUtil.getSqlSession().getMapper(ComputersMapper.class);
+ Computers computers = new Computers();
+ computers.setBrand("联想");
+ computers.setStartPrice(5000F);
+ mapper.queryByConditionIf(computers).forEach(System.out::println);
+ }
+}
diff --git a/mybatis519/src/test/java/TestWife.java b/mybatis519/src/test/java/TestWife.java
new file mode 100644
index 0000000..0f076b4
--- /dev/null
+++ b/mybatis519/src/test/java/TestWife.java
@@ -0,0 +1,15 @@
+import cn.czyx007.mapper.WifeMapper;
+import cn.czyx007.utils.SqlSessionUtil;
+import org.junit.Test;
+
+/**
+ * @author : 张宇轩
+ * @createTime : 2023/5/19 - 10:34
+ */
+public class TestWife {
+ @Test
+ public void test1(){
+ WifeMapper mapper = SqlSessionUtil.getSqlSession().getMapper(WifeMapper.class);
+ mapper.getWifeAll().forEach(System.out::println);
+ }
+}