In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to use List parameters". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
@ RequestBody receives arrays, List parameters, @ Deprecated tag obsolete method @ RequestBody Overview 1, @ RequestBody is mainly used to receive data in json format (data in the request body) passed by the front end to the back end 2, GET mode has no request body, so when @ RequestBody receives data, the front end must submit it in POST mode, and then the data to the page is also json3 by default. In the same method, @ RequestBody and @ RequestParam () can be used at the same time. The former can have at most one, while the latter can have more than one. 4, @ RequestBody receives the data in the request body, and @ RequestParam receives the parameters in the key-value. @ RequestParam request parameter: https://blog.csdn.net/wangmx1993328/article/details/95040803#%40RequestParam receives a single String parameter
Background code:
/ * * single parameter is transferred using String type, such as int, long, flout, etc., all use String * * @ param uid * @ return * / @ PostMapping ("save4") public String save4 (@ RequestBody String uid) {logger.info ("Save single parameter:" + uid); return "saved:" + uid } frontend ajax code: $.ajax ({/ / the content type transmitted by default is key-value type. When array and List receive parameters are used in the background, the content type must be specified as json type in / / headers, otherwise a 415 error will be reported headers: {'Content-Type':' application/json Charset=utf8'}, type: "post", url: "http://localhost:8080/user/save4", / / after specifying the json type, the transmitted data should of course be in json format. Data: JSON.stringify ({"uid": "9527"}), success: function (data) {console.log (data);}, error: function (data) {console.log ("ERROR:" + JSON.stringify (data));}}); receive string array parameters
Background MVC code:
/ * * @ param ids: receive a single: parameter string array on the page. Org.springframework.web.bind.annotation.RequestBody comments must be added. * if it is an integer array, replace it with Integer [] ids. * @ return * / @ PostMapping ("save1") public String save1 (@ RequestBody String [] ids) {logger.info ("save1--- >" + Arrays.asList (ids)); return new Date () + "transfer completed:" + Arrays.asList (ids);}
Front-end ajax code:
Var data = ["18ui", "89uj", "987u", "98uj"]; / / if the backend receives an integer array, you can use it in data, for example: data = [80,90,100,110120] < pad > < pad The transmitted data should of course be in json format. Data: JSON.stringify (data), success: function (data) {console.log (data);}, error: function (data) {console.log ("ERROR:" + JSON.stringify (data));}}); receive List
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.