sql批量查询多条数据(sql数据库查询语句大全)
程序员文章站
2023-11-27 16:51:58
mybatis的批量更新操作我们知道mybatis的插入和删除是可以支持批量操作的,但是update也是支持的,代码如下:
mybatis的批量更新操作
我们知道mybatis的插入和删除是可以支持批量操作的,但是update也是支持的,代码如下:
<update id="updateall" parametertype="java.util.list">
<foreach collection="list" item="it" index="index" open="" close="" separator=";">
update system_expert_library
set user_code = #{it.usercode,jdbctype=varchar},
expert_name = #{it.expertname,jdbctype=varchar},
expert_sex = #{it.expertsex,jdbctype=char},
expert_mail = #{it.expertmail,jdbctype=varchar},
expert_address = #{it.expertaddress,jdbctype=varchar},
expert_card = #{it.expertcard,jdbctype=varchar},
expert_phone = #{it.expertphone,jdbctype=varchar},
expert_xilie = #{it.expertxilie,jdbctype=varchar},
specialty = #{it.specialty,jdbctype=varchar},
status = #{it.status,jdbctype=varchar},
updater = #{it.updater,jdbctype=varchar}
where id = #{it.id,jdbctype=integer}
</foreach>
</update>
注意批量更新的时候,如果使用了druid数据源,则配置的时候要注意:不能配置wall拦截器,否则批量更新不成功。
<bean id="datasource" class="com.alibaba.druid.pool.druiddatasource"
init-method="init" destroy-method="close">
< property name="url" value="jdbc:mysql://10.3.3.133:6789/test?allowmultiqueries=true&
useunicode=true&characterencoding=utf-8"/>
<property name="username" value="test"/>
<property name="password" value="test"/>
<!-- 配置监控统计拦截的filters -->
<!-- <property name="filters" value="stat,log4j,wall"/>
这种配置不支持批量更新语句-->
</bean>
还有重要的一点是要默认开启支持批量修改操作
url拼接?allowmultiqueries=true
jdbc.driverclassname=com.mysql.cj.jdbc.driver
jdbc.url=jdbc:mysql://:3306/xx?allowmultiqueries=true
jdbc.username=
jdbc.password=
mybatis的批量新增删除
<delete id="deletebatch">
delete from t_acl where id in
<foreach collection="list" index="index" item="item"
separator="," open="(" close=")">
#{item.id}
</foreach</delete>
<insert id="insertall" parametertype="java.util.list"
usegeneratedkeys="false">
insert into system_expert_library
<foreach collection="list" item="it" index="index" separator=",">
( )
</foreach>
</insert>