mybatisplus中使用@TableField注解类型转换数据库数组与json类型字段
官网文档: https://mp.baomidou.com/guide/typehandler.html
必须在实体里面加上 @TableName(autoResultMap = true),不然无效
只要在对应字段加上注解就可以:
@TableName(autoResultMap = true)
public class BlogUser implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private String name;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
private Integer version;
@TableField(typeHandler= JsonTypeHandler.class)
private Map<String,Object> relation;
@TableField(typeHandler= ArrayTypeHandler.class)
private List<String> fans;
还有一种就是直接在xml里面写,直接引用,效果是一样的