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

      

  • 相关阅读:
    底层因为接受到操作系统信号而停止的解决
    C语言判断文件是否存在
    Linux磁盘设备文件(sda,sdb,sdc…)变化问题
    linux mysql 数据目录文件夹移动及所遇到的问题
    Linux Mysql如何移动MySQL数据库目录位置
    Linux 磁盘挂载和mount共享
    提高VS2010/VS2012编译速度
    C++[类设计] ini配置文件读写类config
    WIN32读写INI文件方法
    MS509Team----------------Cknife
  • 原文地址:https://www.cnblogs.com/alway-july/p/9871439.html
Copyright © 2020-2023  润新知