动态sql传集合參
传list集合:
传list集合
SQL:
<select id="queryDeptListByBankLevelAndBankName" parameterType="java.util.HashMap"
resultMap="queryDeptListByBankLevelAndBankNameResult">
select DEPTSEQ ,
DEPTNAME,DEPTID
from DEPT
WHERE 1=1
<if test="DeptLevel != null and DeptLevel != ''">And DeptLevel=#{DeptLevel}</if>
<if test="DeptName != null and DeptName != ''"> and DeptName LIKE '%' || #{DeptName} || '%'</if>
<if test="DeptSeq != null and DeptSeq != ''"> and DeptSeq=#{DeptSeq}</if>
<if test="deptIdList != null and deptIdList.size > 0 ">
and DEPTID not in
<foreach collection="deptIdList" item ="deptId" index="i" open="(" close=")" separator=",">
#{deptId}
</foreach>
</if>
ORDER BY DEPTID
</select>
接口:
ArrayList deptIdList = new ArrayList();
String [] deptIds = {"006001", "006002", "006003", "006004", "006005", "006006", "006007",
"006008", "006009", "006010", "006011", "006012", "006013", "006015",
"006016", "006017", "006018", "006019", "006020", "006021", "006022",
"006023", "006024", "006025", "006026", "006027", "006028", "006029",
"006030", "006031", "006032", "006033", "006034", "006035", "006036",
"006037", "006038", "006039", "006040", "006041", "006042", "006043",
"006044", "006045", "006501", "009801", "009802", "009803", "009809",
"009810", "009811", "014001", "015001", "016001", "016501", "019801",
"019802", "019803", "019804", "019805", "019806", "026501", "027006",
"027106", "027206", "027306", "027406", "027506", "029801", "036501",
"037006", "039801", "046501", "047006", "049801", "056501", "057006",
"809801", "059801", "066501", "067006", "069801", "076501", "077006",
"079801", "086501", "087006", "089801", "097006", "099801", "107006",
"109801", "117006", "117106", "119801", "127006", "129801", "806501",
"809801", "816501", "819801", "9802"};
Collections.addAll(deptIdList, deptIds);
Map map = new HashMap();
map.put("deptIdList",deptIdList);
subList = this.sqlMap.queryForList("mcmmcif.queryDeptListByBankLevelAndBankName", map);
传数组:
传数组:
SQL:
<select id="queryDeptListByBankLevelAndBankName" parameterType="java.util.HashMap"
resultMap="queryDeptListByBankLevelAndBankNameResult">
select DEPTSEQ ,
DEPTNAME,DEPTID
from DEPT
WHERE 1=1
<if test="DeptLevel != null and DeptLevel != ''">And DeptLevel=#{DeptLevel}</if>
<if test="DeptName != null and DeptName != ''"> and DeptName LIKE '%' || #{DeptName} || '%'</if>
<if test="DeptSeq != null and DeptSeq != ''"> and DeptSeq=#{DeptSeq}</if>
<if test="deptIdList != null and deptIdList.length > 0 ">
and DEPTID in
<foreach collection="deptIdList" item ="deptId" index="i" open="(" close=")" separator=",">
#{deptId}
</foreach>
</if>
ORDER BY DEPTID
</select>
接口:
String [] deptIds = {"006007","006010","006011","006024","006025","006034","006035","006037",
"016501","016601","016701","016801","016901","017001","017101","017201","017301","017401",
"017501","017601","017605","017701","017801","017901","018001","018101","018301","018401",
"018501","018601","018701","018801","018901","019001","019101","019201","019301","019401",
"019501","019802","019803","019804","019805","019806","026501","027001","027101","027201",
"027301","027401","027501","037001","047001","047002","057001","067001","077001","087001",
"097001","107001","117001","117101","127001","800101","800102","800103","810101","810102",
"810103"};
Map map = new HashMap();
map.put("deptIds",deptIds);
subList = this.sqlMap.queryForList("mcmmcif.queryDeptListByBankLevelAndBankName", map);