mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
add typeHandler test
This commit is contained in:
parent
73b29a2093
commit
42b79bf1f4
@ -40,6 +40,13 @@
|
||||
<version>1.4.199</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
<version>2.0.25</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
|
||||
@ -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<String, Object> options;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@ -50,6 +57,21 @@ public class Account {
|
||||
this.birthday = birthday;
|
||||
}
|
||||
|
||||
public Map<String, Object> getOptions() {
|
||||
return options;
|
||||
}
|
||||
|
||||
public void setOptions(Map<String, Object> 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 +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
INSERT INTO tb_account
|
||||
VALUES (1, 'Michael Yang', 18, '2020-01-11'),
|
||||
(2, 'Zhang san', 19, '2021-03-21');
|
||||
VALUES (1, 'Michael Yang', 18, '2020-01-11', null),
|
||||
(2, 'Zhang san', 19, '2021-03-21', null);
|
||||
@ -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)
|
||||
);
|
||||
Loading…
x
Reference in New Issue
Block a user