From fb6971d5af5445c974fdba918376ea1c1fab6fd4 Mon Sep 17 00:00:00 2001 From: fwq <582742538@qq.com> Date: 星期五, 20 九月 2024 16:00:21 +0800 Subject: [PATCH] Merge branch 'master-base' into master-stander --- src/main/java/com/hx/mybatisTool/SqlStringTool.java | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 53 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/hx/mybatisTool/SqlStringTool.java b/src/main/java/com/hx/mybatisTool/SqlStringTool.java new file mode 100644 index 0000000..e66a562 --- /dev/null +++ b/src/main/java/com/hx/mybatisTool/SqlStringTool.java @@ -0,0 +1,53 @@ +package com.hx.mybatisTool; + +import com.hx.util.StringUtils; + +import java.util.List; +import java.util.Map; + +/** + * 鍏ュ弬鐨刲ist鎷兼帴鏁版嵁 + * + * @author fwq + */ +public class SqlStringTool { + + /** + * @param sql sql璇彞 + * @param tableColumn 鍚埆鍚嶈〃瀛楁 + * @param dataList 瑕佸惊鐜殑鏁板�� + * @param sqlMap sql璇彞瀵瑰簲鐨勫弬鏁癕ap + */ + public static void handleList(StringBuilder sql, String tableColumn, List<String> dataList, Map<String, Object> sqlMap) { + if (sql == null || StringUtils.isEmpty(tableColumn) || dataList == null || dataList.size() < 1) { + return; + } + sql.append(" AND ").append(tableColumn).append(" IN ( "); + for (int i = 0; i < dataList.size(); i++) { + sql.append("#{m.").append("key").append(i).append("}").append(","); + sqlMap.put("key" + i, dataList.get(i)); + } + sql.deleteCharAt(sql.length() - 1).append(" ) "); + } + + /** + * @param sql sql璇彞 + * @param tableColumn 鍚埆鍚嶈〃瀛楁 + * @param dataList 瑕佸惊鐜殑鏁板�� + * @param sqlMap sql璇彞瀵瑰簲鐨勫弬鏁癕ap + */ + public static void handleList(StringBuffer sql, String tableColumn, List<String> dataList, Map<String, Object> sqlMap) { + if (sql == null || StringUtils.isEmpty(tableColumn) || dataList == null || dataList.size() < 1) { + return; + } + sql.append(" AND ").append(tableColumn).append(" IN ( "); + for (int i = 0; i < dataList.size(); i++) { + sql.append("#{m.").append("key").append(i).append("}").append(","); + sqlMap.put("key" + i, dataList.get(i)); + } + sql.deleteCharAt(sql.length() - 1).append(" ) "); + } + +} + + -- Gitblit v1.8.0