---
title: "mybatis动态查询备忘"
author: "lhg4study"
date: "2013-05-29T11:39:28Z"
tags: []
categories: ["开源软件"]
slug: "mybatis"
draft: false
lastmod: "2013-05-29T11:39:28Z"
id: 1879298
url: "https://lhg4study.iteye.com/blog/1879298"
---

public List&lt;String&gt; selectByIds(Set&lt;String&gt; ids, String tableName) {  
        if (ids == null || ids.size() &lt;= 0 || StringUtils.isEmpty(tableName)) {  
            return null;  
        }  
        Map&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;();  
        map.put("tableName", tableName);  
        map.put("ids", ids);  
        return selectListWithMethodName(map);  
    }

 

&lt;select id ="selectByIds"  resultType="java.lang.String" parameterType="java.util.Map" &gt;  
         select   id from ${tableName}  
            where id in  
              &lt;foreach item="item" index="index" collection="ids" open="(" separator="," close=")"&gt;  
                        #{item}  
                &lt;/foreach&gt;  
&lt;/select&gt;