使用ibatis时 sql中 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 id="updateJiesuanDoingStatus" parameterClass="java.util.HashMap">
        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 id="selectByIterate" parameterClass="java.util.List" resultClass="user">

SELECT * FROM USERS WHERE USER_ID IN

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

  #ids[]#

</iterate>

</select>

示例二、

<!-- 删除性别为man,年龄为 11,12 的Person记录,删除相应的person记录 -->
<delete id="deletePerson" parameterClass="map">
delete from 表名 where  sex=#sex# 
<iterate prepend="and" property="personList" open="("
close=")" conjunction="or">
age=$personList[].age$
</iterate>
</delete>

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

 

参考资料:http://hongzhguan.iteye.com/blog/1222353

转载于:https://www.cnblogs.com/sunzhenchao/archive/2012/12/03/2799365.html

Workbench中直接调用ICEM CFD进行网格划分 自从ANSYS 12.0之后,ICEM CFD就从Workbench中被分离出去,作为一个独立的程序使用了。取而代之的是Meshing模块。 在Meshing的属性节点菜单中右键点击Mesh,选择Insert > Method,插入方法。 选择需要划分网格的几何体,点击apply。此时Geometry显示为1 Body。 设置Method为MultiZone,如果不设置成这个的话,找不到进入ICEM CFD的入口。如果要划分四面体,可以在Mapped Mesh Type中选择其他类型。 阅读详情

相关推荐

从专利库到Zemax:一个6mm定焦镜头从零到交付的完整设计流程(含CodeV转换技巧)

本文详细介绍了6mm定焦镜头从专利库检索到最终交付的全流程设计,重点解析了CodeV与Zemax工具链的无缝衔接技巧。通过实际案例展示规格定义、专利筛选、结构适配、非球面优化等关键步骤,帮助光学设计工程师提升设计效率和制造良率。特别包含CodeV转换Zemax的实用技巧,适用于机器视觉和安防镜头开发。

weixin_42561040的博客 161

java mapper in_Java-MyBatis-杂项: MyBatis 中 in 的用法2

一、简介在SQL语法中如果我们想使用in的话直接可以像如下一样使用:select * from HealthCoupon where useType in ( '4' , '3' )但是如果在MyBatis中的使用in的话,像如下去做的话,肯定会报错:MapselectByUserId(@Param("useType") String useType)select * from HealthCou...

weixin_34964950的博客 1519

磁盘I/O %util特别高

磁盘I/O %util特别高

eagle89的专栏 3088

mybatis的Mapper文件中IN条件的传值方式-foreach

在写查询语句的时候,用到了IN,IN后面的条件需要我传参实现,我开始的时候是直接拼接的字符串,发现不对,查询的不正确,后来想起来foreach,但是具体的使用有点模糊了,我又去查询了资料,对佛foreach右重新了解了一边。 foreach属性: item:表示集合或者数组中的数,[1,2,3]在循环的时候分别为1 2 3,如果集合中是对象,那么这个 item就是其中的每一个对象,我们可以使用it...

weixin_40583191的博客 3821

LangFuse部署与实践

LangFuse的原理主要是基于可观察性和分析技术来监控和优化低延迟消息(LLM)应用。它提供了一套完整的解决方案,通过收集、处理和分析LLM应用在运行过程中产生的各种数据,来生成实时的、深入的、可操作的见解。通过提供实时的、深入的见解和可视化的跟踪功能,LangFuse使得识别和解决应用性能问题变得更加简单和高效。总的来说,LangFuse的原理是通过综合运用可观察性和分析技术,来提供对LLM应用的全面监控和优化能力。这使得开发者和运维团队能够更加高效地管理和维护他们的应用,从而提升用户体验和业务效益。

pumpkin84514的博客 7939

在Windows 10/11上使用Qt和SOEM构建EtherCAT主站:工业控制新纪元

