Development Framework (5)-Java Project Development Common tool class

Source: Internet
Author: User
Tags log log

Directory location in the project under the tool class:


1. Chinese into pinyin, initials, Chinesechartopinyin, when using this class must be added Pinyin.jar,pinyin.jar has been placed in the Hqhop-framework-web project Lib directory;

How to use:

The Chinesechartopinyin provides only two methods:

public static string Getpinyin (String src) {...} Convert Chinese characters to full spell

public static string Getpinyinheadchar (String str) {...} Extract the first letter of each Chinese character

2. Type Conversion helper Class Typecasehelper, providing mutual conversions between common types

3. Classes under Java Package security are commonly used cryptographic tool classes

4. Closeutil is primarily used to close some of the connected tool classes:

public class Closeutil {private static final log log = Logfactory.getlog (closeutil.class);/** * Closes the given input stream. <BR> * * @param instream */public static void Close (InputStream instream) {if (instream! = null) {try {instream.close ();} catch (IO Exception e) {log.error ("error on Close the InputStream.", E);}} /** * Closes the given output stream. <BR> * * @param outstream */public static void Close (OutputStream outstream) {if (OutStream! = null) {try {Outstrea M.close ();} catch (IOException e) {log.error ("error on Close the OutputStream.", E);}} /** * Closes the given output stream. <BR> * * @param writer */public static void Close (writer writer) {if (writer! = null) {try {writer.close ()} catch (IOException e) {Log.error ("error on Close the OutputStream.", E);}}} /** * Close the given socket. * * @param socket * Given socket */public static void close (socket socket) {if (socket! = NULL) {try {Socket.clos E ();} catch (IOException e) {log.error ("fail on Close socket:" + socket, e);}}} public static void Close (Reader reader{if (reader! = null) {try {reader.close ();} catch (IOException e) {log.error ("error on Close the reader.", e);}}  public static void Close (Connection conn) {if (conn! = null) {try {conn.close ()} catch (Exception e) {log.error ("error on Close Java.sql.Connection. ", E);}}} public static void Close (PreparedStatement PS) {if (PS! = null) {try {ps.close ()} catch (Exception e) {log.error ("Error O N Close java.sql.PreparedStatement. ", E);}}} public static void Close (ResultSet rs) {if (rs! = null) {try {rs.close ();} catch (Exception e) {log.error ("error on Close Java.sql.ResultSet. ", E);}}} public static void Close (Statement st) {if (st! = null) {try {st.close ()} catch (SQLException e) {log.error ("error on CLO Se java.sql.Statement. ", E);}}}}

5. the Utils class contains more judgment methods, commonly used:

1) Determines whether the object is empty IsEmpty (), Isnotempty ()

2) go back to the client address according to the IP address; Get the User IP address

3) Money converted to uppercase display

4) ID card Verification

......

6.the Springutils class is primarily a return object from the spring container and gets the resource

Public final class Springutils<span style= "color: #ff0000;" > Implements Beanfactorypostprocessor, Resourceloaderaware </span>{private static Configurablelistablebeanfactory beanfactory; Spring Application Context private static Resourceloader Resourceloader;<span style= "color: #ff0000;" > @Overridepublic void Setresourceloader (Resourceloader resourceloader) {Springutils.resourceloader = Resourceloader;} @Overridepublic void Postprocessbeanfactory (Configurablelistablebeanfactory beanfactory) throws Beansexception { Springutils.beanfactory = beanfactory;} </span>/**<span style= "color: #ff0000;" > * 1. Classpath:classpath:com/myapp/config.xml, load the resource under Classpath * 2. File:file:/data/config.xml Loaded as a URL, load resources under File system * 3. Http:http://myserver/logo.png Loaded as a URL. Load the resource under URL * 4. (none)/data/config.xml, load resources according to the current ApplicationContext type </span> * * @param location * @return */public static Reso Urce getresource (String location) {return Resourceloader.getresource (location);} /** * Gets the object * * @param name * @return Object An instance of the bean registered with the given name * @throws org.springframework.beans.BeansException * */@Su Ppresswarnings ("unchecked") public static <T> T Getbean (String name) throws Beansexception {return (T) Beanfactory.getbean (name);} Omit the following method ...
Springutils implements Beanfactorypostprocessor and Resourceloaderaware, it can get to beanfactory and Resourceloader objects, So that you can get the objects in the spring container, the resources


Development Framework (5)-Java Project Development Common tool class

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.