Java EE
In the class that inherits ResourceConfig
, specify the package in which the REST resource class exists.
Spring
Annotate @ RestController
Contents | Java EE | Spring | Remarks |
---|---|---|---|
Method specification | @GET |
@RequestMapping(method=RequestMethod.GET) |
POST/DELETE/Same for PUT |
Specifying the path | @Path("/path") |
@RequestMapping(value="/path") |
|
Specifying the path as a parameter | @Path("{id:[0-9]+}") |
@RequestMapping(value="{id:[0-9]+}") |
The variable part is the same{}Surround with. Regular expressions can also be used. Do not put spaces before or after the colon. |
Accepting parameters with a specified path | @PathParam("id") Integer id |
@PathVariable(name="id") Integer id |
|
Accept query string | @QueryParam("name") String name |
@RequestParam(name="name",required=false) String name |
Spring becomes 400 BAD REQUEST without arguments, so required=Add false. |
Accepting the request body | Nothing in particular. Leave the normal arguments. | @RequestBody To the argument |
Contents | Java EE | Spring | Remarks |
---|---|---|---|
Content type specification | @Produces(MediaType.APPLICATION_JSON) |
@RequestMapping(produces=MediaType.APPLICATION_JSON_VALUE) |
SpringMediaType Isorg.springframework.http package |
200 Returns OK. | return Response.OK.build(); | void |
Recommended Posts