-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" }

9
  • and what is actual problem here? Commented Jul 2, 2021 at 4:51
  • questionUpdated@rkosegi Commented Jul 2, 2021 at 4:58
  • try put {"productId":[1,2,3]} in postman request body, you should tell us what is your problem, and what you want to do @DivyeshKumar Commented Jul 2, 2021 at 6:48
  • badRequest , QuestionUpdated @Dolphin Commented Jul 2, 2021 at 6:50
  • try to put what I told to the postman body @DivyeshKumar Commented Jul 2, 2021 at 6:51

3 Answers 3

1

Your controller code is:

@PostMapping("/getProductsByIds")

but the url you type in postman is:

"path": "/api/excel/getProductsId"
Sign up to request clarification or add additional context in comments.

2 Comments

I have requestmapping defined at class level something like this :- @RequestMapping("/api/excel")
I mean getProductsByIds vs getProductsId
0

Just change signature of method : ArrayList to interface List

public List<AddingProductForView> getListOfData(@RequestBody List<Integer> productid)

Comments

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

1 Comment

No, this thing is not required. Because at the top, You mentioned '@RestController' and It's a combination of '@Controller' and '@ResponseBody'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.