From dc9aef3a8dbc67532e99b21a8560061ad4b14958 Mon Sep 17 00:00:00 2001 From: DigitalSonic Date: Tue, 2 Apr 2019 00:01:20 +0800 Subject: [PATCH] BUGFIX --- .../data/mybatisdemo/MybatisDemoApplication.java | 13 +++++++++---- .../data/mybatisdemo/mapper/CoffeeMapper.java | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Chapter 3/mybatis-demo/src/main/java/geektime/spring/data/mybatisdemo/MybatisDemoApplication.java b/Chapter 3/mybatis-demo/src/main/java/geektime/spring/data/mybatisdemo/MybatisDemoApplication.java index f94b33e..5454d2f 100644 --- a/Chapter 3/mybatis-demo/src/main/java/geektime/spring/data/mybatisdemo/MybatisDemoApplication.java +++ b/Chapter 3/mybatis-demo/src/main/java/geektime/spring/data/mybatisdemo/MybatisDemoApplication.java @@ -27,11 +27,16 @@ public class MybatisDemoApplication implements ApplicationRunner { public void run(ApplicationArguments args) throws Exception { Coffee c = Coffee.builder().name("espresso") .price(Money.of(CurrencyUnit.of("CNY"), 20.0)).build(); - Long id = coffeeMapper.save(c); - log.info("Coffee {} => {}", id, c); + int count = coffeeMapper.save(c); + log.info("Save {} Coffee: {}", count, c); - c = coffeeMapper.findById(id); - log.info("Coffee {}", c); + c = Coffee.builder().name("latte") + .price(Money.of(CurrencyUnit.of("CNY"), 25.0)).build(); + count = coffeeMapper.save(c); + log.info("Save {} Coffee: {}", count, c); + + c = coffeeMapper.findById(c.getId()); + log.info("Find Coffee: {}", c); } } diff --git a/Chapter 3/mybatis-demo/src/main/java/geektime/spring/data/mybatisdemo/mapper/CoffeeMapper.java b/Chapter 3/mybatis-demo/src/main/java/geektime/spring/data/mybatisdemo/mapper/CoffeeMapper.java index e869dd5..0148f13 100644 --- a/Chapter 3/mybatis-demo/src/main/java/geektime/spring/data/mybatisdemo/mapper/CoffeeMapper.java +++ b/Chapter 3/mybatis-demo/src/main/java/geektime/spring/data/mybatisdemo/mapper/CoffeeMapper.java @@ -14,7 +14,7 @@ public interface CoffeeMapper { @Insert("insert into t_coffee (name, price, create_time, update_time)" + "values (#{name}, #{price}, now(), now())") @Options(useGeneratedKeys = true) - Long save(Coffee coffee); + int save(Coffee coffee); @Select("select * from t_coffee where id = #{id}") @Results({