com.highgo.jdbc.util.PSQLException: 错误: 操作符不是唯一的: integer = character varying(mybatis postgreSql)

1545年前 (2021-05-11)瀚高数据库4228

postgresql抛出的异常,是因为数据库类型是int类型,而java传参String造成。有2种解决方案,建议第二种方案更方便简洁

image.png

解决方案一:

代码

public int deleteSysUserSignByIds(String ids) {
    return sysUserSignMapper.deleteSysUserSignByIds(Convert.toStrArray(ids));
}

XML:

<delete id="deleteSysUserSignByIds" parameterType="String">
    delete from sys_user_sign where id in
    <foreach item="id" collection="array" open="(" separator="," close=")">
        #{id}
    </foreach>
</delete>

而数据库的id类型是int类型

修改方案:

public int deleteSysUserSignByIds(String ids) {
    return sysUserSignMapper.deleteSysUserSignByIds(Convert.toLongArray(ids));
}

传入的string数组转换为integer数组或者long数据即可。

当然对应接口方法的接收参数类型也要做相应改变。

解决方案二:(只需修改下xml文件)

解决方案是在xml内将string类型的参数变量 强转为int类型,在变量后加::int

<delete id="deleteGoodsRecordByIds" parameterType="String">
    delete from goods_record where id in
    <foreach item="id" collection="array" open="(" separator="," close=")">
        #{id}::int
    </foreach>
</delete>


本文原创,转载必追究版权。

分享给朋友:

相关文章

js动态加载复选框checkbox(XML串)

 首先,使用JS动态产生Checkbox可以采用如下类似的语句:代码如下:var checkBox=document.createElement("input");che...

多说评论框怎么用更好

 1.隐藏屏蔽掉多说评论框的版权链接代码?简单css实现:多说隐藏版权链接,在后台自定义css添加:#ds-thread #ds-reset .ds-powered-by { display...

使用Myeclipse 8.5开发基于JAX-WS的Web service实例

 本文为Web service 开发入门篇,主要介绍在Myeclipse 8.5环境下开发Web service的服务程序和客户端程序的基本流程。 在Weblogic 11g...

freemarker 判断日期变量为空处理 及InvalidReferenceException异常处理

at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:98);InvalidR...

office 2010安装、激活、激活工具下载

office 2010安装、激活、激活工具下载

 首先下载好工具包(包括office 2010安装程序、激活工具及Microsoft .NET Framework 4.0),点击工具包下载进行下载;安装好office 2010。如果是wi...

Java判断是数字还是字符串

方法一:利用正则表达式public class Testone {public static void main(String[] ...

评论列表

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。