post請求:http://localhost:9080/DataDiscoveryWeb/issueformcount/queryIssueTendencyDetail.xhtml?jobId=862html
前端報500錯誤前端
一、500,是服務器的錯誤,查看一下後臺,沒有報錯。java
二、打斷點,也沒有發現錯誤,可是請求返回空數據的時候,沒有報錯,返回有數據的結果報錯了。後端
三、那應該是對象轉Json的時候報錯了,加入對象轉Json代碼到請求的最後。服務器
ObjectMapper objectMapper = new ObjectMapper(); try { objectMapper.writeValue(System.out,output); } catch (IOException e) { e.printStackTrace(); }
四、再次測試,果真發現報錯了。ReportStatistics.getJobId()實體轉Json的時候空指針。app
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
五、查看代碼,getJobId的返回類型是int,查詢出的JobId是Null值,NUll不能轉爲int,應該是將返回的返回類型改成Integer。實體類應該使用包裝類型,緣由Java Bean 使用包裝類型 仍是基本類型,我修改爲包裝類型後,沒有從新生成get,set方法。post
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); } } );
後端代碼:spa
@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; }