1.控制层
@PostMapping("mapInsert") public void mapInsert() { dictService.mapInsert(); }
2.业务层接口
void mapInsert();
3.业务层
@Override public void mapInsert() { Map<String, Object> map = new HashMap<>(); map.put("id",123123132); map.put("name","我是韩信"); map.put("date",new Date()); dictMapper.mapInsert(map); }
4.mapper只有map一个参数也必须加别名!!!!
void mapInsert(@Param("map") Map<String, Object> map);
5.XML
<insert id="mapInsert"> insert into t_test <foreach collection="map.entrySet()" index="key" item="value" open="(" close=")" separator=","> ${key} </foreach> VALUES <foreach collection="map.entrySet()" index="key" item="value" open="(" close=")" separator=","> #{value} </foreach> </insert>
postman