[Java] [Spring] Java EE (JAX-RS) vs. Spring REST implementation comparison memo

Class implementation

Java EE

In the class that inherits ResourceConfig, specify the package in which the REST resource class exists.

Spring

Annotate @ RestController

Request acceptance part

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. @RequestBodyTo the argument

Response output part

Contents Java EE Spring Remarks
Content type specification @Produces(MediaType.APPLICATION_JSON) @RequestMapping(produces=MediaType.APPLICATION_JSON_VALUE) SpringMediaTypeIsorg.springframework.httppackage
200 Returns OK. return Response.OK.build(); void

Recommended Posts

[Java] [Spring] Java EE (JAX-RS) vs. Spring REST implementation comparison memo
Java Spring environment in vs Code
Java 15 implementation and VS Code preferences
Java --Jersey Framework vs Spring Boot
Java memo
Spring Java
[JQuery] Implementation procedure of AutoComplete function [Java / Spring]
[Java / Spring Boot] Spring security ④ --Implementation of login process
[Java / Spring Boot] Spring security ⑤ --Implementation of logout processing
Java and Swift comparison (3) Class implementation / Class inheritance / Class design
[Verification] Comparison of Spring Boot vs Micronaut boot speed