New file |
| | |
| | | package com.hx.mybatisTool; |
| | | |
| | | import com.hx.util.StringUtils; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 入参的list拼接数据 |
| | | * |
| | | * @author fwq |
| | | */ |
| | | public class SqlStringTool { |
| | | |
| | | /** |
| | | * @param sql sql语句 |
| | | * @param tableColumn 含别名表字段 |
| | | * @param dataList 要循环的数值 |
| | | * @param sqlMap sql语句对应的参数Map |
| | | */ |
| | | 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语句对应的参数Map |
| | | */ |
| | | 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(" ) "); |
| | | } |
| | | |
| | | } |
| | | |
| | | |