1.测试数据库表
CREATE TABLE test_tbl_department(
id varchar(32) NOT NULL,
name varchar(32) NOT NULL,
tel varchar(18) DEFAULT NULL,
PRIMARY KEY(id)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
CREATE TABLE test_tbl_user(
id varchar(32) NOT NULL,
version int(11) NOT NULL DEFAULT '0',
name varchar(32) NOT NULL,
age int(3) DEFAULT NULL,
birthday datetime DEFAULT NULL,
department_id varchar(32) NOT NULL,
sorder int(11) NOT NULL DEFAULT '1',
deleted tinyint(1) NOT NULL DEFAULT '0',
jsonUser varchar(100) DEFAULT NULL
primary key(id)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
2.测试实体类
jsonUser存储User的json类型的信息,通过自定义类型处理器,将JSONObject对象转为字符串类型,或将VARCHAR类型转为JSONObject类型。
建表时,user的department_id为非空字段,但是User实体类中并没有给出。通过自定义类型处理器,将department_id自动转为Department对象,或将Department自动转为department_id字符串。
@Data
public class User{
private String id;
private String name;
private Integer age;
private Date birthday;
private Department department;
private JSONObject jsonUser;
}
@Data
public class Department {
private String id;
private String name;
private String tel;
private Set<User> users;
}
3.测试接口
public interface UserDao {