js判断返回值类型为空的情况下

时间:2021-02-05 19:18:42
js调用后台方法,返回值后判断是否为空,然后给input赋值
$.post("<%=basePath%>busVatLog/search/allListbyid.do"
,{"cust_id":$('#id').val(),"fee_month":$('#payMonth').val()}
,function(vatlog){
if($.isEmptyObject(vatlog)){//判断返回值类型为空的情况下
$('#fee_month1').val($('#payMonth').val());
}else{
alert(vatlog.fee_month);
}
}//end function
,'json');

后台方法,接受前台传递参数,并根据参数查找数据库对应数据,有数据就返回第一条数据,没有则返回空的map
@RequestMapping(value = "/busVatLog/search/allListbyid", produces = "application/json;charset=UTF-8")
public @ResponseBody Map<Object,Object> searchAllVatLogListbyid(@RequestParam String fee_month,@RequestParam String cust_id) {
Map<String,String> map=new HashMap<String, String>();
map.put("fee_month",fee_month);
map.put("cust_id", cust_id);
List<Map<Object,Object>> list = busPayLogService.map_selectAllVatLog(map,RowBounds.DEFAULT);
if(list.size()>=1){
return list.get(0);
}else{
Map<Object,Object> map1=new HashMap<Object, Object>();
return map1;
}
}