This article is to do is optimization, encapsulation. Encapsulate the previous code into the class as much as possible, and do not hardcode it.
This is written before the Insertsysuser () function in Userserviceimpl:
Resultinfo resultinfo=New resultinfo (); Resultinfo.settype (resultinfo.type_result_fail); String message=resourcesutil.getvalue ("Resources.messages", "213"); Resultinfo.setmessage (message); Throw New Exceptionresultinfo (Resultinfo);
Feel too troublesome. We implement a tool class Resultutil ,
PackageYycg.base.process.result;Importjava.util.List;ImportYycg.util.ResourcesUtil;/*** System Results Tool class *@authorMRT **/ Public classResultutil {/*** Create incorrect results *@paramMESSAGE *@return */ Public StaticResultinfo Createfail (String fileName,intmessagecode,object[] objs) {String message=NULL; if(Objs = =NULL) {Message= Resourcesutil.getvalue (FileName, messagecode+ ""); }Else{message= Resourcesutil.getvalue (FileName, messagecode+ "", OBJS); } return NewResultinfo (resultinfo.type_result_fail,messagecode,message); } /*** Create warning prompt results*/ Public StaticResultinfo createwarning (String fileName,intmessagecode,object[] objs) {String message=NULL; if(Objs = =NULL) {Message= Resourcesutil.getvalue (FileName, messagecode+ ""); }Else{message= Resourcesutil.getvalue (FileName, messagecode+ "", OBJS); } return NewResultinfo (resultinfo.type_result_warn,messagecode,message); } /*** Create successful prompt results*/ Public StaticResultinfo createsuccess (String fileName,intmessagecode,object[] objs) {String message=NULL; if(Objs = =NULL) {Message= Resourcesutil.getvalue (FileName, messagecode+ ""); }Else{message= Resourcesutil.getvalue (FileName, messagecode+ "", OBJS); } return NewResultinfo (resultinfo.type_result_success,messagecode,message); } /*** Create general informational alert Results*/ Public StaticResultinfo Createinfo (String fileName,intmessagecode,object[] objs) {String message=NULL; if(Objs = =NULL) {Message= Resourcesutil.getvalue (FileName, messagecode+ ""); }Else{message= Resourcesutil.getvalue (FileName, messagecode+ "", OBJS); } return NewResultinfo (resultinfo.type_result_info,messagecode,message); } /*** Throws an exception *@paramResultinfo *@throwsExceptionresultinfo*/ Public Static voidThrowexcepion (Resultinfo resultinfo)throwsexceptionresultinfo{Throw NewExceptionresultinfo (Resultinfo); } Public Static voidThrowexcepion (resultinfo resultinfo,list<resultinfo> details)throwsexceptionresultinfo{if(Resultinfo! =NULL) {resultinfo.setdetails (details); } Throw NewExceptionresultinfo (Resultinfo); } /*** Create submission result information *@paramResultinfo *@return */ Public Staticsubmitresultinfo Createsubmitresult (resultinfo resultinfo) {return NewSubmitresultinfo (Resultinfo); } /*** Create submission results information, including details *@paramResultinfo *@paramDetails *@return */ Public StaticSubmitresultinfo Createsubmitresult (Resultinfo resultinfo,list<resultinfo>details) { if(Resultinfo! =NULL) {resultinfo.setdetails (details); } return NewSubmitresultinfo (Resultinfo); } Public Static voidMain (string[] args) {//TODO auto-generated Method Stub }}
With this tool class, the previous code can be written like this:
NULL ); New Resultutil (). Throwexcepion (Resultinfo);
Specific to the unclear or look at the document is better.
013 Medical Project-Module One: Join Tool class Resultutil