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 > 
        update jc_jiesuan set doing_time = unix_timestamp(now()),doing_status = #doingStatus:INTEGER# 
         where id in ($ids$)  and current_oprerate_type = #currentOprerateType:INTEGER# 
</update>

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

 

2.使用iterate属性。

Iterate:这属性遍历整个集合,并为 List 集合中的元素重复元素体的内容。 
Iterate 的属性: 
      prepend  - 可被覆盖的 SQL 语句组成部分,添加在语句的前面(可选) 
      property  - 类型为 java.util.List 的用于遍历的元素(必选) 
      open  -  整个遍历内容体开始的字符串,用于定义括号(可选) 
      close  -整个遍历内容体结束的字符串,用于定义括号(可选) 
      conjunction -  每次遍历内容之间的字符串,用于定义 AND 或 OR(可选)

示例一:

<select >

SELECT * FROM USERS WHERE USER_ID IN

<iterate conjunction="," open="(" close=")">

  #ids[]#

</iterate>

</select>

ids:为传入List的名称

示例二、

<!-- 删除性别为man,年龄为 11,12 的Person记录,删除相应的person记录 --> 
<delete > 
age=$personList[].age$ 
</iterate> 
</delete>

输出sql如下: 
delete from 表名 where sex='man' and (age =11 or age=12)

 

参考:http://www.cnblogs.com/sunzhenchao/archive/2012/12/03/2799365.html?ADUIN=834591479&ADSESSION=1406088598&ADTAG=CLIENT.QQ.5329_.0&ADPUBNO=26349

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 > 
        update jc_jiesuan set doing_time = unix_timestamp(now()),doing_status = #doingStatus:INTEGER# 
         where id in ($ids$)  and current_oprerate_type = #currentOprerateType:INTEGER# 
</update>

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

 

2.使用iterate属性。

Iterate:这属性遍历整个集合,并为 List 集合中的元素重复元素体的内容。 
Iterate 的属性: 
      prepend  - 可被覆盖的 SQL 语句组成部分,添加在语句的前面(可选) 
      property  - 类型为 java.util.List 的用于遍历的元素(必选) 
      open  -  整个遍历内容体开始的字符串,用于定义括号(可选) 
      close  -整个遍历内容体结束的字符串,用于定义括号(可选) 
      conjunction -  每次遍历内容之间的字符串,用于定义 AND 或 OR(可选)

示例一:

<select >

SELECT * FROM USERS WHERE USER_ID IN

<iterate conjunction="," open="(" close=")">

  #ids[]#

</iterate>

</select>

ids:为传入List的名称

示例二、

<!-- 删除性别为man,年龄为 11,12 的Person记录,删除相应的person记录 --> 
<delete > 
age=$personList[].age$ 
</iterate> 
</delete>

输出sql如下: 
delete from 表名 where sex='man' and (age =11 or age=12)

 

参考:http://www.cnblogs.com/sunzhenchao/archive/2012/12/03/2799365.html?ADUIN=834591479&ADSESSION=1406088598&ADTAG=CLIENT.QQ.5329_.0&ADPUBNO=26349

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-27
  • 2021-11-25
  • 2021-08-08
  • 2022-12-23
  • 2021-10-09
  • 2022-02-20
猜你喜欢
  • 2022-12-23
  • 2021-06-22
  • 2021-10-30
  • 2022-01-05
  • 2022-12-23
  • 2022-12-23
  • 2021-04-06
相关资源
相似解决方案