1.Map动态传参方式(以创建表为例,需要动态传入表名称)
步骤1:将Mapper层 createtable的形参改为Map类型
// Mapper接口
public interface GisPoiMapper{
void createTable(Map<String,Object> args);
}
步骤2:在service实现层创建Map,put需要传入的参数
public R createTable(String strTableName) {
Map<String, Object> args = new HashMap<String, Object>();
args.put("tabName", strTableName);
gisPoiMapper.createTable(args);
return null;
}
步骤3:在对应的mapper.xml层中编写sql语句
<update id="createTable" parameterType="hashmap" statementType="STATEMENT">
CREATE TABLE ${tabName}
(
)
</update>
2.Map动态传参方式(同时传入集合参数(需要遍历)和其他参数)
以Map传参形式 传入tableName参数 和 ids 集合
public R batchRemove(Long[] ids) {
Map<String, Object> param = new HashMap<String, Object>() {
};
String strTableName = getLatestVerisonName();
param.put("tableName", strTableName);
param.put("ids", ids);
int count = gisPoiMapper.batchRemoveFromTable(param);
return CommonUtils.msg(ids, count);
}
再Mapper.xml中
<delete id="batchRemoveFromTable" parameterType="hashmap">
DELETE
FROM
${tableName}
WHERE
poi_id IN
<foreach item="id" collection="ids" open="(" separator="," close=")">
${id}
</foreach>
</delete>