SpringMVC_MyBatis处理一对多数据组

来源:互联网 发布:摄影作品网站 知乎 编辑:程序博客网 时间:2024/05/29 15:37

假设情景,要更新一个元组,数据为(1,1),(1,2),(1,3) ,用一次合理的请求完成持久化。基于SSM。


URL

localhost:8080/ProjectName/bindPoleType?pid=1&poleid=1&poleid=2&poleid=3



Controller

@RequestMapping(value = "/bindPoleType",produces="text/html;charset=UTF-8")@ResponseBodypublic String bindCamType(@RequestParam(value="pid",required=false)Integer pid,@RequestParam(value="poleid",required=false)int[] poleid) throws JsonProcessingException{Map<String,Object> map = new HashMap<>();map.put("pid", pid);map.put("poleid", poleid);poleTypeMapper.insertPoleTypeProject(map);return "success";}


Dao

int insertPoleTypeProject(Map<String,Object> map);



Mapper

<insert id="insertPoleTypeProject" parameterType="map">insert into t_pole_project_type (pid, poleid) values<foreach collection="poleid" index="index" item="poleid" separator=",">( #{pid},#{poleid})</foreach></insert>




0 0