1.通过url中的“?”传递参数对象,从页面传递参数到后台(分别是js代码,和后台代码),可以使用(@RequestParam("apArray") String[] apArray,@RequestParam("mapid") Integer mapid)
3.最常见的直接传递后台已有的model对象,在页面分装好之后直接将对象传递,但是要保证对象名maps一致。
function saveDeploy(){
var apArray = [];
<c:forEach items="${aplist}" var="apinfo">
var ap${apinfo.id} = $("#AP${apinfo.id}_X").val()+","+$("#AP${apinfo.id}_Y").val();
apArray.push(ap${apinfo.id});
</c:forEach>
for(var i=0; i<apArray.length;i++ ){
if(apArray[i] == ","){
alert("请部署所有AP");
return false;
}
}
$.ajax({
url:'<%=request.getContextPath()%>/maps/saveDeploy?apArray='+apArray+'&mapid='+mapid,
type:'post',
async:false,
error : function(data){
alert("部署失败!");
}
});
}
@RequestMapping("/saveDeploy")
public ModelAndView saveDeploy(@RequestParam("apArray") String[] apArray) throws Exception{
System.out.println(apArray.length);
for (int i = 0; i < apArray.length; i++) {
System.out.println(apArray[i]);
}
return null;
}
2.url直接传递参数,从页面直接传递mapsId这个参数到action
function getAps(mapsId){
jQuery.ajax({
url : '<%=request.getContextPath() %>/de/ap/aps/' + mapsId,
async : false,
success : function(data) {
var parseData = jQuery.parseJSON(data + "");
var listAp = jQuery.parseJSON(parseData.msg + "");//在此转换
$.each(listAp,function(index,d){
var ap = new Aps(this.id,this.x*28,this.y*28,this.angle);
ap.create();
});
}
});
}
@RequestMapping("/deploy/{mapsid}")
public ModelAndView deploy(@PathVariable Integer mapsid) throws Exception{
ModelAndView mv = new ModelAndView("DragMap/DragInMap");
List<ApInfo> aplist = apinfoService.findApByMaps(mapsid,1);
Maps map = this.mapsService.findByPK(mapsid);
mv.addObject("aplist", aplist);
return mv;
}
3.最常见的直接传递后台已有的model对象,在页面分装好之后直接将对象传递,但是要保证对象名maps一致。
@RequestMapping("/edit")
public ModelAndView edit(@ModelAttribute Maps maps) throws Exception{
ModelAndView mv = new ModelAndView("maps/addMaps");
Maps tmps = this.mapsService.findByPK(maps.getIds()[0]);
mv.addObject("maps", tmps);
return mv;
}