提交 | 用户 | age
|
fd90c2
|
1 |
package com.hx.mybatisTool; |
F |
2 |
|
|
3 |
import com.hx.util.StringUtils; |
|
4 |
|
|
5 |
import java.util.List; |
|
6 |
import java.util.Map; |
|
7 |
|
|
8 |
/** |
|
9 |
* 入参的list拼接数据 |
|
10 |
* |
|
11 |
* @author fwq |
|
12 |
*/ |
|
13 |
public class SqlStringTool { |
|
14 |
|
|
15 |
/** |
|
16 |
* @param sql sql语句 |
|
17 |
* @param tableColumn 含别名表字段 |
|
18 |
* @param dataList 要循环的数值 |
|
19 |
* @param sqlMap sql语句对应的参数Map |
|
20 |
*/ |
|
21 |
public static void handleList(StringBuilder sql, String tableColumn, List<String> dataList, Map<String, Object> sqlMap) { |
|
22 |
if (sql == null || StringUtils.isEmpty(tableColumn) || dataList == null || dataList.size() < 1) { |
|
23 |
return; |
|
24 |
} |
|
25 |
sql.append(" AND ").append(tableColumn).append(" IN ( "); |
|
26 |
for (int i = 0; i < dataList.size(); i++) { |
|
27 |
sql.append("#{m.").append("key").append(i).append("}").append(","); |
|
28 |
sqlMap.put("key" + i, dataList.get(i)); |
|
29 |
} |
|
30 |
sql.deleteCharAt(sql.length() - 1).append(" ) "); |
|
31 |
} |
|
32 |
|
|
33 |
/** |
|
34 |
* @param sql sql语句 |
|
35 |
* @param tableColumn 含别名表字段 |
|
36 |
* @param dataList 要循环的数值 |
|
37 |
* @param sqlMap sql语句对应的参数Map |
|
38 |
*/ |
|
39 |
public static void handleList(StringBuffer sql, String tableColumn, List<String> dataList, Map<String, Object> sqlMap) { |
|
40 |
if (sql == null || StringUtils.isEmpty(tableColumn) || dataList == null || dataList.size() < 1) { |
|
41 |
return; |
|
42 |
} |
|
43 |
sql.append(" AND ").append(tableColumn).append(" IN ( "); |
|
44 |
for (int i = 0; i < dataList.size(); i++) { |
|
45 |
sql.append("#{m.").append("key").append(i).append("}").append(","); |
|
46 |
sqlMap.put("key" + i, dataList.get(i)); |
|
47 |
} |
|
48 |
sql.deleteCharAt(sql.length() - 1).append(" ) "); |
|
49 |
} |
|
50 |
|
|
51 |
} |
|
52 |
|
|
53 |
|