码迷,mamicode.com
首页 > 其他好文 > 详细

前后端互相传值

时间:2019-01-10 12:06:22      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:rup   delete   get   str   als   gets   通过   close   mapping   

前端到后端

1.用AJAXdata传值,后端用实体类对应对象或者HttpServletRequest 接收String类型字段,如:


@ResponseBody
@RequestMapping("/insertOrUpdate")
public Object insertOrUpdate(Collecter collecter,HttpServletRequest request){
collecterService.insertOrUpdate(collecter);
int i;
String wgh = request.getParameter("wgh");
if(null!=wgh && ""!=wgh){
collGridService.deleteByUserCode(collecter.getId());
String[] wghArray =wgh.split(",");
for(i=0;i<wghArray.length;i++){
CollGrid collGrid = new CollGrid();
collGrid.setUserCode(collecter.getId());
collGrid.setWorkGridCode(wghArray[i]);
collGridService.insertOrUpdate(collGrid);
}
}
return null;
}

2.layui等插件弹出框url跳转路径后拼接属性和值,如:

/** 新增部门信息弹窗操作*/
$(‘#add‘).click(function () {
parent.layer.open({
type: 2,
closeBtn: 1, //显示关闭按钮
anim: 1,
shade: 0.3,
title: "新增职能部门",
shadeClose: false,
area: [‘1000px‘, ‘500px‘],
shift: 1,
scrollbar: false,
content:$path(‘/depart/addDepartHtml?departName=‘ + $("#departName").val() + ‘&departCode=‘ + $("#departCode").val()),
end:function () {
var tDepartCode = parentTree.ltree.getSelectedNode().departCode;
lTree.refreshSelectedParentNodes();
lTree.refreshChildNodes(lTree.zTree.getNodesByParam("departCode", tDepartCode)[0].tId);
parentTree.ltree.zTree.reAsyncChildNodes(null, "refresh");
}
});
});

后端到前端

1.通过ModelAndView,Model赋值<K,V>,view客户端跳转url,如:

@GetMapping("/addDepartHtml")
public ModelAndView addDepartHtml(HttpServletRequest request){
ModelAndView model = new ModelAndView("yywh/depart/addDepart");
model.addObject("parentName",request.getParameter("departName"));
model.addObject("departCode",request.getParameter("departCode"));
/** 生成部门排序号*/
Long orderNum = Long.valueOf(request.getParameter("departCode"));
model.addObject("orderNum",departService.createOrderNum(orderNum));
return model;
}

前后端互相传值

标签:rup   delete   get   str   als   gets   通过   close   mapping   

原文地址:https://www.cnblogs.com/hazsly/p/10249050.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!