@RequestMapping(value = "/SubmitStep1.json", method = RequestMethod.POST, headers = "Accept=application/json,application/xml")
@ResponseBody
public List<ShopDetails> showShopList(@RequestBody ShopDetails shopDetails)throws Exception{
List<ShopDetails> shopDetailsList=new ArrayList<ShopDetails>();
shopDetailsList=dbq.getShopDetails(shopDetails);
return shopDetailsList;
}
Here in above code i am returning list of shops which consist details of every shop as per locality.
So, my question is , can i add a success/error message while returning if i get the list of shops.
As said @araknoid - you can create wrapper:
public class ShopListResponse {
private List<ShopDetails> shopList;
private String message;
public ShopListResponse (List<ShopDetails> shopList, String message){
this.shopList = shopList;
this.message = message;
}
// getters and setters
}
In your controller class:
@RequestMapping(value = "/SubmitStep1.json", method = RequestMethod.POST, headers = "Accept=application/json,application/xml")
@ResponseBody
public ResponseEntity<ShopListResponse> showShopList(@RequestBody ShopDetails shopDetails)throws Exception{
List<ShopDetails> shopDetailsList = dbq.getShopDetails(shopDetails);
return new ResponseEntity<>(new ShopListResponse(shopDetailsList, "Success or error message"), HttpStatus.OK);
}
If you want return an error - you can return HttpStatus.NOT_FOUND
, or just return HttpStatus.OK
and message with error - it's depends on your approach.
Here controller result:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With