Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

In daily development, many methods are already implemented, so mastering open source methods is essential.

1.StringUtil

  • RemoveAll Removes all given strings from a string
  • EqualIgnoreCase Compares two strings for equality, case insensitive
  • ResetBlank merges multiple whitespace into a single whitespace
  • NumFormat Lowercase amount to Uppercase Chinese amount
  • DoubleFormat Saves double digits as two decimal places (rounded)
  • DoubleFormat Saves double numbers to n decimal places (rounded)
  • CountSubStr gets the number of occurrences of the String STR in the String
  • CountSubStrReg gets the number of occurrences in a String that matches a reg regular expression
  • GetEncode gets the encoding of the string
  • ObjEqual (Object,Object) Objects are equal
  • IsEmpty (Object o) checks whether the Object isEmpty
  • IsNotEmpty (Object o) determines whether an Object isNotEmpty

2.ValidateUtil

  • IsEmail Verifies whether the email address is valid
  • IsIdNo verifies whether it is a valid ID number
  • IsPhone Verifies whether the phone number is valid
  • IsBankAccount verifies that it is a valid bank card number
  • IsStrDate (String strDate) Checks whether the String is in date format

3.CommonUtil

  • IsEmpty collection/Map/Object/Object [] is null
  • IsNotEmpty collection/Map/Object/Object [] is not empty

4.RandomUtil

  • GetStr gets a random string of fixed length (containing only uppercase and lowercase letters and numbers)

5.CodeUtil

  • EncodeURL encodes the string in the specified encoding format
  • DencodeURL decodes the string in the specified encoding format

6.DateUtil

  • GetTime (String pattern) Obtains information in the specified format
  • GetTime (SimpleDateFormat SDF) gets information in the specified format
  • GetAge gets the age by birthday
  • GetDaysDiffFloor computes the number of days that differ between the two times, counting every full day as a day
  • GetDaysDiffCeil calculates the number of days that differ between two times, and counts less than one day as a day
  • GetMonthFirstDay Obtains the first day of the current month
  • GetMonthLastDay Obtains the last day of the current month
  • GetCurrentMonday Retrieves Monday of the current week
  • ConvertTime Time type of the database Timestamp, where STR is converted to LocalDateTime
  • IfToday(Date Date) Whether it is today
  • IfYesterday(Date Date) Whether yesterday
  • IfThisYear(Date Date) whether this year
  • ConversionDateForMsgList(Date Date) converts to the corresponding time format (for message module list)
  • ConversionDateForList(Date Date) converts to the corresponding time format (for generic lists)
  • ConversionDateForDetail(Date Date) converts to the corresponding time format (for details pages)
  • CalculateAging (Date startTime, Date endTime) Calculation aging
  • ConvertTime (String STR) Convert STR to LocalDateTime

7.FileUtil

  • CopyDir Copies a file
  • DelDir Deletes a file/directory
  • Upload a file
  • Download files

8. JSONUtil tools

  • ParseObject (JSON JSON, Class clazz) parses JSON into a javaObject
  • ParseObject (T T) converts T T to JSONObject
  • ParseArray (T[] tArray) is converted to a JSONArray based on the argument array
  • ParseArray (List List) converts a List List collection to a JSONArray
  • ParseArray (Set Set) converts the Set Set collection to a JSONArray
  • ParseJSONArrayToList (JSONArray JSONArray, Class Clazz) parses a JSONArray into a List List collection
  • ParseJSONArrayToSet (JSONArray JSONArray, Set Set) parses a JSONArray to a Set Set
  • ParseJSONArrayToObject (JSONArray JSONArray, Class clazz) parses JSONArray into T T, supports array parsing
  • ParseJSONStringToMap (String jsonString, Map

    Map) parses jsonString to Map

    Map
    ,>
    ,>
  • ToJSONString (Object Object) Unified JSON null value processing method
  • ParseObject (String text) String converts to JSONObject
  • ParseObject (String res, Type clazz) String converts to the specified Type
  • The parseObject(String res, TypeReference mapTypeReference) method deserializes the String into the specified data type

9.B64Util

  • Decode (String STR) Base64 decryption
  • IsBlank (String STR) checks whether it is null

10.CodeGenerator

  • DoGen (DataSourceConfig DSC, String parentModule, String moduleName, String tableName) automatically generates the corresponding project directory

11.ConvertUtils

  • ConvertSortValueByName (String name) Converts the name to a hash value

12.HttpClientUtil

  • DoGet (String URL) sends the GET method
  • DoPost (String URL, Map

    params) sends the POST request
    ,>
  • DoPost (String URL, String json) Post request, JSON parameter
  • DoPostWithSSL (String URL, String json) calls the HTTPS address using the direct trust certificate mode.

13.PasswordEncoder

  • GetEncodHash getEncodHash method
  • SetEncodHash (String encodHash) setEncodHash method
  • Encode (String password) decodes the password

14.SpringContextUtil

  • SetApplicationContext (ApplicationContext ApplicationContext) loads the springContext method as an initialization method by default
  • GetBean (String beanName) retrieves the bean by its name
  • GetBean (Class Clazz) finds objects based on the bean’s Class
  • GetMessage (String Key) gets the specified key value stored in springContext

15.TrustAnyTrustManager

  • ScheckClientTrusted (X509Certificate[] x509Certificates, String s) This method checks the client’s certificate and throws an exception if it is not trusted. Since we don’t need to authenticate the client, we just need to execute this method of the default trust manager
  • The checkServerTrusted(X509Certificate[] x509Certificates, String s) method checks the server’s certificate and throws an exception if it is not trusted. By implementing this method ourselves, we can make it trust any certificate we specify. When you implement this method, you can simply do nothing, that is, an empty function body, and since it does not throw an exception, it will trust any certificate
  • GetAcceptedIssuers () returns an array of trusted X509 certificates