Tag: User must have a string body ring to identify what spring
four types of restful requests
Get is secure (no matter how many times the operation, the state of the resource does not change),
Get,delete,put is idempotent (no matter how many times the operation, the result is the same),
Post is neither secure nor idempotent
Put versus post: Add operations can use post or put, the difference is that the post is acting on a collection resource (/uri), and the put operation is on a specific resource (/URI/XXX), and then more popular, if the URL can be determined on the client, Then use the put, if it is determined on the server, then use post, for example, many resources use the database self-increment primary key as identity information, and the identity information of the created resource is what can only be provided by the server, this time must use post.
RESTful Ajax sends requests
Client:
about ContentType
Default application/x-www-form-urlencoded
In addition to the default, there are also common:
ContentType: "Application/json; Charset=utf-8 ", ContentType:" Text/xml ",
about Get,post,put,delete Requests
To send a GET request, the above mentioned three ways are possible, because the Get method, the parameter is followed by the URL, not related to Content-type.
Other requests, you should consider contenttype, set the corresponding value.
about Data
When there are a large number of parameters, it can be packaged in JSON format and transmitted via Json.stringify ().
For example: Data:JSON.stringify (Paramobject),//pass JSON string to do parameters, future in controller with @requestbody receive
As follows:
var paramobject = {
"Login_name": login_name,
"Nick_name": Nick_name,
"Real_name": Real_name,
"Email": Email
};
Send an AJAX request
$.ajax ({
URL: "http://localhost:8888/spring5/user/" +id,
Type: "Put",
ContentType: "Application/json",//Specify to pass the new type to JSON
Data:JSON.stringify (Paramobject),//pass JSON string to do parameters, future in controller with @requestbody receive
DataType: "JSON",
Success:function (Result) {
if (result.status==1) {//successful
Window.parent.location.reload ();//Refresh Parent window
}else{
Layer.msg (result.msg);//hint failed
}
}
});
Service Side
@ResponseBody//Convert the returned Java object to a JSON string output convert the JSON string passed to the request into a Java object
Need to understand is: in fact, 2. The increase of resources, delete, change, check operation, in fact, can be completed through get/post, do not need to put and delete. But does not conform to the rest specification
Ajax requests under the restful specification