前後端互相傳值
阿新 • • 發佈:2019-01-10
前端到後端:
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;
}