Ajax请求Json数据,报500错误,后台没有错误日志。

post请求:http://localhost:9080/DataDiscoveryWeb/issueformcount/queryIssueTendencyDetail.xhtml?jobId=862

前端报500错误

1、500,是服务器的错误,查看一下后台,没有报错。

2、打断点,也没有发现错误,但是请求返回空数据的时候,没有报错,返回有数据的结果报错了。

3、那应该是对象转Json的时候报错了,加入对象转Json代码到请求的最后。

    ObjectMapper objectMapper = new ObjectMapper();
        try {
            objectMapper.writeValue(System.out,output);
        } catch (IOException e) {
            e.printStackTrace();
        }

4、再次测试,果然发现报错了。ReportStatistics.getJobId()实体转Json的时候空指针。

Caused by: java.lang.NullPointerException
    at com.audaque.datadiscovery.report.entity.ReportStatistics.getJobId(ReportStatistics.java:127)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.jackson.map.ser.BeanPropertyWriter.get(BeanPropertyWriter.java:483)
    at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:418)
    at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
    ... 59 more

5、查看代码,getJobId的返回类型是int,查询出的JobId是Null值,NUll不能转为int,应该是将返回的返回类型改为Integer。实体类应该使用包装类型,原因Java Bean 使用包装类型 还是基本类型,我修改成包装类型后,没有重新生成get,set方法。

private Integer jobId;
public int getJobId() {
    return jobId;
}

前端代码:

 parent.postReturnJsonnoalert("/issueformcount/queryIssueTendencyDetail.xhtml",{
                        jobId:862
            },function(result){
                        if(result.success){
                            debugger;
                            parent.showInfoBox("查询成功");
                        }else{
                            parent.showErrorBox(result.msg);
                        }
                    }
            );

后端代码:

@RequestMapping(value = "queryIssueTendencyDetail.xhtml",method = RequestMethod.POST)
    @ResponseBody
    public EasyUIDataGradOutputModel queryIssueTendencyDetail ( Integer jobId)  {
        EasyUIDataGradOutputModel output = new EasyUIDataGradOutputModel();
        Page<ReportStatistics> page = null;
        try {
            //查询100条数据
            page = reportService.queryJobReportByJobId(jobId, 1, 100);
        } catch (AdqException e) {
            LOG.error(e.getMessage(),e);
            page = new Page<ReportStatistics>();
        }
        output.setRows(page.getRecords());
        output.setTotal((int) page.getTotalRows());
        return output;
    }

 

 

  

 

posted @ 2018-10-29 16:36  Always_July  阅读(11498)  评论(1编辑  收藏  举报