SpringMVC_MyBatis處理一對多數據組

假設情景,要更新一個元組,數據爲(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")
	@ResponseBody
	public 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>




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章