From 62b224fc684656fa033ba6d6b3cd700b81b98d0e Mon Sep 17 00:00:00 2001 From: yyl Date: Thu, 13 Aug 2020 09:54:04 +0800 Subject: [PATCH] # --- .../.gitignore | 51 ++++++++ .../controller/HelloController.java | 119 +++++++++--------- .../mapper/basic/HelloBasicMapper.java | 35 +++--- .../mybatis/mapper/basic/HelloBasicMapper.xml | 113 ++++++++--------- .../springboot/mapper/HelloMapperTest.java | 95 +++++++------- .../controller/Hello1Controller.java | 119 +++++++++--------- .../controller/Hello2Controller.java | 119 +++++++++--------- .../springboot/mapper/db1/Hello1Mapper.java | 39 +++--- .../springboot/mapper/db2/Hello2Mapper.java | 39 +++--- .../springboot/mapper/db1/Hello1Mapper.xml | 113 ++++++++--------- .../springboot/mapper/db2/Hello2Mapper.xml | 113 ++++++++--------- .../springboot/mapper/Hello1MapperTest.java | 97 +++++++------- .../springboot/mapper/Hello2MapperTest.java | 97 +++++++------- spring-boot-example-mybatis-plus/pom.xml | 110 ++++++++-------- .../controller/HelloController.java | 112 ++++++++--------- .../yyl/springboot/service/HelloService.java | 20 +-- .../springboot/mapper/HelloMapperTest.java | 101 ++++++++------- .../controller/HelloController.java | 118 +++++++++-------- .../yyl/springboot/mapper/HelloMapper.java | 39 +++--- .../resources/mybatis/mapper/HelloMapper.xml | 113 ++++++++--------- .../springboot/mapper/HelloMapperTest.java | 96 +++++++------- 21 files changed, 930 insertions(+), 928 deletions(-) create mode 100644 spring-boot-example-mybatis-extends/.gitignore diff --git a/spring-boot-example-mybatis-extends/.gitignore b/spring-boot-example-mybatis-extends/.gitignore new file mode 100644 index 0000000..2e3cdc4 --- /dev/null +++ b/spring-boot-example-mybatis-extends/.gitignore @@ -0,0 +1,51 @@ +# Compile files +*.class + +# Package Files +*.jar +*.war +*.ear +*.nar +*.zip +*.tar +*.tar.gz +*.rar + +# Maven +target/ +*.ser +*.ec + +# J2ME +.mtj.tmp/ + +# Eclipse +.classpath +.project +.settings/ +.metadata/ +.factorypath +.springBeans + +# IntelliJ Idea +.idea/ +out/ +*.ipr +*.iws +*.iml + +# BlueJ Files +*.ctxt + +# OS X +.DS_Store + +# Window +Thumbs.db + +# Virtual Machine Crash Logs +hs_err_pid* + +# Log File +*.log +*.log.* diff --git a/spring-boot-example-mybatis-extends/src/main/java/yyl/springboot/controller/HelloController.java b/spring-boot-example-mybatis-extends/src/main/java/yyl/springboot/controller/HelloController.java index d98244a..adecb15 100644 --- a/spring-boot-example-mybatis-extends/src/main/java/yyl/springboot/controller/HelloController.java +++ b/spring-boot-example-mybatis-extends/src/main/java/yyl/springboot/controller/HelloController.java @@ -1,61 +1,60 @@ -package yyl.springboot.controller; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import yyl.springboot.entity.Hello; -import yyl.springboot.mapper.HelloMapper; - -@RestController -@RequestMapping("/hello") -public class HelloController { - - @Autowired - private HelloMapper helloMapper; - - // | /hello/ - @GetMapping("/") - public Object findAll() { - return helloMapper.findAll(); - } - - // | /hello/{id} - @GetMapping("/{id}") - public Object getById(@PathVariable Long id) { - return helloMapper.getById(id); - } - - // | /hello/ - @PostMapping("/") - public Object save(@RequestBody Hello model) { - Long id = model.getId(); - if (id == null) { - helloMapper.insert(model); - } else { - helloMapper.update(model); - } - return Boolean.TRUE; - } - - // | /hello/{id} - @PutMapping(value = "/{id}") - public Object update(@PathVariable Long id, @RequestBody Hello model) { - model.setId(id); - helloMapper.update(model); - return Boolean.TRUE; - } - - // | /hello/{id} - @DeleteMapping(value = "/{id}") - public void delete(@PathVariable("id") Long id) { - helloMapper.deleteById(id); - } - +package yyl.springboot.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import yyl.springboot.entity.Hello; +import yyl.springboot.mapper.HelloMapper; + +@RestController +@RequestMapping("/hello") +public class HelloController { + + @Autowired + private HelloMapper helloMapper; + + // | /hello/ + @PostMapping("/") + public Object save(@RequestBody Hello model) { + Long id = model.getId(); + if (id == null) { + helloMapper.insert(model); + } else { + helloMapper.updateById(model); + } + return Boolean.TRUE; + } + + // | /hello/{id} + @DeleteMapping(value = "/{id}") + public void delete(@PathVariable("id") Long id) { + helloMapper.deleteById(id); + } + + // | /hello/{id} + @PutMapping(value = "/{id}") + public Object update(@PathVariable Long id, @RequestBody Hello model) { + model.setId(id); + helloMapper.updateById(model); + return Boolean.TRUE; + } + + // | /hello/{id} + @GetMapping("/{id}") + public Object getById(@PathVariable Long id) { + return helloMapper.selectById(id); + } + + // | /hello/ + @GetMapping("/") + public Object list() { + return helloMapper.selectAllList(); + } } \ No newline at end of file diff --git a/spring-boot-example-mybatis-extends/src/main/java/yyl/springboot/mapper/basic/HelloBasicMapper.java b/spring-boot-example-mybatis-extends/src/main/java/yyl/springboot/mapper/basic/HelloBasicMapper.java index 0acc0b5..dcb9bc9 100644 --- a/spring-boot-example-mybatis-extends/src/main/java/yyl/springboot/mapper/basic/HelloBasicMapper.java +++ b/spring-boot-example-mybatis-extends/src/main/java/yyl/springboot/mapper/basic/HelloBasicMapper.java @@ -1,19 +1,18 @@ -package yyl.springboot.mapper.basic; - -import java.util.List; - -import yyl.springboot.entity.Hello; - -public interface HelloBasicMapper { - - List findAll(); - - Hello getById(Long id); - - void insert(Hello hello); - - void update(Hello hello); - - void deleteById(Long id); - +package yyl.springboot.mapper.basic; + +import java.util.List; + +import yyl.springboot.entity.Hello; + +public interface HelloBasicMapper { + + void insert(Hello hello); + + void deleteById(Long id); + + void updateById(Hello hello); + + Hello selectById(Long id); + + List selectAllList(); } \ No newline at end of file diff --git a/spring-boot-example-mybatis-extends/src/main/resources/mybatis/mapper/basic/HelloBasicMapper.xml b/spring-boot-example-mybatis-extends/src/main/resources/mybatis/mapper/basic/HelloBasicMapper.xml index 7fe8ed5..9124f6f 100644 --- a/spring-boot-example-mybatis-extends/src/main/resources/mybatis/mapper/basic/HelloBasicMapper.xml +++ b/spring-boot-example-mybatis-extends/src/main/resources/mybatis/mapper/basic/HelloBasicMapper.xml @@ -1,62 +1,53 @@ - - - - - - - - - - - hello - - - id, name, value - - - - - - - - INSERT INTO - - (name,value) - VALUES - (#{name}, #{value}) - - - - UPDATE - - - - name = #{name}, - - - value = #{value}, - - - WHERE - id = #{id} - - - - DELETE FROM - - WHERE - id =#{id} - - + + + + + + + + + hello + + id, name, value + + + INSERT INTO + + (name,value) + VALUES + (#{name}, #{value}) + + + DELETE FROM + + WHERE + id =#{id} + + + UPDATE + + + + name = #{name}, + + + value = #{value}, + + + WHERE + id = #{id} + + + \ No newline at end of file diff --git a/spring-boot-example-mybatis-extends/src/test/java/yyl/springboot/mapper/HelloMapperTest.java b/spring-boot-example-mybatis-extends/src/test/java/yyl/springboot/mapper/HelloMapperTest.java index 6a96a18..1c0e09b 100644 --- a/spring-boot-example-mybatis-extends/src/test/java/yyl/springboot/mapper/HelloMapperTest.java +++ b/spring-boot-example-mybatis-extends/src/test/java/yyl/springboot/mapper/HelloMapperTest.java @@ -1,49 +1,48 @@ -package yyl.springboot.mapper; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import yyl.springboot.entity.Hello; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class HelloMapperTest { - - @Autowired - private HelloMapper helloMapper; - - @Before - public void before() throws Exception { - helloMapper.insert(ofHello("java", "sun")); - helloMapper.insert(ofHello("C#", "microsoft")); - helloMapper.insert(ofHello("golang", "google")); - } - - @Test - public void testQuery() throws Exception { - for (Hello hello : helloMapper.findAll()) { - System.out.println(hello); - } - } - - @Test - public void testUpdate() throws Exception { - Hello hello = helloMapper.getById(1L); - hello.setName("orcale"); - helloMapper.update(hello); - Assert.assertTrue(("orcale".equals(helloMapper.getById(1L).getName()))); - } - - private Hello ofHello(String name, String value) { - Hello hello = new Hello(); - hello.setName(name); - hello.setValue(value); - return hello; - } - +package yyl.springboot.mapper; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import yyl.springboot.entity.Hello; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class HelloMapperTest { + + @Autowired + private HelloMapper helloMapper; + + @Before + public void before() throws Exception { + helloMapper.insert(ofHello("java", "sun")); + helloMapper.insert(ofHello("C#", "microsoft")); + helloMapper.insert(ofHello("golang", "google")); + } + + @Test + public void testQuery() throws Exception { + for (Hello hello : helloMapper.selectAllList()) { + System.out.println(hello); + } + } + + @Test + public void testUpdate() throws Exception { + Hello hello = helloMapper.selectById(1L); + hello.setName("orcale"); + helloMapper.updateById(hello); + Assert.assertTrue(("orcale".equals(helloMapper.selectById(1L).getName()))); + } + + private Hello ofHello(String name, String value) { + Hello hello = new Hello(); + hello.setName(name); + hello.setValue(value); + return hello; + } } \ No newline at end of file diff --git a/spring-boot-example-mybatis-multi-source/src/main/java/yyl/springboot/controller/Hello1Controller.java b/spring-boot-example-mybatis-multi-source/src/main/java/yyl/springboot/controller/Hello1Controller.java index 5191dd3..46ea893 100644 --- a/spring-boot-example-mybatis-multi-source/src/main/java/yyl/springboot/controller/Hello1Controller.java +++ b/spring-boot-example-mybatis-multi-source/src/main/java/yyl/springboot/controller/Hello1Controller.java @@ -1,61 +1,60 @@ -package yyl.springboot.controller; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import yyl.springboot.entity.db1.Hello1; -import yyl.springboot.mapper.db1.Hello1Mapper; - -@RestController -@RequestMapping("/hello") -public class Hello1Controller { - - @Autowired - private Hello1Mapper hello1Mapper; - - // | /hello1/ - @GetMapping("/") - public Object findAll() { - return hello1Mapper.findAll(); - } - - // | /hello1/{id} - @GetMapping("/{id}") - public Object getById(@PathVariable Long id) { - return hello1Mapper.getById(id); - } - - // | /hello1/ - @PostMapping("/") - public Object save(@RequestBody Hello1 model) { - Long id = model.getId(); - if (id == null) { - hello1Mapper.insert(model); - } else { - hello1Mapper.update(model); - } - return Boolean.TRUE; - } - - // | /hello1/{id} - @PutMapping(value = "/{id}") - public Object update(@PathVariable Long id, @RequestBody Hello1 model) { - model.setId(id); - hello1Mapper.update(model); - return Boolean.TRUE; - } - - // | /hello1/{id} - @DeleteMapping(value = "/{id}") - public void delete(@PathVariable("id") Long id) { - hello1Mapper.deleteById(id); - } - +package yyl.springboot.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import yyl.springboot.entity.db1.Hello1; +import yyl.springboot.mapper.db1.Hello1Mapper; + +@RestController +@RequestMapping("/hello") +public class Hello1Controller { + + @Autowired + private Hello1Mapper hello1Mapper; + + // | /hello1/ + @PostMapping("/") + public Object save(@RequestBody Hello1 model) { + Long id = model.getId(); + if (id == null) { + hello1Mapper.insert(model); + } else { + hello1Mapper.updateById(model); + } + return Boolean.TRUE; + } + + // | /hello1/{id} + @DeleteMapping(value = "/{id}") + public void delete(@PathVariable("id") Long id) { + hello1Mapper.deleteById(id); + } + + // | /hello1/{id} + @PutMapping(value = "/{id}") + public Object update(@PathVariable Long id, @RequestBody Hello1 model) { + model.setId(id); + hello1Mapper.updateById(model); + return Boolean.TRUE; + } + + // | /hello1/{id} + @GetMapping("/{id}") + public Object getById(@PathVariable Long id) { + return hello1Mapper.selectById(id); + } + + // | /hello1/ + @GetMapping("/") + public Object list() { + return hello1Mapper.selectAllList(); + } } \ No newline at end of file diff --git a/spring-boot-example-mybatis-multi-source/src/main/java/yyl/springboot/controller/Hello2Controller.java b/spring-boot-example-mybatis-multi-source/src/main/java/yyl/springboot/controller/Hello2Controller.java index 96fc9b3..7b05c45 100644 --- a/spring-boot-example-mybatis-multi-source/src/main/java/yyl/springboot/controller/Hello2Controller.java +++ b/spring-boot-example-mybatis-multi-source/src/main/java/yyl/springboot/controller/Hello2Controller.java @@ -1,61 +1,60 @@ -package yyl.springboot.controller; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import yyl.springboot.entity.db2.Hello2; -import yyl.springboot.mapper.db2.Hello2Mapper; - -@RestController -@RequestMapping("/hello2") -public class Hello2Controller { - - @Autowired - private Hello2Mapper hello2Mapper; - - // | /hello2/ - @GetMapping("/") - public Object findAll() { - return hello2Mapper.findAll(); - } - - // | /hello2/{id} - @GetMapping("/{id}") - public Object getById(@PathVariable Long id) { - return hello2Mapper.getById(id); - } - - // | /hello2/{id} - @PostMapping("/") - public Object save(@RequestBody Hello2 model) { - Long id = model.getId(); - if (id == null) { - hello2Mapper.insert(model); - } else { - hello2Mapper.update(model); - } - return Boolean.TRUE; - } - - // | /hello/{id} - @PutMapping(value = "/{id}") - public Object update(@PathVariable Long id, @RequestBody Hello2 model) { - model.setId(id); - hello2Mapper.update(model); - return Boolean.TRUE; - } - - // | /hello/{id} - @DeleteMapping(value = "/{id}") - public void delete(@PathVariable("id") Long id) { - hello2Mapper.deleteById(id); - } - +package yyl.springboot.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import yyl.springboot.entity.db2.Hello2; +import yyl.springboot.mapper.db2.Hello2Mapper; + +@RestController +@RequestMapping("/hello2") +public class Hello2Controller { + + @Autowired + private Hello2Mapper hello2Mapper; + + // | /hello2/{id} + @PostMapping("/") + public Object save(@RequestBody Hello2 model) { + Long id = model.getId(); + if (id == null) { + hello2Mapper.insert(model); + } else { + hello2Mapper.updateById(model); + } + return Boolean.TRUE; + } + + // | /hello/{id} + @DeleteMapping(value = "/{id}") + public void delete(@PathVariable("id") Long id) { + hello2Mapper.deleteById(id); + } + + // | /hello/{id} + @PutMapping(value = "/{id}") + public Object update(@PathVariable Long id, @RequestBody Hello2 model) { + model.setId(id); + hello2Mapper.updateById(model); + return Boolean.TRUE; + } + + // | /hello2/{id} + @GetMapping("/{id}") + public Object getById(@PathVariable Long id) { + return hello2Mapper.selectById(id); + } + + // | /hello2/ + @GetMapping("/") + public Object list() { + return hello2Mapper.selectAllList(); + } } \ No newline at end of file diff --git a/spring-boot-example-mybatis-multi-source/src/main/java/yyl/springboot/mapper/db1/Hello1Mapper.java b/spring-boot-example-mybatis-multi-source/src/main/java/yyl/springboot/mapper/db1/Hello1Mapper.java index 3f85953..1f972ba 100644 --- a/spring-boot-example-mybatis-multi-source/src/main/java/yyl/springboot/mapper/db1/Hello1Mapper.java +++ b/spring-boot-example-mybatis-multi-source/src/main/java/yyl/springboot/mapper/db1/Hello1Mapper.java @@ -1,21 +1,20 @@ -package yyl.springboot.mapper.db1; - -import java.util.List; - -import yyl.springboot.annotation.MapperRepository; -import yyl.springboot.entity.db1.Hello1; - -@MapperRepository -public interface Hello1Mapper { - - List findAll(); - - Hello1 getById(Long id); - - void insert(Hello1 hello); - - void update(Hello1 hello); - - void deleteById(Long id); - +package yyl.springboot.mapper.db1; + +import java.util.List; + +import yyl.springboot.annotation.MapperRepository; +import yyl.springboot.entity.db1.Hello1; + +@MapperRepository +public interface Hello1Mapper { + + void insert(Hello1 hello); + + void deleteById(Long id); + + void updateById(Hello1 hello); + + Hello1 selectById(Long id); + + List selectAllList(); } \ No newline at end of file diff --git a/spring-boot-example-mybatis-multi-source/src/main/java/yyl/springboot/mapper/db2/Hello2Mapper.java b/spring-boot-example-mybatis-multi-source/src/main/java/yyl/springboot/mapper/db2/Hello2Mapper.java index 19406fe..c5dca79 100644 --- a/spring-boot-example-mybatis-multi-source/src/main/java/yyl/springboot/mapper/db2/Hello2Mapper.java +++ b/spring-boot-example-mybatis-multi-source/src/main/java/yyl/springboot/mapper/db2/Hello2Mapper.java @@ -1,21 +1,20 @@ -package yyl.springboot.mapper.db2; - -import java.util.List; - -import yyl.springboot.annotation.MapperRepository; -import yyl.springboot.entity.db2.Hello2; - -@MapperRepository -public interface Hello2Mapper { - - List findAll(); - - Hello2 getById(Long id); - - void insert(Hello2 hello); - - void update(Hello2 hello); - - void deleteById(Long id); - +package yyl.springboot.mapper.db2; + +import java.util.List; + +import yyl.springboot.annotation.MapperRepository; +import yyl.springboot.entity.db2.Hello2; + +@MapperRepository +public interface Hello2Mapper { + + void insert(Hello2 hello); + + void deleteById(Long id); + + void updateById(Hello2 hello); + + Hello2 selectById(Long id); + + List selectAllList(); } \ No newline at end of file diff --git a/spring-boot-example-mybatis-multi-source/src/main/resources/yyl/springboot/mapper/db1/Hello1Mapper.xml b/spring-boot-example-mybatis-multi-source/src/main/resources/yyl/springboot/mapper/db1/Hello1Mapper.xml index afb684d..ebbf315 100644 --- a/spring-boot-example-mybatis-multi-source/src/main/resources/yyl/springboot/mapper/db1/Hello1Mapper.xml +++ b/spring-boot-example-mybatis-multi-source/src/main/resources/yyl/springboot/mapper/db1/Hello1Mapper.xml @@ -1,62 +1,53 @@ - - - - - - - - - - - hello1 - - - id, name, value - - - - - - - - INSERT INTO - - (name,value) - VALUES - (#{name}, #{value}) - - - - UPDATE - - - - name = #{name}, - - - value = #{value}, - - - WHERE - id = #{id} - - - - DELETE FROM - - WHERE - id =#{id} - - + + + + + + + + + hello1 + + id, name, value + + + INSERT INTO + + (name,value) + VALUES + (#{name}, #{value}) + + + DELETE FROM + + WHERE + id =#{id} + + + UPDATE + + + + name = #{name}, + + + value = #{value}, + + + WHERE + id = #{id} + + + \ No newline at end of file diff --git a/spring-boot-example-mybatis-multi-source/src/main/resources/yyl/springboot/mapper/db2/Hello2Mapper.xml b/spring-boot-example-mybatis-multi-source/src/main/resources/yyl/springboot/mapper/db2/Hello2Mapper.xml index 9c2a5d0..465c89a 100644 --- a/spring-boot-example-mybatis-multi-source/src/main/resources/yyl/springboot/mapper/db2/Hello2Mapper.xml +++ b/spring-boot-example-mybatis-multi-source/src/main/resources/yyl/springboot/mapper/db2/Hello2Mapper.xml @@ -1,62 +1,53 @@ - - - - - - - - - - - hello2 - - - id, name, value - - - - - - - - INSERT INTO - - (name,value) - VALUES - (#{name}, #{value}) - - - - UPDATE - - - - name = #{name}, - - - value = #{value}, - - - WHERE - id = #{id} - - - - DELETE FROM - - WHERE - id =#{id} - - + + + + + + + + + hello2 + + id, name, value + + + INSERT INTO + + (name,value) + VALUES + (#{name}, #{value}) + + + DELETE FROM + + WHERE + id =#{id} + + + UPDATE + + + + name = #{name}, + + + value = #{value}, + + + WHERE + id = #{id} + + + \ No newline at end of file diff --git a/spring-boot-example-mybatis-multi-source/src/test/java/yyl/springboot/mapper/Hello1MapperTest.java b/spring-boot-example-mybatis-multi-source/src/test/java/yyl/springboot/mapper/Hello1MapperTest.java index c646ffd..54eac14 100644 --- a/spring-boot-example-mybatis-multi-source/src/test/java/yyl/springboot/mapper/Hello1MapperTest.java +++ b/spring-boot-example-mybatis-multi-source/src/test/java/yyl/springboot/mapper/Hello1MapperTest.java @@ -1,50 +1,49 @@ -package yyl.springboot.mapper; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import yyl.springboot.entity.db1.Hello1; -import yyl.springboot.mapper.db1.Hello1Mapper; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class Hello1MapperTest { - - @Autowired - private Hello1Mapper hello1Mapper; - - @Before - public void before() throws Exception { - hello1Mapper.insert(ofHello("java", "sun")); - hello1Mapper.insert(ofHello("C#", "microsoft")); - hello1Mapper.insert(ofHello("golang", "google")); - } - - @Test - public void testQuery() throws Exception { - for (Hello1 hello : hello1Mapper.findAll()) { - System.out.println(hello); - } - } - - @Test - public void testUpdate() throws Exception { - Hello1 hello = hello1Mapper.getById(1L); - hello.setName("orcale"); - hello1Mapper.update(hello); - Assert.assertTrue(("orcale".equals(hello1Mapper.getById(1L).getName()))); - } - - private Hello1 ofHello(String name, String value) { - Hello1 hello = new Hello1(); - hello.setName(name); - hello.setValue(value); - return hello; - } - +package yyl.springboot.mapper; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import yyl.springboot.entity.db1.Hello1; +import yyl.springboot.mapper.db1.Hello1Mapper; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class Hello1MapperTest { + + @Autowired + private Hello1Mapper hello1Mapper; + + @Before + public void before() throws Exception { + hello1Mapper.insert(ofHello("java", "sun")); + hello1Mapper.insert(ofHello("C#", "microsoft")); + hello1Mapper.insert(ofHello("golang", "google")); + } + + @Test + public void testQuery() throws Exception { + for (Hello1 hello : hello1Mapper.selectAllList()) { + System.out.println(hello); + } + } + + @Test + public void testUpdate() throws Exception { + Hello1 hello = hello1Mapper.selectById(1L); + hello.setName("orcale"); + hello1Mapper.updateById(hello); + Assert.assertTrue(("orcale".equals(hello1Mapper.selectById(1L).getName()))); + } + + private Hello1 ofHello(String name, String value) { + Hello1 hello = new Hello1(); + hello.setName(name); + hello.setValue(value); + return hello; + } } \ No newline at end of file diff --git a/spring-boot-example-mybatis-multi-source/src/test/java/yyl/springboot/mapper/Hello2MapperTest.java b/spring-boot-example-mybatis-multi-source/src/test/java/yyl/springboot/mapper/Hello2MapperTest.java index 95e03d6..6c42916 100644 --- a/spring-boot-example-mybatis-multi-source/src/test/java/yyl/springboot/mapper/Hello2MapperTest.java +++ b/spring-boot-example-mybatis-multi-source/src/test/java/yyl/springboot/mapper/Hello2MapperTest.java @@ -1,50 +1,49 @@ -package yyl.springboot.mapper; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import yyl.springboot.entity.db2.Hello2; -import yyl.springboot.mapper.db2.Hello2Mapper; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class Hello2MapperTest { - - @Autowired - private Hello2Mapper hello2Mapper; - - @Before - public void before() throws Exception { - hello2Mapper.insert(ofHello("java", "sun")); - hello2Mapper.insert(ofHello("C#", "microsoft")); - hello2Mapper.insert(ofHello("golang", "google")); - } - - @Test - public void testQuery() throws Exception { - for (Hello2 hello : hello2Mapper.findAll()) { - System.out.println(hello); - } - } - - @Test - public void testUpdate() throws Exception { - Hello2 hello = hello2Mapper.getById(1L); - hello.setName("orcale"); - hello2Mapper.update(hello); - Assert.assertTrue(("orcale".equals(hello2Mapper.getById(1L).getName()))); - } - - private Hello2 ofHello(String name, String value) { - Hello2 hello = new Hello2(); - hello.setName(name); - hello.setValue(value); - return hello; - } - +package yyl.springboot.mapper; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import yyl.springboot.entity.db2.Hello2; +import yyl.springboot.mapper.db2.Hello2Mapper; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class Hello2MapperTest { + + @Autowired + private Hello2Mapper hello2Mapper; + + @Before + public void before() throws Exception { + hello2Mapper.insert(ofHello("java", "sun")); + hello2Mapper.insert(ofHello("C#", "microsoft")); + hello2Mapper.insert(ofHello("golang", "google")); + } + + @Test + public void testQuery() throws Exception { + for (Hello2 hello : hello2Mapper.selectAllList()) { + System.out.println(hello); + } + } + + @Test + public void testUpdate() throws Exception { + Hello2 hello = hello2Mapper.selectById(1L); + hello.setName("orcale"); + hello2Mapper.updateById(hello); + Assert.assertTrue(("orcale".equals(hello2Mapper.selectById(1L).getName()))); + } + + private Hello2 ofHello(String name, String value) { + Hello2 hello = new Hello2(); + hello.setName(name); + hello.setValue(value); + return hello; + } } \ No newline at end of file diff --git a/spring-boot-example-mybatis-plus/pom.xml b/spring-boot-example-mybatis-plus/pom.xml index e09b102..b5e7d02 100644 --- a/spring-boot-example-mybatis-plus/pom.xml +++ b/spring-boot-example-mybatis-plus/pom.xml @@ -1,55 +1,55 @@ - - - - 4.0.0 - - yyl - spring-boot-example - ${revision} - ../pom.xml - - spring-boot-example-mybatis-plus - - spring-boot-example-mybatis-plus - Demo project for Spring Boot - - - - - - org.springframework.boot - spring-boot-starter-web - - - - - com.baomidou - mybatis-plus-boot-starter - 3.2.0 - - - - - com.h2database - h2 - - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - + + + + 4.0.0 + + yyl + spring-boot-example + ${revision} + ../pom.xml + + spring-boot-example-mybatis-plus + + spring-boot-example-mybatis-plus + Demo project for Spring Boot + + + + + + org.springframework.boot + spring-boot-starter-web + + + + + com.baomidou + mybatis-plus-boot-starter + 3.3.2 + + + + + com.h2database + h2 + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/spring-boot-example-mybatis-plus/src/main/java/yyl/springboot/controller/HelloController.java b/spring-boot-example-mybatis-plus/src/main/java/yyl/springboot/controller/HelloController.java index 0479431..4dded3e 100644 --- a/spring-boot-example-mybatis-plus/src/main/java/yyl/springboot/controller/HelloController.java +++ b/spring-boot-example-mybatis-plus/src/main/java/yyl/springboot/controller/HelloController.java @@ -1,56 +1,56 @@ -package yyl.springboot.controller; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import yyl.springboot.entity.Hello; -import yyl.springboot.service.HelloService; - -@RestController -@RequestMapping("/hello") -public class HelloController { - - @Autowired - private HelloService helloService; - - // | /hello/ - @GetMapping("/") - public Object findAll() { - return helloService.findAll(); - } - - // | /hello/{id} - @GetMapping("/{id}") - public Object getById(@PathVariable Long id) { - return helloService.getById(id); - } - - // | /hello/ - @PostMapping("/") - public Object save(@RequestBody Hello model) { - helloService.save(model); - return Boolean.TRUE; - } - - // | /hello/{id} - @PutMapping(value = "/{id}") - public Object update(@PathVariable Long id, @RequestBody Hello model) { - model.setId(id); - helloService.updateById(model); - return Boolean.TRUE; - } - - // | /hello/{id} - @DeleteMapping(value = "/{id}") - public Object delete(@PathVariable("id") Long id) { - helloService.deleteById(id); - return Boolean.TRUE; - } -} +package yyl.springboot.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import yyl.springboot.entity.Hello; +import yyl.springboot.service.HelloService; + +@RestController +@RequestMapping("/hello") +public class HelloController { + + @Autowired + private HelloService helloService; + + // | /hello/ + @PostMapping("/") + public Object save(@RequestBody Hello model) { + helloService.save(model); + return Boolean.TRUE; + } + + // | /hello/{id} + @PutMapping(value = "/{id}") + public Object update(@PathVariable Long id, @RequestBody Hello model) { + model.setId(id); + helloService.updateById(model); + return Boolean.TRUE; + } + + // | /hello/{id} + @DeleteMapping(value = "/{id}") + public Object delete(@PathVariable("id") Long id) { + helloService.deleteById(id); + return Boolean.TRUE; + } + + // | /hello/{id} + @GetMapping("/{id}") + public Object getById(@PathVariable Long id) { + return helloService.getById(id); + } + + // | /hello/ + @GetMapping("/") + public Object list() { + return helloService.getList(); + } +} diff --git a/spring-boot-example-mybatis-plus/src/main/java/yyl/springboot/service/HelloService.java b/spring-boot-example-mybatis-plus/src/main/java/yyl/springboot/service/HelloService.java index 011f690..e2b4c9b 100644 --- a/spring-boot-example-mybatis-plus/src/main/java/yyl/springboot/service/HelloService.java +++ b/spring-boot-example-mybatis-plus/src/main/java/yyl/springboot/service/HelloService.java @@ -17,14 +17,6 @@ public class HelloService { @Autowired private HelloMapper helloMapper; - public List findAll() { - return helloMapper.selectList(Wrappers.emptyWrapper()); - } - - public Hello getById(Long id) { - return helloMapper.selectById(id); - } - public void save(Hello model) { Long id = model.getId(); model.setDeleted(0); @@ -35,12 +27,20 @@ public void save(Hello model) { } } + public void deleteById(Long id) { + helloMapper.deleteById(id); + } + public void updateById(Hello model) { model.setUpdatedAt(new Date()); helloMapper.updateById(model); } - public void deleteById(Long id) { - helloMapper.deleteById(id); + public Hello getById(Long id) { + return helloMapper.selectById(id); + } + + public List getList() { + return helloMapper.selectList(Wrappers.emptyWrapper()); } } \ No newline at end of file diff --git a/spring-boot-example-mybatis-plus/src/test/java/yyl/springboot/mapper/HelloMapperTest.java b/spring-boot-example-mybatis-plus/src/test/java/yyl/springboot/mapper/HelloMapperTest.java index 847a472..97386d1 100644 --- a/spring-boot-example-mybatis-plus/src/test/java/yyl/springboot/mapper/HelloMapperTest.java +++ b/spring-boot-example-mybatis-plus/src/test/java/yyl/springboot/mapper/HelloMapperTest.java @@ -1,51 +1,50 @@ -package yyl.springboot.mapper; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import com.baomidou.mybatisplus.core.toolkit.Wrappers; - -import yyl.springboot.entity.Hello; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class HelloMapperTest { - - @Autowired - private HelloMapper helloMapper; - - @Before - public void before() throws Exception { - helloMapper.insert(ofHello("java", "sun")); - helloMapper.insert(ofHello("C#", "microsoft")); - helloMapper.insert(ofHello("golang", "google")); - } - - @Test - public void testQuery() throws Exception { - for (Hello hello : helloMapper.selectList(Wrappers.emptyWrapper())) { - System.out.println(hello); - } - } - - @Test - public void testUpdate() throws Exception { - Hello hello = helloMapper.selectById(1L); - hello.setName("orcale"); - helloMapper.updateById(hello); - Assert.assertTrue(("orcale".equals(helloMapper.selectById(1L).getName()))); - } - - private Hello ofHello(String name, String value) { - Hello hello = new Hello(); - hello.setName(name); - hello.setValue(value); - return hello; - } - -} +package yyl.springboot.mapper; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; + +import yyl.springboot.entity.Hello; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class HelloMapperTest { + + @Autowired + private HelloMapper helloMapper; + + @Before + public void before() throws Exception { + helloMapper.insert(ofHello("java", "sun")); + helloMapper.insert(ofHello("C#", "microsoft")); + helloMapper.insert(ofHello("golang", "google")); + } + + @Test + public void testQuery() throws Exception { + for (Hello hello : helloMapper.selectList(Wrappers.emptyWrapper())) { + System.out.println(hello); + } + } + + @Test + public void testUpdate() throws Exception { + Hello hello = helloMapper.selectById(1L); + hello.setName("orcale"); + helloMapper.updateById(hello); + Assert.assertTrue(("orcale".equals(helloMapper.selectById(1L).getName()))); + } + + private Hello ofHello(String name, String value) { + Hello hello = new Hello(); + hello.setName(name); + hello.setValue(value); + return hello; + } +} diff --git a/spring-boot-example-mybatis/src/main/java/yyl/springboot/controller/HelloController.java b/spring-boot-example-mybatis/src/main/java/yyl/springboot/controller/HelloController.java index d98244a..483b5af 100644 --- a/spring-boot-example-mybatis/src/main/java/yyl/springboot/controller/HelloController.java +++ b/spring-boot-example-mybatis/src/main/java/yyl/springboot/controller/HelloController.java @@ -1,61 +1,59 @@ -package yyl.springboot.controller; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import yyl.springboot.entity.Hello; -import yyl.springboot.mapper.HelloMapper; - -@RestController -@RequestMapping("/hello") -public class HelloController { - - @Autowired - private HelloMapper helloMapper; - - // | /hello/ - @GetMapping("/") - public Object findAll() { - return helloMapper.findAll(); - } - - // | /hello/{id} - @GetMapping("/{id}") - public Object getById(@PathVariable Long id) { - return helloMapper.getById(id); - } - - // | /hello/ - @PostMapping("/") - public Object save(@RequestBody Hello model) { - Long id = model.getId(); - if (id == null) { - helloMapper.insert(model); - } else { - helloMapper.update(model); - } - return Boolean.TRUE; - } - - // | /hello/{id} - @PutMapping(value = "/{id}") - public Object update(@PathVariable Long id, @RequestBody Hello model) { - model.setId(id); - helloMapper.update(model); - return Boolean.TRUE; - } - - // | /hello/{id} - @DeleteMapping(value = "/{id}") - public void delete(@PathVariable("id") Long id) { - helloMapper.deleteById(id); - } - +package yyl.springboot.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import yyl.springboot.entity.Hello; +import yyl.springboot.mapper.HelloMapper; + +@RestController +@RequestMapping("/hello") +public class HelloController { + + @Autowired + private HelloMapper helloMapper; + + // | /hello/ + @PostMapping("/") + public Object save(@RequestBody Hello model) { + Long id = model.getId(); + if (id == null) { + helloMapper.insert(model); + } else { + helloMapper.updateById(model); + } + return Boolean.TRUE; + } + + // | /hello/{id} + @DeleteMapping(value = "/{id}") + public void delete(@PathVariable("id") Long id) { + helloMapper.deleteById(id); + } + + // | /hello/{id} + @PutMapping(value = "/{id}") + public Object update(@PathVariable Long id, @RequestBody Hello model) { + model.setId(id); + helloMapper.updateById(model); + return Boolean.TRUE; + } + + // | /hello/{id} + @GetMapping("/{id}") + public Object getById(@PathVariable Long id) { + return helloMapper.selectById(id); + } // | /hello/ + + @GetMapping("/") + public Object list() { + return helloMapper.selectAllList(); + } } \ No newline at end of file diff --git a/spring-boot-example-mybatis/src/main/java/yyl/springboot/mapper/HelloMapper.java b/spring-boot-example-mybatis/src/main/java/yyl/springboot/mapper/HelloMapper.java index c728151..e208265 100644 --- a/spring-boot-example-mybatis/src/main/java/yyl/springboot/mapper/HelloMapper.java +++ b/spring-boot-example-mybatis/src/main/java/yyl/springboot/mapper/HelloMapper.java @@ -1,21 +1,20 @@ -package yyl.springboot.mapper; - -import java.util.List; - -import yyl.springboot.annotation.MapperRepository; -import yyl.springboot.entity.Hello; - -@MapperRepository -public interface HelloMapper { - - List findAll(); - - Hello getById(Long id); - - void insert(Hello hello); - - void update(Hello hello); - - void deleteById(Long id); - +package yyl.springboot.mapper; + +import java.util.List; + +import yyl.springboot.annotation.MapperRepository; +import yyl.springboot.entity.Hello; + +@MapperRepository +public interface HelloMapper { + + void insert(Hello hello); + + void deleteById(Long id); + + void updateById(Hello hello); + + Hello selectById(Long id); + + List selectAllList(); } \ No newline at end of file diff --git a/spring-boot-example-mybatis/src/main/resources/mybatis/mapper/HelloMapper.xml b/spring-boot-example-mybatis/src/main/resources/mybatis/mapper/HelloMapper.xml index f91ae6c..facc449 100644 --- a/spring-boot-example-mybatis/src/main/resources/mybatis/mapper/HelloMapper.xml +++ b/spring-boot-example-mybatis/src/main/resources/mybatis/mapper/HelloMapper.xml @@ -1,62 +1,53 @@ - - - - - - - - - - - hello - - - id, name, value - - - - - - - - INSERT INTO - - (name,value) - VALUES - (#{name}, #{value}) - - - - UPDATE - - - - name = #{name}, - - - value = #{value}, - - - WHERE - id = #{id} - - - - DELETE FROM - - WHERE - id =#{id} - - + + + + + + + + + hello + + id, name, value + + + INSERT INTO + + (name,value) + VALUES + (#{name}, #{value}) + + + DELETE FROM + + WHERE + id =#{id} + + + UPDATE + + + + name = #{name}, + + + value = #{value}, + + + WHERE + id = #{id} + + + \ No newline at end of file diff --git a/spring-boot-example-mybatis/src/test/java/yyl/springboot/mapper/HelloMapperTest.java b/spring-boot-example-mybatis/src/test/java/yyl/springboot/mapper/HelloMapperTest.java index 6a96a18..2be492f 100644 --- a/spring-boot-example-mybatis/src/test/java/yyl/springboot/mapper/HelloMapperTest.java +++ b/spring-boot-example-mybatis/src/test/java/yyl/springboot/mapper/HelloMapperTest.java @@ -1,49 +1,49 @@ -package yyl.springboot.mapper; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import yyl.springboot.entity.Hello; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class HelloMapperTest { - - @Autowired - private HelloMapper helloMapper; - - @Before - public void before() throws Exception { - helloMapper.insert(ofHello("java", "sun")); - helloMapper.insert(ofHello("C#", "microsoft")); - helloMapper.insert(ofHello("golang", "google")); - } - - @Test - public void testQuery() throws Exception { - for (Hello hello : helloMapper.findAll()) { - System.out.println(hello); - } - } - - @Test - public void testUpdate() throws Exception { - Hello hello = helloMapper.getById(1L); - hello.setName("orcale"); - helloMapper.update(hello); - Assert.assertTrue(("orcale".equals(helloMapper.getById(1L).getName()))); - } - - private Hello ofHello(String name, String value) { - Hello hello = new Hello(); - hello.setName(name); - hello.setValue(value); - return hello; - } - +package yyl.springboot.mapper; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import yyl.springboot.entity.Hello; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class HelloMapperTest { + + @Autowired + private HelloMapper helloMapper; + + @Before + public void before() throws Exception { + helloMapper.insert(ofHello("java", "sun")); + helloMapper.insert(ofHello("C#", "microsoft")); + helloMapper.insert(ofHello("golang", "google")); + } + + @Test + public void testUpdate() throws Exception { + Hello hello = helloMapper.selectById(1L); + hello.setName("orcale"); + helloMapper.updateById(hello); + Assert.assertTrue(("orcale".equals(helloMapper.selectById(1L).getName()))); + } + + @Test + public void testQuery() throws Exception { + for (Hello hello : helloMapper.selectAllList()) { + System.out.println(hello); + } + } + + private Hello ofHello(String name, String value) { + Hello hello = new Hello(); + hello.setName(name); + hello.setValue(value); + return hello; + } + } \ No newline at end of file