diff --git a/mybatis-flex-test/mybatis-flex-native-test/pom.xml b/mybatis-flex-test/mybatis-flex-native-test/pom.xml index 9f0ef104..f6598ff7 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/pom.xml +++ b/mybatis-flex-test/mybatis-flex-native-test/pom.xml @@ -40,6 +40,13 @@ 1.4.199 + + com.alibaba.fastjson2 + fastjson2 + 2.0.25 + + + org.springframework spring-test diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account.java index 2cb9d35d..a2b60e2e 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account.java @@ -1,10 +1,14 @@ package com.mybatisflex.test; +import com.mybatisflex.annotation.Column; import com.mybatisflex.annotation.Id; -import com.mybatisflex.annotation.Table; import com.mybatisflex.annotation.KeyType; +import com.mybatisflex.annotation.Table; +import com.mybatisflex.core.handler.Fastjson2TypeHandler; import java.util.Date; +import java.util.HashMap; +import java.util.Map; @Table("tb_account") public class Account { @@ -18,6 +22,9 @@ public class Account { private Date birthday; + @Column(typeHandler = Fastjson2TypeHandler.class) + private Map options; + public Long getId() { return id; } @@ -50,6 +57,21 @@ public class Account { this.birthday = birthday; } + public Map getOptions() { + return options; + } + + public void setOptions(Map options) { + this.options = options; + } + + public void addOption(String key, Object value) { + if (options == null) { + options = new HashMap<>(); + } + options.put(key, value); + } + @Override public String toString() { return "Account{" + @@ -57,6 +79,7 @@ public class Account { ", userName='" + userName + '\'' + ", age=" + age + ", birthday=" + birthday + + ", options=" + options + '}'; } } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/EntityTestStarter.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/EntityTestStarter.java index aa475050..8aeb0067 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/EntityTestStarter.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/EntityTestStarter.java @@ -112,5 +112,20 @@ public class EntityTestStarter { accountMapper.paginate(2, 3, QueryWrapper.create())); System.out.println(accountPage); + + Account optionsAccount = new Account(); + optionsAccount.setUserName("optionstest"); + optionsAccount.addOption("c1", 11); + optionsAccount.addOption("c2", "zhang"); + optionsAccount.addOption("c3", new Date()); + bootstrap.execute(AccountMapper.class, accountMapper -> + accountMapper.insert(optionsAccount)); + System.out.println(">>>>>>> optionsAccount: " + optionsAccount.getId()); + + + Account selectOptionsAccount = bootstrap.execute(AccountMapper.class, accountMapper -> + accountMapper.selectOneById(optionsAccount.getId())); + System.out.println(selectOptionsAccount); + } } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/resources/data.sql b/mybatis-flex-test/mybatis-flex-native-test/src/main/resources/data.sql index 9a09ed8a..d896a0e9 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/resources/data.sql +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/resources/data.sql @@ -1,3 +1,3 @@ INSERT INTO tb_account -VALUES (1, 'Michael Yang', 18, '2020-01-11'), - (2, 'Zhang san', 19, '2021-03-21'); \ No newline at end of file +VALUES (1, 'Michael Yang', 18, '2020-01-11', null), + (2, 'Zhang san', 19, '2021-03-21', null); \ No newline at end of file diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/resources/schema.sql b/mybatis-flex-test/mybatis-flex-native-test/src/main/resources/schema.sql index d7e21fac..ac986401 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/resources/schema.sql +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/resources/schema.sql @@ -3,5 +3,6 @@ CREATE TABLE IF NOT EXISTS `tb_account` `id` INTEGER PRIMARY KEY auto_increment, `user_name` VARCHAR(100), `age` Integer, - `birthday` DATETIME + `birthday` DATETIME, + `options` VARCHAR(1024) ); \ No newline at end of file