Mybatis-plus + PostgreSQL json格式类型转换异常

前言

Mybatis Plus中自带很多Json类型处理器,在MySQL中直接使用没有任何问题,但在PostgreSQL中却报错:
Caused by: org.postgresql.util.PSQLException: 错误: 字段 "xxx" 的类型为 json, 但表达式的类型为 character varying

解决方案

用法上没有变化,仅在PostgreSQL 的url后追加参数stringtype=unspecified

yml 复制代码
spring:
  datasource:
    driver-class-name: org.postgresql.Driver
    url: jdbc:postgresql://localhost:5432/xxx?stringtype=unspecified

PostgreSQL 的 JDBC 驱动默认会把所有参数都当作varchar 类型发送。对于 JSON 字段,必须告诉驱动不要预设类型,让 MyBatis-PlusTypeHandler 接管处理。

相关推荐
摇滚侠1 小时前
《SpringBoot 3:入门与应用实战》第 13 章 整合 MyBatis MyBatis 简单开发 阅读笔记 39
spring boot·笔记·mybatis
java1234_小锋2 小时前
MyBatis-Plus 3.5.15 已全面支持 Spring Boot 4.0 及 Jackson 3.0
java·spring boot·mybatis
摇滚侠3 小时前
《SpringBoot 3:入门与应用实战》第 13 章 整合 MyBatis 使用 MyBatis-Plus 阅读笔记 40
spring boot·笔记·mybatis
oliver_sys_log17 小时前
老项目 json-lib 2.4 JSONTokener 精度丢失问题排查
json
数智启示录19 小时前
PostgreSQL 计划缓存实战(第 10 篇):预编译 SQL 前五次都快,第六次为什么可能变慢
经验分享·sql·缓存·postgresql·面试
IT_Octopus20 小时前
JSON 日志里的 `{“$ref“:“$.xxx“}`:从 fastjson 兼容包到原生 fastjson2 的迁移实录
开发语言·python·json
二进制漫游记1 天前
PostgreSQL超详细入门教程:Windows安装+Python异步连接+完整增删改查实战
python·postgresql
IvorySQL1 天前
基于 PostgreSQL 的非线性回归原理与 AI 数据库融合实践
数据库·人工智能·postgresql
赵渝强老师1 天前
【赵渝强老师】高斯数据库(openGauss)的数据库对象
数据库·postgresql·opengauss·国产数据库·高斯数据库
摇滚侠1 天前
《SpringBoot 3:入门与应用实战》第 13 章 整合 MyBatis MyBatis 概述 阅读笔记 37
spring boot·笔记·mybatis