求助:接口参数传入的是json对象数组,如何存储到postgresql数据库jsonb类型字段呢?

Blade 已结 2 2157
asit
asit 2021-05-12 21:14
悬赏:20

求助:接口参数传入的是json对象数组,如何存储到postgresql数据库jsonb类型字段呢?

1、实体entity,字段类型如何定义呢?

private List imgUrls;

2、mybatis文件xml属性文件如何定义?


2条回答
  •  admin
    admin (楼主)
    2021-05-12 22:09

    凝练关键词可以到搜索引擎找到大量答案

    image.png

    作者追问:2021-05-12 22:09

    谢谢指点!根据第一搜索(https://www.cnblogs.com/liangyy/p/13573043.html)方法调整:

    1、Entity定义

    private Object imgUrls;


    2、mybatis plus中xml定义:

    <result column="img_urls" property="imgUrls" typeHandler="xx.common.hanlder.JsonTypeHandler" javaType="Object"/>


    执行后还是报错如下:

    nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='imgUrls', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #15 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #15 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of java.util.ArrayList. Use setObject() with an explicit Types value to specify the type to use.


    作者追问:2021-05-12 22:09

    <result column="img_urls" property="imgUrls" typeHandler="xxx.common.hanlder.JsonTypeHandler" javaType="Object"/>


    作者追问:2021-05-12 22:09

    <result column="img_urls" property="imgUrls" typeHandler=".common.hanlder.JsonTypeHandler" javaType="Object"/>


    作者追问:2021-05-12 22:09

    <result column="img_urls" property="imgUrls" typeHandler="xx.common.hanlder.JsonTypeHandler" javaType="Object"/>

提交回复