ruoyi BeanUtils

Package com.ruoyi.common.utils.bean; 

Import the java.lang.reflect.Method;
 Import of java.util.ArrayList;
 Import java.util.List;
 Import java.util.regex.Matcher;
 Import the java.util.regex. the Pattern; 

/ ** 
 * Bean tools 
 * 
 * @author ruoyi
  * / 
public  class BeanUtils the extends org.springframework.beans.BeanUtils 
{ 
    / ** Bean method name attribute names starting index * / 
    Private  static  Final  int BEAN_METHOD_PROP_INDEX. 3 = ; 

    / ** * getter method of matching regular expression* / 
    Private  static  Final the Pattern of Pattern.compile GET_PATTERN = ( "GET (javaUpperCase {P} \\ \\ W *)" ); 

    / ** * setter method of matching a regular expression * / 
    Private  static  Final the Pattern = SET_PATTERN the Pattern. the compile ( "SET (javaUpperCase {P} \\ \\ W *)" ); 

    / ** 
     * Bean property replication tool methods. 
     * 
     * @Param dest audiences 
     * @param the src source object
      * / 
    public  static  void copyBeanProp (dest Object, Object the src) 
    { 
        the try 
        { 
            copyProperties (the src, dest); 
        } 
        the catch(Exception E) 
        { 
            e.printStackTrace (); 
        } 
    } 

    / ** 
     * get the object setter methods. 
     * 
     * @Param obj Object 
     * @return the setter method object list
      * / 
    public  static List <Method,> getSetterMethods (Object obj) 
    { 
        // the setter method list 
        List <Method,> = setterMethods new new the ArrayList <Method,> (); 

        // Get All methods 
        method, [] = methods obj.getClass () getMethods ();. 

        // Find setter methods 

        for (method, method: methods)
        { 
            Matcher m = SET_PATTERN.matcher (method.getName ());
             IF (. M.matches () && (Method.getParameterTypes () == length. 1 )) 
            { 
                setterMethods.add (Method); 
            } 
        } 
        // Returns setter method list 
        return setterMethods; 
    } 

    / ** 
     * get the object getter method. 
     * 
     * @Param obj Object 
     * @return getters method object list
      * / 

    public  static List <Method,> getGetterMethods (Object obj) 
    { 
        // getters list Method 
        List <Method,> = getterMethods new new the ArrayList <Method,> ();
         // get all methods 
        Method, [] = Methods obj.getClass () getMethods ();.
         // Find getter method 
        for (Method, Method: Methods) 
        { 
            m Matcher = GET_PATTERN.matcher (method.getName ());
             IF (m.matches () && (Method.getParameterTypes () == 0 length. )) 
            { 
                getterMethods.add (method); 
            } 
        } 
        // returns the getter list 
        return getterMethods; 
    } 

    / **
     * Bean property name checking method name of equality. <br> 
     * as getName () and setName () attribute the same name, getName () and setAge () attribute name is not the same. 
     * 
     * @Param M1 method name 1 
     * @param M2 method name 2 
     * @return returns the attribute name as true, otherwise false
      * / 

    public  static  boolean isMethodPropEquals (String M1, M2 String) 
    { 
        return m1.substring (BEAN_METHOD_PROP_INDEX) .equals (m2.substring (BEAN_METHOD_PROP_INDEX)); 
    } 
}

 

Guess you like

Origin www.cnblogs.com/tonggc1668/p/11788713.html