JSON的返回可以看这个博客 还是写的比较详细的 同时也是自己记录一下

MybatisPlus如何处理Mysql的json类型_java_脚本之家

以下为自己的实践:

1、使用 MybatisPlus的通用方法查询返回 JSON字段 如下

需要在实体类上加入 autoResultMap = true

需要在字段上加入  @TableField(typeHandler = JacksonTypeHandler.class)

typeHandler有多种使用方法 比如字符串List 但这里使用的是 List<Map>的

@Data
@ApiModel("合同台账")
@TableName(value = "tb_standing_book",autoResultMap = true)
public class StandingBook extends BaseEntity<StandingBook> {

    @ApiModelProperty("附件")
    @TableField(typeHandler = JacksonTypeHandler.class)
    private List<Map> attachments;

}

2、如果是在Xml中查询需要查询返回JSON字段 必须要进行一层  resultMap 映射进行配置 如下

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sh.tb.mapper.StandingBookMapper">

    <resultMap type="com.ksb.tb.dto.StandingBookDto" id="standingBookDto">
        <result property="attachments"    column="attachments"   typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" />
    </resultMap>

    
    <select id="standingBookPage"  resultMap="standingBookDto">
        select
        tb_standing_book.attachments as attachments,
        tb_standing_book.customer_no as customerNo,
        from tb_standing_book
    </select>

</mapper>

3、如果是JSON SQL查询 可以采用该SQL语句 ext_params 为JSON字段 currency 为JSON中的key值

AND JSON_EXTRACT(ext_params, '$.currency') = #{currency}

 备注一下Mybait 升级为 Plus的一次报错

注意看 SqlSessionFactory 是否有自定义配置 需要将Mybait的配置升级为 PLus
GitHub 加速计划 / js / json
57
5
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:1 个月前 )
c633693d Bumps [ossf/scorecard-action](https://github.com/ossf/scorecard-action) from 2.4.1 to 2.4.2. - [Release notes](https://github.com/ossf/scorecard-action/releases) - [Changelog](https://github.com/ossf/scorecard-action/blob/main/RELEASE.md) - [Commits](https://github.com/ossf/scorecard-action/compare/f49aabe0b5af0936a0987cfb85d86b75731b0186...05b42c624433fc40578a4040d5cf5e36ddca8cde) --- updated-dependencies: - dependency-name: ossf/scorecard-action dependency-version: 2.4.2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 21 小时前
cf16c5ab 1 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