Java receive parameters and return data entity class Encapsulation 1

Source: Internet
Author: User

 Public classPagedataextendsHashMapImplementsMap {Private Static Final LongSerialversionuid = 1L; Map Map=NULL;    HttpServletRequest request;  PublicPagedata (HttpServletRequest request) { This. Request =request; Map Properties=Request.getparametermap (); Map Returnmap=NewHashMap (); Iterator Entries=Properties.entryset (). iterator ();        Map.entry Entry; String name= ""; String value= "";  while(Entries.hasnext ()) {entry=(Map.entry) entries.next (); Name=(String) Entry.getkey (); Object Valueobj=Entry.getvalue (); if(NULL==valueobj) {Value= ""; } Else if(Valueobjinstanceofstring[]) {string[] values=(string[]) valueobj;  for(inti = 0; i < values.length; i++) {Value= Values[i] + ","; } Value= value.substring (0, Value.length ()-1); } Else{Value=valueobj.tostring (); }            if(Name.equals ("Timeend")) {                if(!value.equals ("") ) {value= value + "23:59:59"; } Else{}} returnmap.put (name, value); } Map=Returnmap; }     Publicpagedata (jsonobject Jo) {Map returnmap=NewHashMap ();  for(Iterator<string> keys =Jo.keys (); Keys.hasnext ();) {            Try{String Key1=Keys.next ();//System.out.println ("Key1---" + key1 + "------" + jo.get (key1) + (Jo.get (key1) instanceof Jsonobject) 
    //+ jo.get (key1) + (Jo.get (key1) instanceof Jsonarray));//System.out.println ("Key1:" + key1 + "----------jo.get (Key1):" + jo.get (key1));Returnmap.put (Key1.touppercase (), Jo.get (Key1)); } Catch(jsonexception e) {e.printstacktrace (); }} Map=Returnmap; }     PublicPagedata () {map=NewHashMap (); } @Override Publicobject get (Object key) {Object obj=NULL; if(Map.get (Key)instanceofobject[]) {object[] arr=(object[]) map.get (key); Obj= Request = =NULL? Arr: (Request.getparameter (String) key) = =NULL? Arr:arr[0]); } Else{obj=Map.get (key); }        returnobj; }     PublicString getString (Object key) {if(NULL! = Get (key) && "NULL"! =get (Key)) {            returnstring.valueof (Get (key)); }        return""; }     Public Doublegetdouble (Object key) {Object value=get (key); if(NULL! = value &&! " Null ". Equals (value) &&!". Equals (value)) {            if(ValueinstanceofString) {                returndouble.parsedouble (value.tostring ()); } Else if(ValueinstanceofDouble) {                return(Double) value; }            //return (double) get (key);        }        return0.0; }     Public intgetInt (Object key) {Object value=get (key); if(NULL! = value &&! " Null ". Equals (value) &&!". Equals (value)) {            if(ValueinstanceofString) {                returnInteger.parseint (value.tostring ()); } Else if(ValueinstanceofInteger) {                return(int) value; }        }        return0; }

Its essence is a HashMap

Java receive parameters and return data entity class Encapsulation 1

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.