缺少退货单,我所缺少的

时间:2018-09-14 05:43:19

标签: java spring-mvc

我编写了一个方法,该方法将通过返回true和false来确认控制器,我在try内返回true,如果一切正常,它将返回true,并且在catch块内返回false,但是方法仍然显示错误"missing return statement"最好的方法是什么?

以下用Java编写的方法将true或false发送回控制器。

第二,我想将异常消息从这里传送到控制器,我想到返回字符串,这是个好方法,

请建议我进行异常处理的最佳方法

 public boolean pickSalayData(String yearMonth, String regionId, String circleId, Userdetail loginUser) throws MyExceptionHandler {
        String tableSuffix = yearMonth.substring(4, 6) + yearMonth.substring(0, 4);

        log.info("Pick Salary Data From ERP " + DateUtility.dateToStringDDMMMYYYY(new Date()));
        List<SalaryDetailReport> detailReports = hRMSPickSalaryDataDAO.findAll(yearMonth, regionId, circleId);

        TransactionDefinition def = new DefaultTransactionDefinition();
        TransactionStatus trstatus = transactionManager.getTransaction(def);
        try {
            List<SalaryDetailReport> salaryDetailReport = null;
            int countDetail = 0;
            if (detailReports != null && detailReports.size() > 0) {

                for (SalaryDetailReport salary : detailReports) {
                    try {
                        if (countDetail % COMMIT_COUNT == 0) {
                            if (salaryDetailReport != null) {
                                salaryDetailReportDAO.save(salaryDetailReport, tableSuffix);
                                reportHistoryDAO.save(salaryDetailReport, loginUser);
                            }
                            salaryDetailReport = new ArrayList<SalaryDetailReport>();
                        }
                        salaryDetailReport.add(salary);
                        countDetail++;

                    } catch (Exception e) {
                        log.error("Error on Save Salary Pay Head Details Data from ERP to Prayas .");
                    }
                }
                if (salaryDetailReport != null && salaryDetailReport.size() > 0) {
                    salaryDetailReportDAO.save(salaryDetailReport, tableSuffix);
                    reportHistoryDAO.save(salaryDetailReport, loginUser);
                }
            } else {
                throw new MyExceptionHandler("No record for Save in Database from ERP.");
            }
            salaryDetailReportDAO.update(tableSuffix, regionId, circleId);
            List<SalaryDetailReport> reports = salaryDetailReportDAO.findAll(tableSuffix, regionId, circleId);
            if (reports != null && reports.size() > 0) {
                for (SalaryDetailReport salaryDetail : reports) {
                    try {
                        SalaryDetail sd = new SalaryDetail();
                        sd.setDetailReport(salaryDetail);
                        salaryDetailDAO.save(sd, tableSuffix);
                    } catch (Exception e) {
                        log.error("Error occured", e);
                        e.printStackTrace();
                        throw new MyExceptionHandler(" Error :" + e.getMessage());
                    }
                }
                System.out.println("data found");

            } else {
                log.error("Salary Record Not Found.");
                throw new MyExceptionHandler("No record Found.");
            }
            salaryDetailDAO.updateEarningDeduction(tableSuffix);
            //salaryDetailDAO.updateEarningDeductionsInSDT();
            transactionManager.commit(trstatus);
            try {
                hRMSPickSalaryDataDAO.update(regionId, circleId, yearMonth);
                return true;
            } catch (Exception ex) {
                log.error("Some error : ", ex);
            }

//            //   System.out.println("Completed =============================");
        } catch (MyExceptionHandler ex) {
            transactionManager.rollback(trstatus);
            ex.printStackTrace();
            log.error("Failed to Save Salary data  :" + ex.getMessage());
            return false;

        } catch (Exception ex) {
            transactionManager.rollback(trstatus);
            ex.printStackTrace();
            log.error("Error occured on Save Salary data.", ex);
            return false;
        }
    }

1 个答案:

答案 0 :(得分:2)

您缺少以下return块的catch语句:

 catch (Exception ex) {
                log.error("Some error : ", ex);
 }

您可以在此return块中或在方法的末尾添加catch语句