Home>

restful a software architecture style,Design style rather than standard,It just provides a set of design principles and constraints.It is mainly used for client-server interaction software.Software designed based on this style can be more concise,More hierarchical,Easier to implement mechanisms such as caching.

When array parameters need to be passed,If it is a general form, you can directly define the parameter type as list(cannot be defined as array typeOtherwise you can only get a 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?

But if it is an interface for uploading files,Because the @formdataparam annotation is used, the above usage cannot be 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

It can be seen that when using the @formdataparam annotation, it is not possible to define the parameter type as list.Can be defined as list, and parameters can be obtained from 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 (formdatabodypart keywordobj:keywordobjs) {
   string keyword=keywordobj.getvalueas (string.class);
   system. out.println ("Keyword:" + keyword);
     }
   }

restful annotations

@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 the root or child resource.http get requests are mapped to methods annotated by @get;http post requests are mapped to methods annotated by @post,And so on.

@conumes and @produces

The @conumes annotation represents a mime type that a resource can accept. The @produces annotation represents the type of mime that a resource can return.

@path

The @path annotation is used to describe the root resource, sub-resource method, or sub-resource location.value can contain text characters, variables, or variables with custom regular expressions.

  • Previous Detailed explanation of JavaScript based on object-oriented creation of objects (2)
  • Next Simple demonstration of tab switching effect in jQuery