☑️ Windows平台上的EtherCAT主站☑️ 微秒级精度的实时控制☑️ 动态设备配置与管理☑️ 直观的Qt监控界面☑️ 分布式时钟同步“技术不是取代人类的工具,而是拓展人类能力的翅膀。当我们在Windows上实现微秒级精度的工业控制时,不是在征服机器,而是在创造人与机器和谐共舞的新舞台。集成AI异常检测算法支持EtherCAT G协议云端监控与远程诊断完整项目代码预编译SOEM库示例视频教程。

QQ_778132974的博客 633

关于mapper中SQL条件的使用

关于mapper中SQL条件的使用

snowolflame的博客 2242

在zcu102开发板上使用PetaLinux运行Qt程序

请注意,上述步骤只是一个概述,并且可能需要根据特定的开发环境和要求进行适当的调整。如果你是一个初学者或者对于这些领域不太熟悉,建议在尝试之前阅读相关的文档和教程,或者寻求专业人士的帮助。在"Projects"菜单中,选择"Build & Run"选项,并在"Build"步骤中选择正确的工具链。注意:如果Qt程序依赖于其他库文件,需要将这些库文件一起复制到PetaLinux工程的根文件系统目录中,并在Qt程序中正确地配置库文件路径。如果一切顺利,PetaLinux系统将启动,并自动运行Qt程序。

UhxzCombined的博客 698

mybatis中的mapper.xml中如何使用in方法

项目场景:mybatis中的mapper.xml中如何使用in方法 提示:mapper.xml中如何使用in方法一般都是like或= 解决方案:见SQL 提示:使用foreach <if test="List != null and List.size()!=0 "> and list in <foreach collection="List" item="item" index="index" open="(" close=")" separator=","> #{item

weixin_43949154的博客 1万+

深入理解 Terraform 中的资源更新与管理

摘要:本文探讨Terraform处理AWS安全组名称变更时的行为。当修改不可变属性(如安全组名称)时,Terraform会创建新资源并删除旧资源。通过状态文件比对所需状态与实际状态,Terraform对不可变属性采用"先创建后删除"策略,对可变属性则直接更新。实例演示了修改安全组名称和关联EC2实例时的处理过程,强调理解资源属性可变性对基础设施管理的重要性。(149字)

2501_90323865的博客 471

2026国内Claude Code保姆级教程:安装、避坑、防串台全优化

安装 Claude Code CLI + 切换 npm 国内镜像优先配置固定关闭:自动联网、自动项目扫描VSCode 内置终端直接用,不装多余插件会话隔离+指令约束,彻底解决 Rust、小程序 跨语言串台。

lpfasd123的博客 2543

ibatis mysql in_使用ibatis时 sql中 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,44447...

weixin_36474795的博客 314

YOLO11全网首发:CVPR2026 Transformer注意力 | BinaryAttention 1-bit注意力,推理提速100%,超越FlashAttention2

本文改进:BinaryAttention 结合YOLO11的C3k2模块,全网首发创新。

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 853

ibatis中使用in写SQL语句

对于快速学习ibatis而没有过多时间去查阅资料的朋友,比如我,可能有些东西不一定能在快速上手的文档中涉猎到。今天就碰到一个问题,要在分页查询的同时进行where语句删选操作。由于表记录比较少,因此采用了in语句,但是in语句所设计的字段是number型的,因此在拼凑出in后面括号所需的内容时,出现了错误。说内容不是数字还是说不能为字符串,有点忘了,反正就是吧拼凑的in里的内容当成字符串‘’了。

smithdoudou88的专栏 2343

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

ibatis获取运行时的动态SQL语句及其参数

