Print this page and how many following pages?

 


 

Spring MVC annotation

@RequestMapping


With params defined the request will only get passed to this method if the query parameters of the caller's URL exist. If no method matches the caller gets a 400.

   @RequestMapping(value="/remote", params={"host"})
   public ResponseEntity<?> remote(
        @RequestParam(value = "host"final String host)
   {
      ...
   }


Without params defined the request will also only get passed to this method if the query parameters of the callers URL exist. If not method matches the caller gets a 400 with a message saying the parameter is required

   @RequestMapping(value="/remote")
   public ResponseEntity<?> remote(
        @RequestParam(value = "host"final String host)
   {
      ...
   }


Without params defined and with the the @RequestParam defined to be not required this method will be called no matter whether the query parameter exists on the callers URL. It is up to the code to decide how to cope with the situation.

   @RequestMapping(value="/remote")
   public ResponseEntity<?> remote(
        @RequestParam(value = "host", required = falsefinal String host)
   {
      if (null == host)
        return new ResponseEntity<>("'host' parameter is required", HttpStatus.BAD_REQUEST);
      ...
   }

VeryQuickWiki Version 2.8.1 | Admin

All contents copyright mdsh.com (C) 2011-2023.