处理 sql in 多条件搜索时 单引号双引号问题
StringBuilder pidNoZeroIds = new StringBuilder();
Integer numTmp = 0;
for (ShequLsDatingType pidNoZero : pidNoZeroList) {
pidNoZeroIds.append("'" + pidNoZero.getId() + "'"); //拼接单引号,到数据库后台用in查询.
if ( numTmp < pidNoZeroList.size() - 1) { //前面的元素后面全拼上",",最后一个元素后不拼
pidNoZeroIds.append(",");
}
numTmp++;
}
Date date = new Date();
String simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd").format(date);
Map<Integer, Integer> usedNumByDatingTypeId = sysService.getUsedNumByDatingTypeId(pidNoZeroIds, simpleDateFormat);
<select id="getUsedNumByDatingTypeId" resultType="map">
SELECT dating_type_id AS datingTypeId,SUM(used_num) AS usedNum FROM shequ_ls_dating_times where dating_type_id IN (#{paramMap.dating_type_ids_str}) AND date = #{paramMap.now_date} GROUP BY dating_type_id;
</select>
标签:pidNoZeroIds,Java,自定义,date,mybatis,new,dating,type,id
From: https://www.cnblogs.com/wangjinkui/p/17083016.html