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>
|
<version>1.4.199</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.fastjson2</groupId>
|
||||||
|
<artifactId>fastjson2</artifactId>
|
||||||
|
<version>2.0.25</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-test</artifactId>
|
<artifactId>spring-test</artifactId>
|
||||||
|
|||||||
@ -1,10 +1,14 @@
|
|||||||
package com.mybatisflex.test;
|
package com.mybatisflex.test;
|
||||||
|
|
||||||
|
import com.mybatisflex.annotation.Column;
|
||||||
import com.mybatisflex.annotation.Id;
|
import com.mybatisflex.annotation.Id;
|
||||||
import com.mybatisflex.annotation.Table;
|
|
||||||
import com.mybatisflex.annotation.KeyType;
|
import com.mybatisflex.annotation.KeyType;
|
||||||
|
import com.mybatisflex.annotation.Table;
|
||||||
|
import com.mybatisflex.core.handler.Fastjson2TypeHandler;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Table("tb_account")
|
@Table("tb_account")
|
||||||
public class Account {
|
public class Account {
|
||||||
@ -18,6 +22,9 @@ public class Account {
|
|||||||
|
|
||||||
private Date birthday;
|
private Date birthday;
|
||||||
|
|
||||||
|
@Column(typeHandler = Fastjson2TypeHandler.class)
|
||||||
|
private Map<String, Object> options;
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -50,6 +57,21 @@ public class Account {
|
|||||||
this.birthday = birthday;
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Account{" +
|
return "Account{" +
|
||||||
@ -57,6 +79,7 @@ public class Account {
|
|||||||
", userName='" + userName + '\'' +
|
", userName='" + userName + '\'' +
|
||||||
", age=" + age +
|
", age=" + age +
|
||||||
", birthday=" + birthday +
|
", birthday=" + birthday +
|
||||||
|
", options=" + options +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -112,5 +112,20 @@ public class EntityTestStarter {
|
|||||||
accountMapper.paginate(2, 3, QueryWrapper.create()));
|
accountMapper.paginate(2, 3, QueryWrapper.create()));
|
||||||
System.out.println(accountPage);
|
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
|
INSERT INTO tb_account
|
||||||
VALUES (1, 'Michael Yang', 18, '2020-01-11'),
|
VALUES (1, 'Michael Yang', 18, '2020-01-11', null),
|
||||||
(2, 'Zhang san', 19, '2021-03-21');
|
(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,
|
`id` INTEGER PRIMARY KEY auto_increment,
|
||||||
`user_name` VARCHAR(100),
|
`user_name` VARCHAR(100),
|
||||||
`age` Integer,
|
`age` Integer,
|
||||||
`birthday` DATETIME
|
`birthday` DATETIME,
|
||||||
|
`options` VARCHAR(1024)
|
||||||
);
|
);
|
||||||
Loading…
x
Reference in New Issue
Block a user