mybatis多条件批量查询,插入
1、多条件批量查询
mapper:
List<MsAllocEntity> selectBatch(@Param(value = "reqList") List<ReqDTO> reqList);
xml:
<select id="selectBatch" resultMap="baseEntityMap"> select <include refid="Alloc_Line_Column_List" /> from MSTB_ALLOC where <foreach collection="reqList" item="req" open="(" close=")" separator=" or "> ( REGION_CODE = #{req.regionCode} and DIST_NUMBER = #{req.distNum} and ALLOC_CODE = #{req.allocCode} and KEY_CODE = #{req.keyCode} <if test="req.cycle != null"> and CYCLE = #{req.cycle} </if> <if test="req.cycle == null"> and (CYCLE is null or CYCLE = ) </if>) </foreach> </select>
2、单条件批量查询
mapper:
List<TsAllocLogItemEntity> queryLogItemByLogId(@Param(value = "params") Map<String, Object> params, @Param(value = "logIdMaps")List<Map<String, Object>> logIdList);
xml: <select id="queryLogItemByLogId" resultMap="baseTsLogItemMap"> select log.ID from TSTB_ALLOC_LOG_ITEM log where log.ALLOC_LOG_ID in <foreach collection="logIdMaps" item="map" open="(" close=")" separator=","> #{map.id} </foreach> limit #{params.page},#{params.pageSize} </select>
查询,修改,删除类似
3、批量插入
mapper:
int insertBatchQuotaLine(List<MsLineEntity> allocLineList);
xml:
insert id="insertBatchLine" parameterType="java.util.List"> insert into MSTB__LINE (ID, STATUS, CREATE_DATE, UPDATE_DATE, CREATOR, UPDATOR, VERSION, SYSN_STATUS, EFFECTIVE_DATE, EXPIRE_DATE, INIT_FLAG ) values <foreach collection="list" item="line" separator=","> (#{line.id},#{line.status}, NOW(), NOW(), #{line.creator}, #{line.updator}, #{line.version}, #{line.sysnStatus}, #{line.effectiveDate}, #{line.expireDate}, #{line.initFlag} ) </foreach> </insert>