Java Enumeration Type Modification

Source: Internet
Author: User

Original usage

 Public enum Color {    RED, GREEN, BLANK, YELLOW  }  

Usage in development

 Public enumapicodeenum {SUCCESS (0, "OK"), User_not_exists (1, "The user does not exist!" "), Code_error (2, "The verification code is not correct!" "), Buy_fail (3, "Purchase failed! "), not_logged (4, "No login! "), No_auth (5, "No Permissions! "),    //Field    PrivateInteger errno; PrivateString msg; //constructor Functionapicodeenum (Integer errno,string msg) { This. errno =errno;  This. msg =msg; }    //get data in an enumeration     PublicInteger Geterrno () {returnerrno; }    //get data in an enumeration     PublicString getmsg () {returnmsg; }}//wrap objects back into JSON format Public classApicodedto {//Return Code    PrivateInteger errno; //return content    PrivateString msg;  Publicapicodedto () {}//Manually create return information codes and information content     Publicapicodedto (Integer errno, String msg) { This. errno =errno;  This. msg =msg; }    //encapsulates information code and information content based on enumerated content     Publicapicodedto (Apicodeenum apicodeenum) { This. errno =Apicodeenum.geterrno ();  This. msg =apicodeenum.getmsg (); }}/*returning entity objects in Spring MVC is automatically converted to JSON format*/return NewApicodedto (apicodeenum.login_success);

Front End return Result:

Java Enumeration Type Modification

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.