SpringBoot+MybatisPlus 存json读json

发布时间 2023-12-04 13:14:34作者: 邹笑傲

基础环境

springboot 2.5.3
mysql 8.0.22
fastjson2 2.0.38

主要配置

1. 返回VO字段添加注解

    @ApiModelProperty("字段内容")
    @TableField(typeHandler = JacksonTypeHandler.class)
    private List<JSONObject> columnContent;

2. 返回Mapper中的resultMap中字段添加配置

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

查询效果


{
  "errcode": 200,
  "errmsg": "操作成功",
  "data": {
    "records": [
      {
        "id": 9,
        "columnContent": [
          {
            "id": 1,
            "name": "张三",
            "email": "xiaomimg@163.com",
            "tableName": "iot_person",
            "sourceName": "测试库1",
            "databasesName": "abd1"
          },
          {
            "id": "/",
            "name": "/",
            "email": "/",
            "table_name": "iot_person",
            "source_name": "测试库2",
            "databases_name": "abd2"
          }
        ],
        "recordUuid": "13a2b1d1a60549c78f5e2e461c91c00b"
      },
      {
        "id": 10,
        "columnContent": [
          {
            "id": 2,
            "name": "李四",
            "email": "xiaomimg@163.com",
            "tableName": "iot_person",
            "sourceName": "测试库1",
            "databasesName": "abd1"
          },
          {
            "id": 2,
            "name": "李四",
            "email": "lisi@163.com",
            "table_name": "iot_person",
            "source_name": "测试库2",
            "databases_name": "abd2"
          }
        ],
        "recordUuid": "13a2b1d1a60549c78f5e2e461c91c00b"
      }
    ],
    "total": 4,
    "size": 4,
    "current": 1,
    "orders": [],
    "optimizeCountSql": true,
    "searchCount": true,
    "countId": null,
    "maxLimit": null,
    "pages": 1
  }
}