013 Medical Project-Module One: Join Tool class Resultutil

Source: Internet
Author: User

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

Related Article

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.