sql语句查询多条数据 sql查询多个数据



文章插图
sql语句查询多条数据 sql查询多个数据

文章插图
mybatis的批量更新操作
我们知道mybatis的插入和删除是可以支持批量操作的,但是update也是支持的,代码如下:
<update id="updateAll" parameterType="java.util.List"><foreach collection="list" item="it" index="index" open="" close="" separator=";">update SYSTEM_EXPERT_LIBRARYSET 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="http://www.mnbkw.com/jxjc/190128/jdbc:mysql://10.3.3.133:6789/test?allowMultiQueries=true&useUnicode=true&characterEncoding=utf-8"/><property name="username" value="http://www.mnbkw.com/jxjc/190128/test"/><property name="password" value="http://www.mnbkw.com/jxjc/190128/test"/><!-- 配置监控统计拦截的filters --><!-- <property name="filters" value="http://www.mnbkw.com/jxjc/190128/stat,log4j,wall"/> 这种配置不支持批量更新语句--></bean>还有重要的一点是要默认开启支持批量修改操作
Url拼接?allowMultiQueries=true
jdbc.driverClassName=com.mysql.cj.jdbc.Driverjdbc.url=jdbc:mysql://:3306/xx?allowMultiQueries=truejdbc.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>
【sql语句查询多条数据 sql查询多个数据】<insert id="insertAll" parameterType="java.util.List" useGeneratedKeys="false">insert into SYSTEM_EXPERT_LIBRARY<foreach collection="list" item="it" index="index" separator=",">()</foreach></insert>