From b5257720e01c66585b4b6e42a30a5dc8265314b9 Mon Sep 17 00:00:00 2001 From: F_X_Zhe <295363299@qq.com> Date: Fri, 31 May 2024 20:07:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86ddl=E5=B9=B6?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E4=BA=86=E6=95=B0=E6=8D=AE=EF=BC=8C=E5=B7=B2?= =?UTF-8?q?=E7=BB=8F=E5=8F=AF=E4=BB=A5=E8=BF=9B=E8=A1=8C=E5=A2=9E=E5=88=A0?= =?UTF-8?q?=E6=94=B9=E6=9F=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/database/MultiRelationsInsert.sql | 32 +++++++++++++++++++ code/database/ddl.sql | 6 ++-- .../dao/{IDrugDao.java => IDataDao.java} | 5 ++- .../main/java/com/keafmd/dao/IUserDao.java | 8 ----- .../main/java/com/keafmd/domain/Drugs.java | 29 +++++++++++++++++ .../resources/com/keafmd/dao/IDataDao.xml | 12 ++++++- .../resources/com/keafmd/dao/IUserDao.xml | 16 ---------- .../java/com/keafmd/test/MybatisTest.java | 15 ++++++--- 8 files changed, 89 insertions(+), 34 deletions(-) create mode 100644 code/database/MultiRelationsInsert.sql rename code/server/src/main/java/com/keafmd/dao/{IDrugDao.java => IDataDao.java} (56%) delete mode 100644 code/server/src/main/java/com/keafmd/dao/IUserDao.java delete mode 100644 code/server/src/main/resources/com/keafmd/dao/IUserDao.xml diff --git a/code/database/MultiRelationsInsert.sql b/code/database/MultiRelationsInsert.sql new file mode 100644 index 0000000..58a8bff --- /dev/null +++ b/code/database/MultiRelationsInsert.sql @@ -0,0 +1,32 @@ +delete from T_Drugs; + +insert into T_Drugs values('10001','0.9%ȻעҺ',800); +insert into T_Drugs values('10002','10%עҺ',1600); +insert into T_Drugs values('10003','25%עҺ',500); +insert into T_Drugs values('10004','50%עҺ',1250); +insert into T_Drugs values('10005','ױעҺ',323); +insert into T_Drugs values('10006','άڷҺ',155); +insert into T_Drugs values('10007','Ⱥϼ(ϼ)',697); +insert into T_Drugs values('10008','ϴϣģ',52); +insert into T_Drugs values('10009','ƬƬ',168); +insert into T_Drugs values('10010','̼ڿ',985); +insert into T_Drugs values('10011','ͪעҺ(ע)',211); +insert into T_Drugs values('10012','ά˨(˨)',129); +insert into T_Drugs values('10013','հעҺ',681); +insert into T_Drugs values('10014','()',52); +insert into T_Drugs values('10015','׽',36); +insert into T_Drugs values('10016','̩ң)',89); +insert into T_Drugs values('10017','п',67); +insert into T_Drugs values('10018','࿨עҺ',225); +insert into T_Drugs values('10019','ȻעҺ',569); +insert into T_Drugs values('10020','׷˾ͪ',44); +insert into T_Drugs values('10021','ͪȲƴƬ',49); +insert into T_Drugs values('10022','ָעҺ',113); +insert into T_Drugs values('10023','ɳ߹עҺ',253); +insert into T_Drugs values('10024','˫˾ƬƬ',55); +insert into T_Drugs values('10025','άADμ',169); +insert into T_Drugs values('10026','άB1',32); +insert into T_Drugs values('10027','άB6',87); +insert into T_Drugs values('10028','ᰱҺ',12); +insert into T_Drugs values('10029','߻̫-ù˨',31); +insert into T_Drugs values('10030','ע',462); diff --git a/code/database/ddl.sql b/code/database/ddl.sql index af9250a..10b7574 100644 --- a/code/database/ddl.sql +++ b/code/database/ddl.sql @@ -1,7 +1,7 @@ create table T_Drugs( ID varchar(5), - name varchar(20), - num numeric(3,0), + name varchar(64), + num numeric(5,0), primary key (ID)); @@ -13,7 +13,7 @@ create table T_Norms( create table T_Vendor( ID varchar(5), - name varchar(20), + name varchar(64), address varchar(64), phonenumber varchar(11), monitor varchar(5), diff --git a/code/server/src/main/java/com/keafmd/dao/IDrugDao.java b/code/server/src/main/java/com/keafmd/dao/IDataDao.java similarity index 56% rename from code/server/src/main/java/com/keafmd/dao/IDrugDao.java rename to code/server/src/main/java/com/keafmd/dao/IDataDao.java index 9b3190f..c40d3ad 100644 --- a/code/server/src/main/java/com/keafmd/dao/IDrugDao.java +++ b/code/server/src/main/java/com/keafmd/dao/IDataDao.java @@ -1,8 +1,11 @@ package com.keafmd.dao; import com.keafmd.domain.Drugs; +import com.keafmd.domain.User; import java.util.List; -public interface IDrugDao { +public interface IDataDao { + List find_User(); + List find_drugs(); } diff --git a/code/server/src/main/java/com/keafmd/dao/IUserDao.java b/code/server/src/main/java/com/keafmd/dao/IUserDao.java deleted file mode 100644 index 8dc0dc0..0000000 --- a/code/server/src/main/java/com/keafmd/dao/IUserDao.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.keafmd.dao; - -import com.keafmd.domain.User; -import java.util.List; - -public interface IUserDao { - List find_User(); -} diff --git a/code/server/src/main/java/com/keafmd/domain/Drugs.java b/code/server/src/main/java/com/keafmd/domain/Drugs.java index ea56620..a6cc333 100644 --- a/code/server/src/main/java/com/keafmd/domain/Drugs.java +++ b/code/server/src/main/java/com/keafmd/domain/Drugs.java @@ -1,4 +1,33 @@ package com.keafmd.domain; public class Drugs { + private Integer ID; + private String name; + private Integer num; + + public Integer getID() { + return ID; + } + public void setID(Integer ID) { + this.ID = ID; + } + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + public Integer getNum() { + return num; + } + public void setNum(Integer num) { + this.num = num; + } + + @Override + public String toString() { + return "Drugs:{ID=" + ID + ", name=" + name + ", num=" + num + "}"; + } } diff --git a/code/server/src/main/resources/com/keafmd/dao/IDataDao.xml b/code/server/src/main/resources/com/keafmd/dao/IDataDao.xml index a40be2a..792b7f4 100644 --- a/code/server/src/main/resources/com/keafmd/dao/IDataDao.xml +++ b/code/server/src/main/resources/com/keafmd/dao/IDataDao.xml @@ -2,7 +2,7 @@ - + + + diff --git a/code/server/src/main/resources/com/keafmd/dao/IUserDao.xml b/code/server/src/main/resources/com/keafmd/dao/IUserDao.xml deleted file mode 100644 index 2e5c84f..0000000 --- a/code/server/src/main/resources/com/keafmd/dao/IUserDao.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - diff --git a/code/server/src/test/java/com/keafmd/test/MybatisTest.java b/code/server/src/test/java/com/keafmd/test/MybatisTest.java index 3c21769..f84edb6 100644 --- a/code/server/src/test/java/com/keafmd/test/MybatisTest.java +++ b/code/server/src/test/java/com/keafmd/test/MybatisTest.java @@ -1,7 +1,7 @@ package com.keafmd.test; -import com.keafmd.dao.IUserDao; -import com.keafmd.domain.User; +import com.keafmd.dao.IDataDao; +import com.keafmd.domain.Drugs; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; @@ -22,11 +22,16 @@ public class MybatisTest { //3.使用工厂生产SqlSession对象 SqlSession session = factory.openSession(); //4.使用SqlSession创建Dao接口的代理对象 - IUserDao userDao = session.getMapper(IUserDao.class); + /*IUserDao userDao = session.getMapper(IUserDao.class); //5.使用代理对象执行方法 - List users = Collections.unmodifiableList(userDao.find_User()); - for (User user : users) { + List users = Collections.unmodifiableList(userDao.find_User());*/ + IDataDao drugDao = session.getMapper(IDataDao.class); + List drugs = Collections.unmodifiableList(drugDao.find_drugs()); + /*for (User user : users) { System.out.println(user); + }*/ + for (Drugs d : drugs) { + System.out.println(d); } //6.释放资源 session.close();