From d7c566794e445e7c8b0f4da107af84a6e86a7830 Mon Sep 17 00:00:00 2001 From: lucashu <6125220@qq.com> Date: Thu, 12 Sep 2024 14:31:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E8=AF=BE=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- springboot1/pom.xml | 29 ++++++++++++---- .../hnucm/springboot/springboot1/Main.java | 33 ++++++++++++++++++ .../springboot1/Springboot1Application.java | 2 ++ .../controller/PersonController.java | 14 ++++++-- .../springboot1/dao/IdcardMapper.java | 11 ++++++ .../springboot1/dao/OrderMapper.java | 12 +++++++ .../springboot1/dao/PersonIdcardMapper.java | 1 + .../springboot1/dao/ProducatMapper.java | 12 +++++++ .../springboot/springboot1/model/Order.java | 14 ++++++++ .../springboot/springboot1/model/Person.java | 4 +++ .../springboot/springboot1/model/Product.java | 10 ++++++ .../springboot1/service/PersonService.java | 2 +- .../service/impl/PersonServiceImpl.java | 21 ++++++++---- .../src/main/resources/application.properties | 4 +-- .../main/resources/mapper/IdcardMapper.xml | 18 ++++++++++ .../src/main/resources/mapper/OrderMapper.xml | 19 +++++++++++ .../resources/mapper/PersonIdcardMapper.xml | 23 ++++++++++++- .../main/resources/mapper/PersonMapper.xml | 10 +++--- .../main/resources/mapper/ProducatMapper.xml | 10 ++++++ .../main/resources/templates/addperson.html | 2 ++ .../main/resources/templates/personlist.html | 34 ++++++++++++++----- untitled/.idea/dataSources.xml | 19 +++++++++++ 22 files changed, 273 insertions(+), 31 deletions(-) create mode 100644 springboot1/src/main/java/com/hnucm/springboot/springboot1/Main.java create mode 100644 springboot1/src/main/java/com/hnucm/springboot/springboot1/dao/IdcardMapper.java create mode 100644 springboot1/src/main/java/com/hnucm/springboot/springboot1/dao/OrderMapper.java create mode 100644 springboot1/src/main/java/com/hnucm/springboot/springboot1/dao/ProducatMapper.java create mode 100644 springboot1/src/main/java/com/hnucm/springboot/springboot1/model/Order.java create mode 100644 springboot1/src/main/java/com/hnucm/springboot/springboot1/model/Product.java create mode 100644 springboot1/src/main/resources/mapper/IdcardMapper.xml create mode 100644 springboot1/src/main/resources/mapper/OrderMapper.xml create mode 100644 springboot1/src/main/resources/mapper/ProducatMapper.xml create mode 100644 untitled/.idea/dataSources.xml diff --git a/springboot1/pom.xml b/springboot1/pom.xml index d3f7b65..f7a1857 100644 --- a/springboot1/pom.xml +++ b/springboot1/pom.xml @@ -60,17 +60,34 @@ spring-boot-starter-test test - - - org.mybatis.spring.boot - mybatis-spring-boot-starter - 3.0.3 - + + + + + mysql mysql-connector-java 8.0.25 + + + com.baomidou + mybatis-plus-spring-boot3-starter + 3.5.7 + + + + com.baomidou + mybatis-plus-generator + 3.5.7 + + + org.freemarker + freemarker + 2.3.31 + + diff --git a/springboot1/src/main/java/com/hnucm/springboot/springboot1/Main.java b/springboot1/src/main/java/com/hnucm/springboot/springboot1/Main.java new file mode 100644 index 0000000..dcb4eeb --- /dev/null +++ b/springboot1/src/main/java/com/hnucm/springboot/springboot1/Main.java @@ -0,0 +1,33 @@ +package com.hnucm.springboot.springboot1; + +import com.baomidou.mybatisplus.generator.FastAutoGenerator; +import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine; + +import java.nio.file.Paths; + +public class Main { + public static void main(String[] args) { + FastAutoGenerator.create("jdbc:mysql://106.53.194.250:63306/mybatis2004712?serverTimezone=UTC" + , "2004712", + "@hnucm1254") + .globalConfig(builder -> builder + .author("张三") + .outputDir(Paths.get(System.getProperty("user.dir")) + "/src/main/java") + .commentDate("yyyy-MM-dd") + ) + .packageConfig(builder -> builder + .parent("com.hnucm.springboot.springboot1") + .entity("model") + .mapper("dao") + .service("service") + .serviceImpl("service.impl") + .xml("mapper.xml") + ) + .strategyConfig(builder -> builder + .entityBuilder() + .enableLombok() + ) + .templateEngine(new FreemarkerTemplateEngine()) + .execute(); + } +} diff --git a/springboot1/src/main/java/com/hnucm/springboot/springboot1/Springboot1Application.java b/springboot1/src/main/java/com/hnucm/springboot/springboot1/Springboot1Application.java index dff9cae..2348954 100644 --- a/springboot1/src/main/java/com/hnucm/springboot/springboot1/Springboot1Application.java +++ b/springboot1/src/main/java/com/hnucm/springboot/springboot1/Springboot1Application.java @@ -1,9 +1,11 @@ package com.hnucm.springboot.springboot1; +import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication +// @MapperScan("com.hnucm.springboot.springboot1.dao") public class Springboot1Application { public static void main(String[] args) { diff --git a/springboot1/src/main/java/com/hnucm/springboot/springboot1/controller/PersonController.java b/springboot1/src/main/java/com/hnucm/springboot/springboot1/controller/PersonController.java index e265756..09dbe79 100644 --- a/springboot1/src/main/java/com/hnucm/springboot/springboot1/controller/PersonController.java +++ b/springboot1/src/main/java/com/hnucm/springboot/springboot1/controller/PersonController.java @@ -1,5 +1,6 @@ package com.hnucm.springboot.springboot1.controller; +import com.hnucm.springboot.springboot1.model.IdCard; import com.hnucm.springboot.springboot1.model.Person; import com.hnucm.springboot.springboot1.service.PersonService; import org.springframework.beans.factory.annotation.Autowired; @@ -38,14 +39,21 @@ public class PersonController { } @RequestMapping("addperson") - public String addPerson(Person person){ + public String addPerson(String name,int age,String stuid,String classname){ + Person person=new Person(); + person.setAge(age); + person.setName(name); + IdCard idCard = new IdCard(); + idCard.setStuid(stuid); + idCard.setClassname(classname); + person.setIdCard(idCard); personService.addPerson(person); return "redirect:personlist"; } @RequestMapping("deleteperson") - public String deleteperson(int id){ - personService.deletePerson(id); + public String deleteperson(int id,int idcardid){ + personService.deletePerson(id,idcardid); return "redirect:personlist"; } diff --git a/springboot1/src/main/java/com/hnucm/springboot/springboot1/dao/IdcardMapper.java b/springboot1/src/main/java/com/hnucm/springboot/springboot1/dao/IdcardMapper.java new file mode 100644 index 0000000..4efd201 --- /dev/null +++ b/springboot1/src/main/java/com/hnucm/springboot/springboot1/dao/IdcardMapper.java @@ -0,0 +1,11 @@ +package com.hnucm.springboot.springboot1.dao; + +import com.hnucm.springboot.springboot1.model.IdCard; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface IdcardMapper { + public IdCard getIdcard(int id); + public int deleteIdcard(int id); + public int addIdcard(IdCard idcard); +} diff --git a/springboot1/src/main/java/com/hnucm/springboot/springboot1/dao/OrderMapper.java b/springboot1/src/main/java/com/hnucm/springboot/springboot1/dao/OrderMapper.java new file mode 100644 index 0000000..98193dd --- /dev/null +++ b/springboot1/src/main/java/com/hnucm/springboot/springboot1/dao/OrderMapper.java @@ -0,0 +1,12 @@ +package com.hnucm.springboot.springboot1.dao; + +import com.hnucm.springboot.springboot1.model.IdCard; +import com.hnucm.springboot.springboot1.model.Order; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface OrderMapper { + public List getOrderByUserId(int id); +} diff --git a/springboot1/src/main/java/com/hnucm/springboot/springboot1/dao/PersonIdcardMapper.java b/springboot1/src/main/java/com/hnucm/springboot/springboot1/dao/PersonIdcardMapper.java index 576af94..37ed85e 100644 --- a/springboot1/src/main/java/com/hnucm/springboot/springboot1/dao/PersonIdcardMapper.java +++ b/springboot1/src/main/java/com/hnucm/springboot/springboot1/dao/PersonIdcardMapper.java @@ -10,4 +10,5 @@ import java.util.List; @Mapper public interface PersonIdcardMapper { public List getAllPersons(); + public List getAllPersons1(); } diff --git a/springboot1/src/main/java/com/hnucm/springboot/springboot1/dao/ProducatMapper.java b/springboot1/src/main/java/com/hnucm/springboot/springboot1/dao/ProducatMapper.java new file mode 100644 index 0000000..bcc4181 --- /dev/null +++ b/springboot1/src/main/java/com/hnucm/springboot/springboot1/dao/ProducatMapper.java @@ -0,0 +1,12 @@ +package com.hnucm.springboot.springboot1.dao; + +import com.hnucm.springboot.springboot1.model.Order; +import com.hnucm.springboot.springboot1.model.Product; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface ProducatMapper { + public List getProductByOrderId(int id); +} diff --git a/springboot1/src/main/java/com/hnucm/springboot/springboot1/model/Order.java b/springboot1/src/main/java/com/hnucm/springboot/springboot1/model/Order.java new file mode 100644 index 0000000..e28a7fc --- /dev/null +++ b/springboot1/src/main/java/com/hnucm/springboot/springboot1/model/Order.java @@ -0,0 +1,14 @@ +package com.hnucm.springboot.springboot1.model; + +import lombok.Data; + +import java.util.List; + +@Data +public class Order { + private int id; + private int userid; + private int orderprice; + private String orderinfo; + private List productList; +} diff --git a/springboot1/src/main/java/com/hnucm/springboot/springboot1/model/Person.java b/springboot1/src/main/java/com/hnucm/springboot/springboot1/model/Person.java index fa8ce8e..c0e1a64 100644 --- a/springboot1/src/main/java/com/hnucm/springboot/springboot1/model/Person.java +++ b/springboot1/src/main/java/com/hnucm/springboot/springboot1/model/Person.java @@ -1,6 +1,9 @@ package com.hnucm.springboot.springboot1.model; import lombok.Data; + +import java.util.List; + //set+get @Data public class Person { @@ -8,4 +11,5 @@ public class Person { private int age; private int id; private IdCard idCard; + private List orderList; } diff --git a/springboot1/src/main/java/com/hnucm/springboot/springboot1/model/Product.java b/springboot1/src/main/java/com/hnucm/springboot/springboot1/model/Product.java new file mode 100644 index 0000000..72993ea --- /dev/null +++ b/springboot1/src/main/java/com/hnucm/springboot/springboot1/model/Product.java @@ -0,0 +1,10 @@ +package com.hnucm.springboot.springboot1.model; + +import lombok.Data; + +@Data +public class Product { + private int id; + private int price; + private String productname; +} diff --git a/springboot1/src/main/java/com/hnucm/springboot/springboot1/service/PersonService.java b/springboot1/src/main/java/com/hnucm/springboot/springboot1/service/PersonService.java index 52d852b..e23a6ad 100644 --- a/springboot1/src/main/java/com/hnucm/springboot/springboot1/service/PersonService.java +++ b/springboot1/src/main/java/com/hnucm/springboot/springboot1/service/PersonService.java @@ -7,7 +7,7 @@ import java.util.List; public interface PersonService { public List getPersons(); public int addPerson(Person person); - public int deletePerson(int id); + public int deletePerson(int id,int idcardid); public int updatePerson(Person person); public List searchPersonsbyName(String name); } diff --git a/springboot1/src/main/java/com/hnucm/springboot/springboot1/service/impl/PersonServiceImpl.java b/springboot1/src/main/java/com/hnucm/springboot/springboot1/service/impl/PersonServiceImpl.java index 93553d3..80d73ea 100644 --- a/springboot1/src/main/java/com/hnucm/springboot/springboot1/service/impl/PersonServiceImpl.java +++ b/springboot1/src/main/java/com/hnucm/springboot/springboot1/service/impl/PersonServiceImpl.java @@ -1,11 +1,13 @@ package com.hnucm.springboot.springboot1.service.impl; +import com.hnucm.springboot.springboot1.dao.IdcardMapper; import com.hnucm.springboot.springboot1.dao.PersonIdcardMapper; import com.hnucm.springboot.springboot1.dao.PersonMapper; import com.hnucm.springboot.springboot1.model.Person; import com.hnucm.springboot.springboot1.service.PersonService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -18,21 +20,28 @@ public class PersonServiceImpl implements PersonService { @Autowired private PersonIdcardMapper personIdcardMapper; + @Autowired + private IdcardMapper idcardMapper; @Override public List getPersons() { - return personIdcardMapper.getAllPersons(); + return personIdcardMapper.getAllPersons1(); } + //保证一致性 事务 + @Transactional + @Override + public int deletePerson(int id,int idcardid) { + idcardMapper.deleteIdcard(idcardid); + return personMapper.deletePerson(id); + } + + @Transactional @Override public int addPerson(Person person) { + idcardMapper.addIdcard(person.getIdCard()); return personMapper.addPerson(person); } - @Override - public int deletePerson(int id) { - return personMapper.deletePerson(id); - } - @Override public int updatePerson(Person person) { return personMapper.updatePerson(person); diff --git a/springboot1/src/main/resources/application.properties b/springboot1/src/main/resources/application.properties index 046a672..6ee6c9b 100644 --- a/springboot1/src/main/resources/application.properties +++ b/springboot1/src/main/resources/application.properties @@ -14,8 +14,8 @@ spring.datasource.username=2004712 spring.datasource.password=@hnucm1254 #??????????MyBatis?? #??Mybatis?Mapper?? -mybatis.mapper-locations=classpath:mapper/*.xml +mybatis-plus.mapper-locations=classpath:mapper/*.xml #??Mybatis????? -mybatis.type-aliases-package=com.hnucm.springboot.springboot1.model +mybatis-plus.type-aliases-package=com.hnucm.springboot.springboot1.model # ?? logging.level.com.hnucm.springboot.springboot1 = debug \ No newline at end of file diff --git a/springboot1/src/main/resources/mapper/IdcardMapper.xml b/springboot1/src/main/resources/mapper/IdcardMapper.xml new file mode 100644 index 0000000..e62462d --- /dev/null +++ b/springboot1/src/main/resources/mapper/IdcardMapper.xml @@ -0,0 +1,18 @@ + + + + + + + delete from idcard where id = #{id}; + + + + insert into idcard(stuid,classname) values(#{stuid},#{classname}); + + \ No newline at end of file diff --git a/springboot1/src/main/resources/mapper/OrderMapper.xml b/springboot1/src/main/resources/mapper/OrderMapper.xml new file mode 100644 index 0000000..3432002 --- /dev/null +++ b/springboot1/src/main/resources/mapper/OrderMapper.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/springboot1/src/main/resources/mapper/PersonIdcardMapper.xml b/springboot1/src/main/resources/mapper/PersonIdcardMapper.xml index 657f1b3..d565091 100644 --- a/springboot1/src/main/resources/mapper/PersonIdcardMapper.xml +++ b/springboot1/src/main/resources/mapper/PersonIdcardMapper.xml @@ -1,6 +1,28 @@ + + + + + + + + + + + + + + - - - - insert into person(name,age) values(#{name},#{age}); + + + + insert into person(name,age,idcardid) values(#{name},#{age},#{idCard.id}); delete from person where id = #{id}; + update person set name = #{name},age = #{age} where id = #{id}; diff --git a/springboot1/src/main/resources/mapper/ProducatMapper.xml b/springboot1/src/main/resources/mapper/ProducatMapper.xml new file mode 100644 index 0000000..de61794 --- /dev/null +++ b/springboot1/src/main/resources/mapper/ProducatMapper.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/springboot1/src/main/resources/templates/addperson.html b/springboot1/src/main/resources/templates/addperson.html index 50c378a..ac8f18a 100644 --- a/springboot1/src/main/resources/templates/addperson.html +++ b/springboot1/src/main/resources/templates/addperson.html @@ -10,6 +10,8 @@


+
+
diff --git a/springboot1/src/main/resources/templates/personlist.html b/springboot1/src/main/resources/templates/personlist.html index f3ad15f..98d124d 100644 --- a/springboot1/src/main/resources/templates/personlist.html +++ b/springboot1/src/main/resources/templates/personlist.html @@ -23,21 +23,39 @@ 姓名 学号 班级 + 删除操作 更新操作 + 订单 - - - - 删除 - - - 更新 - +
+ + + + 删除 + + + 更新 + +
+ +
+ +
    +
  • +
    +
    +
    +
    +
  • +
+ +
+ diff --git a/untitled/.idea/dataSources.xml b/untitled/.idea/dataSources.xml new file mode 100644 index 0000000..57a5dab --- /dev/null +++ b/untitled/.idea/dataSources.xml @@ -0,0 +1,19 @@ + + + + + mysql.8 + true + true + $PROJECT_DIR$/../springboot1/src/main/resources/application.properties + com.mysql.cj.jdbc.Driver + jdbc:mysql://106.53.194.250:63306/mybatis2004712?serverTimezone=UTC + + + + + + $ProjectFileDir$ + + + \ No newline at end of file