Spring MVC - singhmahabir/allinone-rest-services GitHub Wiki
@GetMapping(value = "validate", params = {"name!="}, produces = MediaType.TEXT_PLAIN_VALUE) If this annotation is even used in interface it automatically inherited in child class as well-meaning exposed end point will work for implemented class method but implemented class has to used @RequestParam
We an override @GetMapping in class and can change the exposed end point So every case priority goes to class over interface
If you used params = {"name!="} on GetMapping then it make sure name should not empty even spaces are not allowed until you make required =false like @RequestParam(required = false) String name only on class
@RequestParam @PathVariable and @RequestBody are by-default required true
@PathVariable it is mandatory and it will not contain empty string or space if it is present last of the endpoint else space is allowed . NOTE : In implemented class if @PathVariable is not used still we have to pass the value to run the endpoint else 405 will get and most important value won't injected to method argument Ex. http://localhost:8080/option/{vin}/{name} http://localhost:8080/option/ANY VIN /ANYNAME or http://localhost:8080/option/ /ANY NAME it will work http://localhost:8080/option/vin/ it will send 405 Method not supported
To inject the data to method at class level @PathVariable is mandatory to use.
@RequestParam, @RequestBody it depends on its required attribute whether it is mandatory or not by default it is mandatory. NOTE : in implemented class if it is not exist then it is optional line normal argument of methods and null will be inserted .
@RestController is combination of @Controller and @ResponseBoady
Primitive value in rest methods : either you used any @RequestParam or not , to call this endpoints method you have to pass the value either you will get 500 or 406 not accepted or if not pass correct data then you will get 400 bad request. Except for boolean , boolean has false even if you haven't has the value
Spring return any java class as json response but if you have to send as xml then your java class should use @XmlRootElement and HttpMessageConverters uses Jaxb2RootElementHttpMessageConverter to change java to xml Or if you don't want to use @XmlRootElement over class then you must need to add