Useful public methods in the development of the Java EE Project

Source: Internet
Author: User
Tags ticket

In the project IDCM involves a variety of work orders, including: server | network equipment up and down work order, server | Network equipment Restart work order, server fiber cable replacement work order, network equipment withdrawal wiring work order, server | Network equipment replacement ticket, server | Network equipment RMA ticket, General atomic work order, Hard disk degaussing bending work order, logistics work order, asset entry ticket, cabinet up and down electrician list, to be counted | Surplus work orders and so on. Work order management system to be involved in the creation of work orders | API creation and maintenance. Therefore, it is necessary to put forward some common methods, similar to the modular architecture involved.

1. Business logic Description: In the Ticket system details page, need to show the work order operation record, so do a general module design, so when the ticket details in the log section to make changes, in the shortest possible time, the smallest changes in the case, the perfect solution to the problem. A new Attachment field in the Log table is associated with the primary key in the App_attachment table, and when the operator is consistent with the login, the file can be uploaded by attachment.

Solution: Abstract The ORDEROPTLIST.VM module in the Details page, in the Ticket details page through $control.settemplate ("WEB:ORDEROPTLIST.VM") into the Ticket details page, At the same time the backend needs to provide common context.put ("operations", Operations) and Context.put ("Appuserinfo", Pvginfo) to match the presentation of the front-end data.

2. Business logic Description: Need to add a time-out field in the Ticket's detail page to determine if the ticket timed out at the time of the statement, if the entry is added in the ticket, the intrusion is too heavy and not conducive to post-maintenance, so take advantage of the Java reflection mechanism, dynamic update whether the timeout field.

Solution: The parameters in the method are set to the super-parent class object, the passed-in class, through the. getclass (). Getdeclaredmethod ("Method name", the method into the parameter comma-delimited), gets to the method class, and then satisfies the business logic, The method is called by the Method.invoke (object obj, object: args) method to refresh the data.

 Public voidupdateistimeout (Object pojo, Date StartTM, Double SLA, String slaunit) {Try{Method Method= Pojo.getclass (). Getdeclaredmethod ("Setistimeout", String.class); if(NULL! = StartTM &&NULL!=Pojo) {                if(NULL! = SLA &&Stringutil.isnotblank (Slaunit)) {                    BooleanIstimeout = (NewDate (). GetTime ()-Starttm.gettime () > (Long) (Sla.doublevalue () * Slautil.getslaunit (Slaunit). Getunit ())?true:false); if(NULL!=method) {                        if(istimeout) {Method.invoke (Pojo, Workordercst.yes); } Else{Method.invoke (Pojo, workordercst.no); }                    }                } Else{Method.invoke (Pojo, Workordercst.unknown); }            } Else{Method.invoke (Pojo, Workordercst.unknown); }        } Catch(Exception e) {logger.error ("Update istimeout Erros."); }    }

The method of the class is dynamically assigned, using the method Method.invoke (Obj,args ...) method, obj in the method is an instantiated object, and args is the parameter of the method.

 Public Object invoke (Object obj, object ... args)    obj: objects from which the underlying method is invoked must be an instantiated object,    args: Used for method invocation, is an array of object, because arguments may have more than one 

3. Business logic Description:

Solution:

 PackageBasic;Importjava.security.MessageDigest; Public classTestMD5 { Public Static voidMain (string[] args) {Try{String name= "Zhao, Xu-guang"; String CharSet= "GBK"; String Str= "2k3u.o#02pt" +name;            MessageDigest MessageDigest; MessageDigest= Messagedigest.getinstance ("MD5");            Messagedigest.reset ();            Messagedigest.update (Str.getbytes (charset)); byte[] ByteArray =messagedigest.digest (); StringBuffer Md5strbuff=NewStringBuffer ();  for(inti = 0; i < bytearray.length; i++) {                if(Integer.tohexstring (0xFF & Bytearray[i]). Length () = = 1) {md5strbuff.append ("0"). Append (Integer.tohexstring (0xFF &bytearray[i])); } Else{md5strbuff.append (integer.tohexstring (0xFF &bytearray[i]));        }} System.out.println (Md5strbuff.tostring (). toLowerCase ()); } Catch(Exception e) {e.printstacktrace (); }    }}

Useful public methods in the development of the Java EE Project

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.