前后端互相传值

Posted hazsly

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了前后端互相传值相关的知识,希望对你有一定的参考价值。

前端到后端

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;
}















































以上是关于前后端互相传值的主要内容,如果未能解决你的问题,请参考以下文章

pbootcms对接微信扫码登录代码核心片段和步骤(前后端)

微信小程序和H5之间互相跳转互相传值

转:sqlplus与shell互相传值的几种情况

JSP页面之间互相传值

vue_父子组件互相传值

vue组件之间互相传值:父传子,子传父