Code xét trường hợp bị sai

em đang sai vong if else. để rống 1 trong idProductType hoắc idArea nó chỉ chạy xuống p1

if (idProductType == null &&idArea!=null && minPrice==0 && maxPrice==0) {
            System.out.println("======");
            List<ProjectModel> list = projectService.findProjectByIdArea(idArea, limit, page);
            responseData = new ResponseData(0, "thanh cong", new ResponseBase(null, list));
} else if (idProductType != null && idArea!=null && minPrice>=0 && maxPrice!=0){
            System.out.println("......");
            List<ProjectModel> list = (List<ProjectModel>) projectService.findProjectAdvance(idProductType, idArea, minPrice, maxPrice, limit, page);
            System.out.println(list);
            responseData = new ResponseData(0, "thanh cong", new ResponseBase(null, list));
 }
else if(idArea==null && idProductType!=null && minPrice==0 && maxPrice==0){
            System.out.println("d1");
            List<ProjectModel> list=projectService.findProjectByType(idProductType,limit,page);
            responseData=new ResponseData(0,"thanh cong",new ResponseBase(null,list));
}
        else if ( idArea!=null && idProductType != null && minPrice==0 && maxPrice ==0){
                System.out.println("p1");
                List<ProjectModel> list = projectService.findProjectByIdAreaAndType(idProductType, idArea, limit, page);
                responseData = new ResponseData(0, "thanh cong", new ResponseBase(null, list));
}

Bạn đã thử với nhiều trường hợp khác chưa ?? Vì có thể idArea = nullidProductType = null luôn thì vẫn hợp lý mà

2 Likes

em muốn tìm kiếm theo 1 trong 2 cái đó mà

Bạn đặt dòng này trên cùng để debug này:

System.out.println("idArea: "+idArea +",idProductType: "+ idProductType +",minPrice: "+minPrice+",maxPrice: "+maxPrice)

xem nó chạy ra gì nhé

Nếu nó chạy đến p1 thì chỉ có trường hợp cả hai cái đó đều = null. Bạn kiểm tra lại xem việc gán giá trị có đúng không ??

1 Like

em cảm ơn mọi người… em tìm ra cách sửa rồi ạ

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?