从离职的同事那里接手了一个项目开始改bug,然后就接触到了ibatis。然后有个bug是查询到的数据和预期的不一样,改来改去还是不一样。最后只能祭出杀手锏,把ibatis运行时的动态SQL打印出来,发现SQL语句压根就没刷新啊,摔。咳咳,下面讲如何获取ibatis运行时的动态SQL以及其参数。 假设我想获得这段调了ibatis接口的java代码所执行的sql语句以及其参数: n = (

You can't stand me now 4896

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

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,44...

weixin_31100203的博客 377

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

ibatis 使用文档 (上篇)

(代码下载地址:http://download.youkuaiyun.com/detail/partner4java/4760043) iBATIS一词来源于“internet”和“abatis”的组合,是一个基于Java的持久层框架。 创建于2002年,后很快加入了Apache,但是2010年又易主到google code,并改名为MyBatis。 本篇文章主要是基于iBATIS来进行展示,后面会再发

java相关技术(partner4java专栏)希望对您的学习有所帮助 4286

IBatis SqlParameter参数数量超过2100报错

在使用IBatis框架时,绝大多数情况下都不会出现传入参数超过限制的

bigheadsheep的专栏 4366

ibatis中写SQL语句时使用in遇到的问题描述

UPDATE CHUNQIU3.order_head t SET t.status = #flag# WHERE t.id in (#orderIds#) 传递的id为2488877,2488878,2488879。但是数据却没有任何的修改。 因为iBATIS默认会把“#”中间的变量作为字符串来处理。这样,就会出现这样的SQL UPDATE CHUNQIU3.order_head t

xiaoyong8823的专栏 952

IBATIS总结

iBATIS 学习总结 一、        了解iBATIS 1.什么是iBATIS “一个映射层,在对象和数据库间传递数据,并保持两者与映射层本身独立”  iBatis 不是直接在类和数据表或字段与列之间进行关联,而是把SQL语句的参数和返回结果映射至类。iBatis是出于类和数据表之间的一个中间层。这使得它在类和数据表之间进行映射时更加灵活。 iBATIS 是把SQL语句的参数和返回

duci2的专栏 2505

iBATIS中使用List做参数生成in语句

  iBATIS中使用List做参数生成in语句    有时候需要使用List做参数,将List的内容用来生成含"in"的SQL语句,sqlMap写法如下:   [java] view plaincopy &lt;select id="getHdRiskByCodes" parameterClass="java.util.ArrayList" result...

Pb_cctv的专栏 299

iBATIS SQL Maps(一)

前段时间写了些 Hibernate 方面的系列文章,网友们反映还不错。在接下来的时间里,我将会引入另外一种 O/R Mapping 解决方案——iBATIS,本系列将沿用 Hibernate 系列文章的风格。什么是 iBATIS ?    和众多的 SourceForge 开源项目一样,iBATIS 曾经也是其中的一员。在2004年11月3日成功地成为了 Apache Incubator 下的子项

成都心情 7239

在IBATIS中配置SQL语句的IN方式

在使用IBATIS进行SQL语句配置查询时,我们一定会遇到通过IN查询的地方,在使用IN查询时我们可以有两种方式进行配置参数:String和List。具体使用方式如下: 1.String:定义一个String的参数userIds,把这个参数传入IBATIS的sql配置文件,sql语句就可以这样写: #user...

XinhuaShuDiao的博客 404

ibatis动态SQL与非动态条件相结合,在参数均不符条件时报错的解决办法!

    在使用ibatis的过程中,很多时候要用的动态SQL,特别是where由为常用。  但是大家在用的时候,就会发现如果全部是带参数的动态条件是一点问题也不会有的,但如果我想以一个写死的条件与动态条件相结合的方式进行查询,我们就会发现动态参数全都不合条件的时候就会出现SQL异常。  select * from news t,category s

bingwang08的专栏 2019

ibatis中sql xml的基础写法

ibatis中sqlxml的基础写法 在工作中整理的ibatis sql配置文件的一些基础写法。 ibatis sql xml文件基本构成 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd"> <sqlMap namespace="USER">

lewenson的博客 1670
上一篇: 利用SecureCRT录制linux脚本
下一篇: 敏捷宣言和敏捷原则
dly41721
博客等级 码龄12年 1粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值