实体类
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("user_contact")
public class UserContact implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 用户id
*/
private String userId;
/**
* 联系人id或群组id
*/
private String contactId;
/**
* 联系人类型 0:好友 1:群组
*/
private UserContactTypeEnum contactType;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 状态 0:非好友 1:好友 2:已删除好友 3:被好友删除 4:已拉黑好友 5:被好友拉黑
*/
private UserContactStatusEnum status;
/**
* 最后更新时间
*/
private LocalDateTime lastUpdateTime;
}
实体类中有两个枚举类,分别为UserContactTypeEnum 和UserContactStatusEnum ,分别为:
@Getter
public enum UserContactTypeEnum{
FRIEND(0,"好友"),
GROUP(1,"群组");
@EnumValue
private int value;
private String desc;
UserContactTypeEnum(int value, String desc){
this.value=value;
this.desc=desc;
}
}
@Getter
public enum UserContactStatusEnum {
NOT_FRIEND(0,"非好友"),
FRIEND(1,"好友"),
DEL(2,"已删除好友"),
DEL_BE(3,"被好友删除"),
BLACKLIST(4,"已拉黑好友"),
BLACKLIST_BE(5,"被好友拉黑");
@EnumValue
private int value;
private String desc;
UserContactStatusEnum(int value,String desc){
this.value=value;
this.desc=desc;
}
}
在枚举类中需要与数据库转化的字段上加上@EnumValue注解。数据库中存储contactType和status字段使用int,所以在这两个枚举类的value字段上加上@EnumValue注解。
最后在配置文件上加上:
mybatis-plus:
configuration:
default-enum-type-handler: org.apache.ibatis.type.EnumOrdinalTypeHandler
type-enums-package: com.txy.baiduPan.entity.enums
测试
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class test {
@Resource
private IUserContactService userContactService;
@Test
public void test(){
UserContact one = userContactService.getOne(new LambdaQueryWrapper<UserContact>().eq(UserContact::getUserId, "1111111"));
System.out.println(one.getStatus());
}
}