From f33e3b6b080fbf4b01c2b7b4443823ea574d0717 Mon Sep 17 00:00:00 2001 From: F_X_Zhe <295363299@qq.com> Date: Sun, 26 May 2024 15:59:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E7=AB=AF=E5=9F=BA=E6=9C=AC=E6=A1=86?= =?UTF-8?q?=E6=9E=B6=EF=BC=88=E4=BB=A5=E5=A4=A7=E5=AD=A6=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E4=B8=BA=E4=BE=8B=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 38 ++++++ .idea/.gitignore | 8 ++ .idea/dataSources.xml | 18 +++ .idea/encodings.xml | 7 + .idea/misc.xml | 19 +++ .idea/sqldialects.xml | 7 + .idea/uiDesigner.xml | 124 ++++++++++++++++++ .idea/vcs.xml | 6 + pom.xml | 47 +++++++ src/main/java/com/keafmd/dao/IUserDao.java | 8 ++ src/main/java/com/keafmd/domain/User.java | 52 ++++++++ src/main/resources/SqlMapConfig.xml | 21 +++ .../resources/com/keafmd/dao/IUserDao.xml | 10 ++ src/main/resources/log4j.properties | 19 +++ .../java/com/keafmd/test/MybatisTest.java | 35 +++++ 15 files changed, 419 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/dataSources.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/sqldialects.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml create mode 100644 pom.xml create mode 100644 src/main/java/com/keafmd/dao/IUserDao.java create mode 100644 src/main/java/com/keafmd/domain/User.java create mode 100644 src/main/resources/SqlMapConfig.xml create mode 100644 src/main/resources/com/keafmd/dao/IUserDao.xml create mode 100644 src/main/resources/log4j.properties create mode 100644 src/test/java/com/keafmd/test/MybatisTest.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.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/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..7bd13a3 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,18 @@ + + + + + oracle.19 + true + false + oracle.jdbc.OracleDriver + jdbc:oracle:thin:@localhost:1521:orcl + + + + + + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e5b61dc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml new file mode 100644 index 0000000..691b6ca --- /dev/null +++ b/.idea/sqldialects.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..698791c --- /dev/null +++ b/pom.xml @@ -0,0 +1,47 @@ + + + + 4.0.0 + + org.example + example01 + 1.0-SNAPSHOT + + + 18 + 18 + UTF-8 + + + + + org.mybatis + mybatis + 3.5.2 + + + + com.oracle + ojdbc6 + 11.2.0.1.0 + + + + log4j + log4j + 1.2.17 + + + + + junit + junit + 4.12 + test + + + + + \ No newline at end of file diff --git a/src/main/java/com/keafmd/dao/IUserDao.java b/src/main/java/com/keafmd/dao/IUserDao.java new file mode 100644 index 0000000..bbc7482 --- /dev/null +++ b/src/main/java/com/keafmd/dao/IUserDao.java @@ -0,0 +1,8 @@ +package com.keafmd.dao; + +import com.keafmd.domain.User; +import java.util.List; + +public interface IUserDao { + List findAll(); +} diff --git a/src/main/java/com/keafmd/domain/User.java b/src/main/java/com/keafmd/domain/User.java new file mode 100644 index 0000000..33f8b97 --- /dev/null +++ b/src/main/java/com/keafmd/domain/User.java @@ -0,0 +1,52 @@ +package com.keafmd.domain; + +import java.util.Date; + +public class User { + private Integer id; + private String name; + private String dept_name; + private Float salary; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getUsername() { + return name; + } + + public void setUsername(String name) { + this.name = name; + } + + public String getDept_name() { + return dept_name; + } + + public void setDept_name(String dept_name) { + this.dept_name = dept_name; + } + + public Float getSalary() { + return salary; + } + + public void setSalary(Float salary) { + this.salary = salary; + } + + @Override + public String toString() { + return "User{" + + "id=" + id + + ", name='" + name + '\'' + + ", dept_name='" + dept_name + '\'' + + ", salary='" + salary + '\'' + + '}'; + } +} diff --git a/src/main/resources/SqlMapConfig.xml b/src/main/resources/SqlMapConfig.xml new file mode 100644 index 0000000..3e72ce6 --- /dev/null +++ b/src/main/resources/SqlMapConfig.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/com/keafmd/dao/IUserDao.xml b/src/main/resources/com/keafmd/dao/IUserDao.xml new file mode 100644 index 0000000..53341c5 --- /dev/null +++ b/src/main/resources/com/keafmd/dao/IUserDao.xml @@ -0,0 +1,10 @@ + + + + + + diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties new file mode 100644 index 0000000..138c037 --- /dev/null +++ b/src/main/resources/log4j.properties @@ -0,0 +1,19 @@ +# Set root category priority to INFO and its only appender to CONSOLE. +#log4j.rootCategory=INFO, CONSOLE debug info warn error fatal +log4j.rootCategory=debug, CONSOLE, LOGFILE + +# Set the enterprise logger category to FATAL and its only appender to CONSOLE. +log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE + +# CONSOLE is set to be a ConsoleAppender using a PatternLayout. +log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender +log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m\n + +# LOGFILE is set to be a File appender using a PatternLayout. +log4j.appender.LOGFILE=org.apache.log4j.FileAppender +log4j.appender.LOGFILE.File=d:\axis.log +log4j.appender.LOGFILE.Append=true +log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout +log4j.appender.LOGFILE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m\n + diff --git a/src/test/java/com/keafmd/test/MybatisTest.java b/src/test/java/com/keafmd/test/MybatisTest.java new file mode 100644 index 0000000..8deb44f --- /dev/null +++ b/src/test/java/com/keafmd/test/MybatisTest.java @@ -0,0 +1,35 @@ +package com.keafmd.test; + +import com.keafmd.dao.IUserDao; +import com.keafmd.domain.User; +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.InputStream; +import java.util.Collections; +import java.util.List; + +public class MybatisTest { + + public static void main(String[] args) throws Exception{ + //1.读取配置文件 + InputStream in = Resources.getResourceAsStream("SqlMapConfig.xml"); + //2.创建SqlSessionFactory工厂 + SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder(); + SqlSessionFactory factory = builder.build(in); + //3.使用工厂生产SqlSession对象 + SqlSession session = factory.openSession(); + //4.使用SqlSession创建Dao接口的代理对象 + IUserDao userDao = session.getMapper(IUserDao.class); + //5.使用代理对象执行方法 + List users = Collections.unmodifiableList(userDao.findAll()); + for (User user : users) { + System.out.println(user); + } + //6.释放资源 + session.close(); + in.close(); + } +}