1.pom文件引进maven
<groupId>com.baomidou
<artifactId>mybatis-plus-annotation
<version>3.2.0
<groupId>com.baomidou
<artifactId>mybatis-plus-extension
<version>3.2.0
</dependency>
2.实体加注解:实体前与JSONObject字段前
@TableName(autoResultMap = true)
public class W {
@TableField(typeHandler = FastjsonTypeHandler.class)
JSONObject ratingJson;
}
3.xml文件中加配置
<resultMap id="BaseResultMap(下面select引用的resultMap)" type="实体W路径" >
<result column="ratingJson(JSONObject字段名)"
property="ratingJson(JSONObject字段名)"
jdbcType="OTHER" javaType="com.alibaba.fastjson.JSONObject"
typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler" />
</resultMap>
<select id="getW" resultType="实体W路径" resultMap="BaseResultMap">
SELECT r.rating_json_ ratingJson FROM `waybill_rating_` r
</select>