前端传参`
function onExportExcel() {
table.set('selectGroup-table');
$.modal.confirm("确定导出所有详细的数据吗?", function () {
$.modal.loading("正在导出数据,请稍后...");
$.post("collectionscharges/exports",
"chargeKindID=" + chageKindIDs+"&"
+ "outOperatorID="+ outOperatorIDs+"&"
+ "maxID="+maxIDs+"&"
+"minID="+minIDs, function (result) {
if (result.code == web_status.SUCCESS) {
window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
} else if (result.code == web_status.WARNING) {
$.modal.alertWarning(result.msg)
} else {
$.modal.alertError(result.msg);
}
$.modal.closeLoading();
});
});
}
后端接收参数
@RequiresPermissions("system:user:export")
@PostMapping("/exports")
@ResponseBody
public AjaxResult exports(@RequestParam(value = "chargeKindID",required = false)Integer chargeKindID,
@RequestParam(value = "outOperatorID",required = false)Integer outOperatorID,
@RequestParam(value = "maxID",required = false)Integer maxID,
@RequestParam(value = "minID",required = false)Integer minID) {
CollectionsChargesClassifiedStatisticsVO collectionsChargesClassifiedStatisticsVO = new CollectionsChargesClassifiedStatisticsVO();
if(chargeKindID != null){
collectionsChargesClassifiedStatisticsVO.setChargeKindID(chargeKindID);
}
if(outOperatorID != null ){
collectionsChargesClassifiedStatisticsVO.setOutOperatorID(outOperatorID);
}
if(maxID!=null){
collectionsChargesClassifiedStatisticsVO.setMaxID(maxID);
}
if(minID!=null){
collectionsChargesClassifiedStatisticsVO.setMinID(minID);
}
HttpSession session = getRequest().getSession();
collectionsChargesClassifiedStatisticsVO.setParams((Map<String, Object>) session.getAttribute("time"));
List<CollectionsChargesDetailVO> list = collectionsChargesDetailSercice.selectidname(collectionsChargesClassifiedStatisticsVO);
ExcelUtil<CollectionsChargesDetailVO> util = new ExcelUtil<CollectionsChargesDetailVO>(CollectionsChargesDetailVO .class);
return util.exportExcel(list, "车辆出入详细数据");
}
前端传参可一个null类型的值,通过json传入过去,但是前端接收的时候使用Interge和String都报错了,由于数据传输时,是不能直接传对象的,所以在真正传值的时候,要转换成JSON字符串,无论什么类型都要转换成字符串或数字。
等到后台接收到参数的时候,其实后台也不知道传过来的是什么类型,只能按照规定好的参数类型,尝试对字符串进行强制转换。
于是,如果出现了null,前台就只能转化成”null”,这就导致了后台只能接收到”null”,甚至无法区分null和”null”。
更严重的问题在于:如果后台接收的参数是数字类型(Long、Int、Double),而前台传入是null的话,由于字符串强制转换为数字失败,会直接导致后台500.并且前端使用不为null不能进行判断
所以在前端传值的时候就需要将null的去掉
function onExportExcel() {
table.set('selectGroup-table');
$.modal.confirm("确定导出所有详细的数据吗?", function () {
$.modal.loading("正在导出数据,请稍后...");
$.post("collectionscharges/exports",
(chageKindIDs == null ? "":("chargeKindID=" + chageKindIDs))+"&"
+ (outOperatorIDs == null ? "":("outOperatorID="+ outOperatorIDs))+"&"
+ (maxIDs == null ? "":("maxID="+maxIDs))+"&"
+(minIDs==null? "":("minID="+minIDs)), function (result) {
if (result.code == web_status.SUCCESS) {
window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
} else if (result.code == web_status.WARNING) {
$.modal.alertWarning(result.msg)
} else {
$.modal.alertError(result.msg);
}
$.modal.closeLoading();
});
});
}
版权声明:本文为hxbdc56原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。