java 避免不同库使用left join查询速率低效 采用 sql 注入foreach 遍历list查询方式
(1)前端接受回用“,”拼接起来的字符串 String select_copy_ids
List<Integer> copyIds = DBUtil.getParamIntList(select_copy_ids);
List<Integer> roleIds = new ArrayList<Integer>();
List<DrillingRoleModel> copyRoleModels = drillingModelService.listDrillingRoleModelCopyById(copyIds);
public static List<Integer> getParamIntList(String value) throws Exception {
List<Integer> returnList = new ArrayList<Integer>();
if (StringUtils.isBlank(value)) {
return returnList;
} else {
try {
String[] idsStr = value.split(ConstUtil.SPLIT_DH);
for (String id : idsStr) {
returnList.add(Integer.parseInt(id));
}
} catch (Exception e) {
throw new Exception("处理提交请求参数:Int List类型异常,转换值value=" + value);
}
return returnList;
}
}
(3)数据库xml配置
<select id="listDrillingRoleModelCopyById" resultType="com.baofoo.admin.entity.data.drilling.DrillingRoleModel">
SELECT * FROM BAOFOO_ADMIN.drilling_role_model WHERE id IN (
<foreach collection="list" item="item" index="index" separator=",">
#{item}
</foreach>
)
</select>