-1

my requirement is to get the list of entity from the list of ids , I was trying something like this and I when I am priting to string method I am getting the list but when I am trying to return it , It saying not found .

My repo code

  List<AddingProductForView> findAllByproductidIn(ArrayList<Integer> productid);

my servicecode:-

   public List<AddingProductForView> getListOfData(ArrayList<Integer> productid){
        List<AddingProductForView> findAllByProductIdIn = repository.findAllByproductidIn(productid);
         return findAllByProductIdIn;
    }

mycontrollercode:-

    @PostMapping("/getProductsId")
public List<AddingProductForView> getListOfData(@RequestBody ArrayList<Integer> productid) {
    List<AddingProductForView> findAllByProductIdIn = fileService.getListOfData(productid);
    return findAllByProductIdIn;
}

while priting toString method (getting the result as :-

`[AddingProductForView [productid=1, productname=RO, imagepath=./assets/1.jpeg, price=4000  , productdescription=best], AddingProductForView [productid=2, productname=RO, imagepath=./assets/2.jpeg, price=8000  , productdescription=cheap], AddingProductForView [productid=3, productname=RO, imagepath=./assets/3.jpeg, price=2000  , productdescription=values]]`

What I am trying to hit from postman:-

  [1,3,2]

Error:- { "timestamp": "2021-07-02T07:25:50.973+0000", "status": 404, "error": "Not Found", "message": "No message available", "path": "/api/excel/getProductsId" }

3 Answers3

1

Your controller code is:

@PostMapping("/getProductsByIds")

but the url you type in postman is:

"path": "/api/excel/getProductsId"
0

Just change signature of method : ArrayList to interface List

public List<AddingProductForView> getListOfData(@RequestBody List<Integer> productid)
Mr_Thorynque
  • 1,749
  • 1
  • 20
  • 31
0

we have to use @ResponseBody at the method level for such

@PostMapping("/getProductsId")
@ResponseBody
public List<AddingProductForView> getListOfData(@RequestBody List<Integer> productid) {
    List<AddingProductForView> findAllByProductIdIn = fileService.getListOfData(productid);
    return findAllByProductIdIn;
}
  • No, this thing is not required. Because at the top, You mentioned '@RestController' and It's a combination of '@Controller' and '@ResponseBody'. – Dhwanil Patel Jul 02 '21 at 10:05