凝练关键词可以到搜索引擎找到大量答案
谢谢指点!根据第一搜索(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.
<result column="img_urls" property="imgUrls" typeHandler="xxx.common.hanlder.JsonTypeHandler" javaType="Object"/>
<result column="img_urls" property="imgUrls" typeHandler=".common.hanlder.JsonTypeHandler" javaType="Object"/>
<result column="img_urls" property="imgUrls" typeHandler="xx.common.hanlder.JsonTypeHandler" javaType="Object"/>
原文引用:
https://blog.csdn.net/qq_31183727/article/details/108273293
1、数据库链接 URL配置
先在 postgreSql 的数据库 URL 后面加上 &stringtype=unspecified
postgreSql:
name: public
url: jdbc:postgresql://127.0.0.1:5432/test_db?&allowMultiQueries=true&autoReconnect=true&stringtype=unspecified
2、实体类配置
@TableName
加上 autoResultMap = true
例如:
@TableName(value = "form_detail", autoResultMap = true)
@TableField
加上 typeHandler = JacksonTypeHandler.class,这里我用的是Jackson的
fastjson 可以使用 FastjsonTypeHandler.class
Gson 可以使用 GsonTypeHandler.class
例如:
@TableField(value = "form_json", typeHandler = JacksonTypeHandler.class)
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)
@TableName(value = "form_detail", autoResultMap = true)
public class FormDetail extends Model<FormDetail> {
private static final long serialVersionUID = 1L;
/**
* 表单key
*/
@TableId(value = "form_key", type = IdType.ASSIGN_UUID)
@ApiModelProperty(value = "表单key,主键")
private String formKey;
/**
* 表单内容json串
*/
@TableField(value = "form_json", typeHandler = JacksonTypeHandler.class)
@ApiModelProperty(value = "表单内容json串")
private Object formJson;
/**
* 修改时间
*/
@TableField("update_time")
@JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss", timezone = "GMT+8")
private Date updateTime;
@Override
protected Serializable pkVal() {
return this.formKey;
}
}
3、XML配置
如果使用 resultMap ,则也需要添加 typeHandler
<resultMap id="BaseResultMap" type="com.wpg.common.entity.ticket.FormDetail">
<id column="form_key" property="formKey"/>
<result column="form_json" property="formJson" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
</resultMap>
扫一扫访问 Blade技术社区 移动端