May 30, 2021 Article blog
1. 1. Pass the specified parameters
3. 3. The background accepts the data processing and returns the results
type
Default: "GET").
How to request ("POST" or "GET"), defaulting to "GET"
url
Default: Current page address.
The address at which the request was sent.
data
The data sent to the server. A
utomatically converts to the request string format. T
he GET request will be attached after the URL.
Must be in Key/Value format
contentType
The type of content encoding when sending information to the server.
dataType
The type of data that the server is expected to return.
If not specified, jQuery will automatically be intelligently judged based on HTTP package MIME information
success
The callback function after a successful request.
Argument: Data returned by the server and processed according to the dataType parameter;
$.ajax({
type: 'post',
url: '/operate/getNewsBynew_id',
data:{"new_id":data.new_id},
success: function (data) {
}
});
$.ajax({
type: 'post',
url: '/news/addnews',
contentType: "application/json; charset=utf-8",
data: JSON.stringify(data.field),
success: function (data) {
location.href="/gover_index_1.html"
}
}
);
@PostMapping("/addnews")
public News addNews(@RequestBody News news){
news.setTime(new Date());
newsService.insertNews(news);
return news;
}
@PostMapping("/getNewsBynew_id")
public NewsAll getNews(Integer new_id){
NewsAll newsAll=newsService.getNewsBynew_id(new_id);
System.out.println(newsAll.getS_times()+" "+newsAll.getTitle());
return newsAll;
}