您的位置:首页 > 编程语言 > Java开发

java 避免不同库使用left join查询速率低效 采用 sql 注入foreach 遍历list查询方式

2017-10-25 19:53 656 查看
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);


(2)将带“,”拼接字符串 装换为List
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sql查询高效
相关文章推荐