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里面写,直接引用,效果是一样的


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM