Spring MVC Controller obtains the JSON type passed to the page, mvcjson

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.