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 接管处理。

相关推荐
jzwugang3 小时前
postgresql链接详解
数据库·postgresql
bloglin999994 小时前
掌握解析JSON输出的技巧:使用LLM生成结构化数据
json
R***z1014 小时前
Spring Boot 整合 MyBatis 与 PostgreSQL 实战指南
spring boot·postgresql·mybatis
BduL OWED5 小时前
PostgreSQL常用时间函数与时间计算提取示例说明
数据库·postgresql
妄汐霜9 小时前
小白学习笔记(MyBatis)
笔记·学习·mybatis
TlYf NTLE11 小时前
PostgreSQL的备份方式
数据库·postgresql
Java成神之路-12 小时前
Spring 整合 MyBatis 全流程详解(附 Junit 单元测试实战)(Spring系列6)
spring·junit·mybatis
卡西里弗斯奥13 小时前
【海量数据库】参数设置与累积
数据库·postgresql·vastbase·海量数据库
百结2141 天前
PostgreSQL 初体验
数据库·postgresql
weixin_425023001 天前
PG JSONB 对应 Java 字段 + MyBatis-Plus 完整实战
java·开发语言·mybatis