Spring MVC Controller obtains the JSON type passed to the page, mvcjson
A small step
College life is coming to an end. I have always thought that the world outside is full of color and can only be found after I step out ..... My class goes ~, It's full of color!
With a little emotion, the internship process is the fastest growing. What I learned at school is indeed the tip of the iceberg .. It's better to write down every learning process of yourself, happiness ......
Note:
Spring MVC is obtained in the controller. The method parameter in the Controller is a POJO class encapsulated by me. I naively thought that he could get the json object, so I had to give it a try, eventually, my head was stunned, but fortunately, there were countless gods on the internet, and I found my information in line with my situation. I am grateful to ing ......, let's not talk about it. Remember it now ~~~
POJO class public class BlackQueryArgs {private String name; private String idNumber; private String phone; // get/set .... // toString ....} controller @ RequestMapping (value = "test/getJson", method = RequestMethod. POST) @ ResponseBody public String testJson (BlackQueryArgs black) {LOG.info ("Get parameter information [{},{},{}]", black. getName (), black. getIdNumber (), black. getPhone (); return null ;}
As a result, I naively thought that he could receive json data. As a result, he still disappointed me ......
What should we do? Little cainiao had to go to the Internet to view the essays of the great gods. I was lucky enough to find them. The method parameters were modified using @ RequestBody, so it's like this .......
@ RequestMapping (value = "test/getJson", method = RequestMethod. POST) @ ResponseBody public String testJson (@ RequestBody BlackQueryArgs black) {LOG.info ("Get parameter information [{},{},{}]", black. getName (), black. getIdNumber (), black. getPhone (); return null ;}
Looking at the data printed on the console, cainiao cried ..........
So what does @ RequestBody do?
@ RequestBody: click here for details ~~ @ RequestBody, @ responseBody
Another small step
Little cainiao flew to spring step by step with leaves ~~~~~ (Spring)