RESTful a software architecture style, design style rather than standard, just provides a set of design principles and constraints. It is mainly used for client and server interaction class software. Software designed based on this style can be simpler, more layered, and easier to implement such mechanisms as caching.
If you need to pass an array parameter, if it is a generic form form, you can directly define the parameter type as list<string> (you cannot define an array type, or you can get only one null).
The sample code is as follows:
@POST
@Path ("/user") public
Response CreateUser (@FormParam ("username") String username,
@FormParam (" Keyword ") list<string> keywords) {
How does the file upload interface pass data parameters?
However, if it is an interface for uploading files, the above usage cannot be used because @FormDataParam annotations are used:
@POST
@Path ("/upload")
@Consumes (mediatype.multipart_form_data) public
Response UploadFile (@ Formdataparam ("filename") String filename,
@FormDataParam ("file") InputStream Uploadedinputstream,
@ Formdataparam ("file") formdatacontentdisposition Filedetail,
@FormDataParam ("keyword") Final list<string > Keywords) {
An exception occurs when accessing this interface:
Java.lang.IllegalArgumentException:wrong Number of arguments
When @FormDataParam annotations are used, it is not possible to define the parameter types as list<string>, which can be defined as list<formdatabodypart>, from Parameters can be obtained in the Formdatabodypart object:
@POST
@Path ("/upload")
@Consumes (mediatype.multipart_form_data) public
Response UploadFile (@ Formdataparam ("filename") String filename,
@FormDataParam ("file") InputStream Uploadedinputstream,
@ Formdataparam ("file") formdatacontentdisposition Filedetail,
@FormDataParam ("keyword") Final list< Formdatabodypart> keywordobjs) {
if (KEYWORDOBJS!= null &&! Keywordobjs.isempty ()) {for
(formdatab Odypart keywordobj:keywordobjs) {
String keyword = keywordobj.getvalueas (string.class);
System. Out.println ("keyword:" + keyword);
}
RESTful Annotation Encyclopedia
@GET, @POST, @PUT, @DELETE, @HEAD
@GET, @POST, @PUT, @DELETE, and @HEAD are all HTTP request method indicator annotations. You can use them to bind Java methods and HTTP request methods within a root resource or child resource. HTTP GET requests are mapped to methods that are annotated by the @GET, and HTTP POST requests are mapped to methods that are @POST annotated, and so on.
@Conumes and @Produces
@Conumes annotation represents a MIME type that a resource can accept. @Produces annotation represents the MIME type that a resource can return.
@Path
@Path annotations are used to describe the root resource, child resource method, or child resource location. Value values can contain text characters, variables, or variables that have custom regular expressions.