一、针对mysql json 数据类型的读写坑
1、json字段数据类型映射
数据库存储object类型: com.alibaba.fastjson.JSONObject
数据库存储array类型:com.alibaba.fastjson.JSONArray
/**
* 注解的typeHandler只生效于insert和update,
* 要生效select必须TableName.autoResultMap=true
*/
@TableField(typeHandler = FastjsonTypeHandler.class,updateStrategy = FieldStrategy.IGNORED)
@ApiModelProperty(name = "equipmentInfo", value = "关联设备 [{'equipment_id':001}]")
private JSONArray equipmentInfo;
注意以上配置只能适用于mp自己的方法,对于mybatis,xml中自己写的方法不适用,返回类型如果需要做json处理需要。申明typeHandler
<resultMap type="com.cloud.business.model.ott.vehicleinfo.OttVehicleInfoModel" id="ottVehicleInfoViewMap">
<result property="objectId" column="object_id"/>
<result property="isDeleted" column="is_deleted"/>
<result property="createUserId" column="create_user_id"/>
<result property="createTime" column="create_time"/>
<result property="modificationUserId" column="modification_user_id"/>
<result property="modificationTime" column="modification_time"/>
<result property="vehicleName" column="vehicle_name"/>
<result property="licensePlate" column="license_plate"/>
<result property="brandInfo" column="brand_info" typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"/>
<result property="loadingCapacity" column="loading_capacity"/>
<result property="enumMedium" column="enum_medium"/>
</resultMap>
未完待续。。。。。