ibatis mysql in_ibatis mapper文件in参数赋值方法

1.在使用ibatis执行下面的sql:

update jc_jiesuan set doing_time = unix_timestamp(curdate()),doing_status = ?           where id in (?) and current_oprerate_type = ?

2.传入的参数是:

Parameters: [1, 444475305,444475300,444475297,444475299, 3]

Types: [java.lang.Integer, java.lang.String, java.lang.Integer]

3.报错信息为:

org.springframework.dao.DataIntegrityViolationException: SqlMapClient operation; SQL [];

--- The error occurred in com/chl/dao/ibatis/sqlMap/sc_jiesuan-sqlmap.xml.

--- The error occurred while applying a parameter map.

--- Check the updateJiesuanDoingStatus-InlineParameterMap.

--- Check the statement (update failed).

--- Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: '444475305,444475300,444475297,444475299'; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:

二、解决方法:

1.使用“$”

通常在ibatis中传入参数使用的是“#”,如#currentOprerateType:INTEGER#

如果要想in中传入参数,则需要使用“$”符号。

update jc_jiesuan set doing_time = unix_timestamp(now()),doing_status = #doingStatus:INTEGER#

where id in ($ids$)  and current_oprerate_type = #currentOprerateType:INTEGER#

但这种方式会增加系统被入侵的可能,因为'$'这个符号会将传进来的值直接组合成查询语句,这样很容易被Sql注入攻击。

2.使用iterate属性。

Iterate:这属性遍历整个集合,并为 List 集合中的元素重复元素体的内容。

Iterate 的属性:

prepend  - 可被覆盖的 SQL 语句组成部分,添加在语句的前面(可选)

property  - 类型为 java.util.List 的用于遍历的元素(必选)

open  -  整个遍历内容体开始的字符串,用于定义括号(可选)

close  -整个遍历内容体结束的字符串,用于定义括号(可选)

conjunction -  每次遍历内容之间的字符串,用于定义 AND 或 OR(可选)

示例一:

SELECT * FROM USERS WHERE USER_ID IN

#ids[]#

ids:为传入List的名称

示例二、

delete from 表名 where  sex=#sex#

close=")" conjunction="or">

age=$personList[].age$

输出sql如下:

delete from 表名 where sex='man' and (age =11 or age=12)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值