mdsh.com/wiki


RecentChanges

TextFormattingRules
AllWikiTopics
OrphanedWikiTopics
ToDoWikiTopics
WikiLockList
RSS
Export2HTML

WikiSearch

SetUsername

StartingPoints
Home
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);
      ...
   }


Spring MVC annotation is mentioned on: Java


VeryQuickWiki Version 2.8.1 | Admin

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