java post请求返回500错误_Ajax请求Json数据,报500错误,后台没有错误日志。

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

前端报500错误

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

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

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

ObjectMapper objectMapper = newObjectMapper();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方法。

privateInteger jobId;public intgetJobId() {returnjobId;

}

前端代码:

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)

@ResponseBodypublicEasyUIDataGradOutputModel queryIssueTendencyDetail ( Integer jobId) {

EasyUIDataGradOutputModel output= newEasyUIDataGradOutputModel();

Page page = null;try{//查询100条数据

page = reportService.queryJobReportByJobId(jobId, 1, 100);

}catch(AdqException e) {

LOG.error(e.getMessage(),e);

page= new Page();

}

output.setRows(page.getRecords());

output.setTotal((int) page.getTotalRows());returnoutput;

}

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值