1. 程式人生 > >js判斷返回值型別為空的情況下

js判斷返回值型別為空的情況下

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