将参数值从我的实现服务传递给我的RestController java springboot

问题描述 投票:1回答:1

我在传递返回表结果时得到的错误值时遇到麻烦。

我的ServiceImpl类中有一个方法,该方法返回表的结果,并计算错误的数量。

public List<Flow>  getAllProcessContextWithCriteriaAndFlowCode(
            String startDate, String endDate, String flowCode) {



        List<FlowDto> flowDtos = new ArrayList<>(500);
        flowDtos = processContextRepository
                .fetch(startDate,
                        endDate, flowCode);

        List<Flow> flows = new ArrayList();

        // bodyguard
        if (flowDtos == null || flowDtos.size() == 0) {
            return flows;
        }

        int counter = 0;
        StringBuilder idFonctionnelBuilder = new StringBuilder();
        FlowDto currentFlowDto = null;
        FlowState flowState = new FlowState();
        FlowDto nextFlowDto = null;
        Flow flowTemp = null;
        Map<String, String> mapFlowIdsAndIdF = new HashMap<>();
        int iNbreError = 0;
        String sTempError = "";

        for (int i = 0; i < flowDtos.size(); i++) {

            currentFlowDto = flowDtos.get(i);

            if ((i + 1) < flowDtos.size()) {
                nextFlowDto = flowDtos.get(i + 1);
                if (((nextFlowDto.getFlowId()
                        .equals(currentFlowDto.getFlowId())))) {
                    idFonctionnelBuilder.append(currentFlowDto.getIdf() + ", ");
                    continue;

                } else {
                    flowTemp = new Flow();

                    flowTemp.setFlowId(currentFlowDto.getFlowId());

                    flowTemp.setLogRole(currentFlowDto.getLogRole());


                    Date date = null;
                    try {
                        date = inputFormat.parse(currentFlowDto
                                .getContextTime());
                    } catch (ParseException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    flowTemp.setContextTime(outputFormat.format(date));

                    if (currentFlowDto.getLogRole() != null) {
                        iNbreError++;
                        flowTemp.setNbreError(iNbreError);
                    } else {
                        flowTemp.setNbreError(iNbreError);
                    }



                    flowTemp.setNbreError(iNbreError);
                    flows.add(flowTemp);


                }
            } else {

                flowTemp = new Flow();



                if (currentFlowDto.getLogRole() != null) {

                    iNbreError++;
                    flowTemp.setNbreError(iNbreError);
                } else {
                    flowTemp.setNbreError(iNbreError);
                }
                flowTemp.setContextTime(outputFormat.format(date));


                flows.add(flowTemp);
            }
        }


        LOGGER.info("[ getAllProcessContextWithCriteriaAndFlowCode ] iNbreError    : "
                + iNbreError);
        getNbreError(iNbreError);
        return flows;
    }

然后我在同一类ServiceImpl中有另一个方法,该方法获取错误数并将其设置在变量中,结果打印在这里总是正确的。

public int getNbreError( int iNbreError){
        System.out.println("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH");
            System.out.println(iNbreError);
        setCountError(iNbreError);
        System.out.println("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH");
        System.out.println(countError);
        return countError;
    }

我想做的就是将此值(counterror)发送到我的RestController,它在另一个称为RestController的类中,因此我可以将其发送到我的前端。>

    @GetMapping(value = "/nbreError")
    public int getCountError() {
        FMServiceImpl flows = new FMServiceImpl();
        int countError = 0;
        int iNbreError = 0;


        return fmService.getNbreError( iNbreError);

    }
}

实际上,结果始终为0。感谢您的帮助或建议:)

我在传回表格结果时遇到的错误值时遇到麻烦。我的ServiceImpl类中有一个方法,该方法返回表的结果并计算数量...

java spring-restcontroller
1个回答
0
投票
  1. 不要使用getMethod
© www.soinside.com 2019 - 2024. All rights reserved.