1. The spelling of this parameter
Learn, when Keys.length-1 is added "&" and is behind the puzzle
Public StaticString Map2content (Mapparams) {StringBuilder StringBuilder=NewStringBuilder (); Try{Set KeySet=params. KeySet (); Object[] Keys=Keyset.toarray (); for(intI=0; i < keys.length; i++{stringbuilder.append (Encode (), keys[i].tostring (),"UTF-8"). Append ("="). Append (Encode (params.Get(Keys[i]). ToString (),"UTF-8")); if (i < (keys.length-1)) {stringbuilder.append ("&"); } } } Catch(Exception e) {Throw NewHttpException ("failed to generate content from map", E); } returnstringbuilder.tostring ();}
2. Delete the file if it exists, and then create a new file
Private voidSaveusers (set<string>set,string FileName) {File F=NewFile (Getdatafolder (), fileName); if (f.exists ()) {f.delete (); } Try {f.createnewfile (); BufferedWriter Bwriter=NewBufferedWriter (NewFileWriter (f)); intCount=0; for(String name:set) {bwriter.write (name+ System.getproperty ("Line.separator")); Count++; } consoleutils.printinfo (NAME,"Saved" + Count + "users in" + filename+ "'!"); Bwriter.flush (); Bwriter.close (); } Catch(Exception e) {consoleutils.printexception (E,name,"Error while saving file '" + fileName + "'!"); }}
3.if (widget instanceof Checkbox) {
CheckBox cb = (checkbox) Widget If this is the case, strong turn into this class, commonly used in the wording
}
@Override PublicSet<activity>GE
Tinstitutionactivities () {Set<Activity> activities=NewHashset<activity>(); for(inti=0; I < Institutionactivities.getwidgetcount (); i++) {Widget widget=Institutionactivities.getwidget (i); if (widget instanceof checkbox) {checkbox cb= (checkbox) widget; if(Cb.getvalue ()) {Activity Activity=NewActivity (); Activity.setid (Integer.parseint (Cb.getformvalue ())); Activity.setname (Cb.gettext ()); Activities.add (activity); } } } returnactivities;}
Add elements in 4.set and do not repeat
Private Object createstringset (String ... strings) { Set<String> stringset=new hashset<string >(); for ( string string:strings) { stringset.add (string); } return Stringset;}
5. The exception can return null, empty can return null
Public Staticstring getsearchenginequerystring (httpservletrequest request,string referrer) {string queryString=NULL; String HostName=NULL; if(Referrer! =NULL) {URL refererurl; try {refererurl=new URL (referrer); } catch (Malformedurlexception e) {return null; } hostName=Refererurl.gethost (); QueryString=Refererurl.getquery (); if (Strings.isempty (queryString)) {return null; } Set<String> keys=Separams.keyset (); for(String se:keys) {if(Hostname.tolowercase (). Contains (SE)) {queryString=getquerystringparameter (Querystring,separams.get (SE)); } } returnqueryString; } return NULL;}
6.
Java Good habit 2