Ibatis批量处理
Posted zslm___
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ibatis批量处理相关的知识,希望对你有一定的参考价值。
1.插入
<insert id="insTable" resultClass="int"> INSERT INTO [dbo].[table] ([Id] ,[FId],[IsDel],[CreateTime] ) VALUES <iterate conjunction="," open="" close=""> (#[].Id# ,#[].FId# ,0 ,GETDATE() ) </iterate> </insert>
2.读取
<select id="queryTable" resultMap="Table" parameterClass="List"> select Id, FId, CreateTime from Table (nolock) where IsDel=1 and [Id] in <iterate open="(" close=")" conjunction=","> #[]# </iterate> </select>
3.修改
<update id="updateTable" parameterClass="list"> begin <iterate conjunction=""> update TABLE set Fid=#[].FId# where id = #[].Id#; </iterate> end; </update>
var tables = new List<Table>() { {new Table() {Id = 1, FId = "100"}}, {new Table() {Id = 2, FId = "102"}}, }; this.mapper.Update("updateTable", tables);
4.删除
<delete id="delTable" parameterClass="List"> delete from TABLE where id in <iterate conjunction="," open="(" close=")"> #[]# </iterate> </delete>
var ids=new List<int>(){2,3,4}; this.mapper.Delete("delTable", ids);
以上是关于Ibatis批量处理的主要内容,如果未能解决你的问题,请参考以下文章