Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the hutool utility class

2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to use the hutool tool class". In the daily operation, I believe many people have doubts about how to use the hutool tool class. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use the hutool tool class". Next, please follow the editor to study!

Brief introduction

Hutool is a small and comprehensive Java tool class library that makes Java as elegant as a functional language and makes Java language "sweet".

This is a very eye-catching sentence on Hutool gitee. For veteran programmers who often develop, it is true that the encapsulation of tool classes greatly improves the development efficiency, not to mention that Hutool involves the encapsulation of those tool classes, write wherever you want to.

Object to Map

Public static void test () {JavaEntity javaEntity = new JavaEntity (); javaEntity.setName ("Zhang San"); / / object conversion to Map output {name= Zhang San, address=null} Map map = BeanUtil.beanToMap (javaEntity); System.out.println (map);}

Date formatting class that provides commonly used date formatting objects

/ /- -Normal / * * Standard date format: yyyy-MM-dd * / public final static String NORM_DATE_PATTERN = "yyyy-MM-dd" / * * Standard date format {@ link FastDateFormat}: yyyy-MM-dd * / public final static FastDateFormat NORM_DATE_FORMAT = FastDateFormat.getInstance (NORM_DATE_PATTERN); / * Standard time format: HH:mm:ss * / public final static String NORM_TIME_PATTERN = "HH:mm:ss" / * * Standard time format {@ link FastDateFormat}: HH:mm:ss * / public final static FastDateFormat NORM_TIME_FORMAT = FastDateFormat.getInstance (NORM_TIME_PATTERN); / * Standard date and time format, accurate to minutes: yyyy-MM-dd HH:mm * / public final static String NORM_DATETIME_MINUTE_PATTERN = "yyyy-MM-dd HH:mm" / * * Standard date-time format, accurate to minutes {@ link FastDateFormat}: yyyy-MM-dd HH:mm * / public final static FastDateFormat NORM_DATETIME_MINUTE_FORMAT = FastDateFormat.getInstance (NORM_DATETIME_MINUTE_PATTERN); / * Standard date-time format, accurate to seconds: yyyy-MM-dd HH:mm:ss * / public final static String NORM_DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss" / * * Standard date-time format, accurate to seconds {@ link FastDateFormat}: yyyy-MM-dd HH:mm:ss * / public final static FastDateFormat NORM_DATETIME_FORMAT = FastDateFormat.getInstance (NORM_DATETIME_PATTERN)

MD5 encryption

String sign = SecureUtil.md5 (append.toString ()); System.out.println (sign)

Http request

String result = HttpUtil.post ("https://fpdk.beijing.chinatax.gov.cn/NSbsqWW/pltj.do", map)

List collection split

List partitionList = Lists.partition (valList, 30)

Convert to Int

/ / string is converted to int type System.out.println (Convert.toInt ("3"))

Convert arrays to collections

String [] b = {"1", "2", "3", "4"}; System.out.println (Convert.toList (b))

String conversion time

/ / conversion time String date = "2020-05-06"; System.out.println (Convert.toDate (date))

Half-width and full-width conversion

/ / full-width String num = "123456"; System.out.println (Convert.toSBC (num)); / / full-width String num1 = "123456"; System.out.println (Convert.toDBC (num1))

Unicode and string conversion

/ / Unicode string conversion String con = "\ u5468\\ u516d\\ u8981\\ u559d\\ u9189"; System.out.println (Convert.unicodeToStr (con)); / / string conversion to UnicodeSystem.out.println (Convert.strToUnicode ("Hutool is fine"))

Time unit conversion

/ / convert milliseconds to minutes long a = 19299292; long minutes = Convert.convertTime (a, TimeUnit.MILLISECONDS,TimeUnit.MINUTES); System.out.println (minutes)

Amount case conversion

/ / the amount is converted to RMB uppercase double a = 67556.32 domestic system. Out.println (Convert.digitToChinese (a))

timer

TimeInterval timer = DateUtil.timer (); / / execute process ConVertTest (); System.out.println (timer.interval ())

Generate a QR code

/ / generate the QR code QrCodeUtil.generate ("https://hutool.cn/", 300,300, FileUtil.file (" d:/qrcode.jpg ")); at this point, the study on" how to use the hutool tool class "is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report