MyBatis-Plus 扩展-字段类型处理器

类型处理器,用于 JavaType 与 JdbcType 之间的转换,用于 ​PreparedStatement设置参数值和从 ​ResultSet或 ​CallableStatement中取出一个值,本文讲解 mybaits-plus 内置常用类型处理器如何通过TableField注解快速注入到 mybatis 容器中。

  • JSON 字段类型
@Data
@Accessors(chain = true)
@TableName(autoResultMap = true)
public class User {
    private Long id;

    ...


    /**
     * 注意!! 必须开启映射注解
     *
     * @TableName(autoResultMap = true)
     *
     * 以下两种类型处理器,二选一 也可以同时存在
     *
     * 注意!!选择对应的 JSON 处理器也必须存在对应 JSON 解析依赖包
     */
    @TableField(typeHandler = JacksonTypeHandler.class)
    // @TableField(typeHandler = FastjsonTypeHandler.class)
    private OtherInfo otherInfo;

}

该注解对应了 XML 中写法为

<result column="other_info" jdbcType="VARCHAR" property="otherInfo" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" />

作者:admin,如若转载,请注明出处:https://www.web176.com/mybatis-plus/20387.html

(0)
打赏 支付宝 支付宝 微信 微信
adminadmin
上一篇 2023年5月16日
下一篇 2023年5月16日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注