Spring MVC returns multiple JSON data

Source: Internet
Author: User

First, demand:

Page return Data

1 {2 "code": 0,3 " msg": "",4 "Count": "2",5 "Data": [{6 " keywords": "Guangdong Timber Supply Co., Ltd. 1",7 "Frequency": 4621,8 "Usernums": 42359     },Ten     { One " keywords": "Guangdong Timber Supply Co., Ltd. 2", A "Frequency": 4621, - "Usernums": 4235 -     }] the}

Two, for this wrote a firm class

1  Public classFirm {2 3     PrivateString keywords;4     PrivateString frequency;5     PrivateString usernums;6     7      PublicTestdata (string keywords, string frequency, String usernums) {8          This. Keywords =keywords;9          This. Frequency =frequency;Ten          This. Usernums =usernums; One     } A}

Third, in the Controller method

1@RequestMapping ("/firm/listdata.action")2      Public@ResponseBody map<string, object>ListData () {3         4List<testdata> tdlist =NewArraylist<>();5Testdata TD1 =NewTestdata ("Guangdong Timber Supply Co., Ltd. 1", "4621", "4235");6Testdata TD2 =NewTestdata ("Guangdong Timber Supply Co., Ltd. 1", "4621", "4235");7 Tdlist.add (TD1);8 Tdlist.add (TD2);9 Tdlist.add (TD3);Ten Tdlist.add (TD4); One Tdlist.add (TD5); Amap<string, object> map =NewHashmap<>(); -Map.put ("code", 0); -Map.put ("msg", "" "); theMap.put ("Count", 2); -         map.put ("Data", tdlist);  -         returnmap; -}

Four, the browser reported 500 exception when visiting

 for class
No properties discovered to create Beanserializer


for class

(through reference chain:java.util.hashmap["data"]->java.util.arraylist[0])

V. Settlement

Implement serialization for the firm class, provide getter/setter for fields, and construct methods without parameters

1  Public classFirmImplements Serializable {2 3     PrivateString keywords;4     PrivateString frequency;5     PrivateString usernums;6     7      PublicString getkeywords () {8         returnkeywords;9     }Ten      Public voidsetkeywords (String keywords) { One          This. Keywords =keywords; A     } -      PublicString getfrequency () { -         returnfrequency; the     } -      Public voidsetfrequency (String frequency) { -          This. Frequency =frequency; -     } +      PublicString getusernums () { -         returnusernums; +     } A      Public voidsetusernums (String usernums) { at          This. Usernums =usernums; -     } -Non-parametric construction method -      PublicTestdata () { -          -     } in      -      PublicTestdata (string keywords, string frequency, String usernums) { to          This. Keywords =keywords; +          This. Frequency =frequency; -          This. Usernums =usernums; the     } *}

Spring MVC returns multiple JSON data

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.