The thief s easy-to-use Java tool library, GitHub starred 10k+, are you using it?

The thief s easy-to-use Java tool library, GitHub starred 10k+, are you using it?


Hutool is a self-made word of Hu + tool. The former pays tribute to my "predecessor company", and the latter means a tool. The homophony is "confused", which implies the pursuit of "all things are confused, there is no loss, no gain".

Hutool is a Java toolkit, it is just a toolkit, it helps us simplify every line of code, reduce every method, so that the Java language can also be "sweet". Hutool was originally a compilation of the "util" package in my project. Later, I gradually accumulated and added more non-business-related functions, and extensively learned the essence of other open source projects. After finishing and modifying by myself, I finally formed a rich open source tool set. (Copy from the author's introduction)


A Java basic tool class that encapsulates JDK methods such as files, streams, encryption and decryption, transcoding, regular, thread, XML, etc., to form various Util tool classes, and provides the following components:

  • hutool-aop JDK dynamic proxy package, providing non-IOC aspect support
  • hutool-bloomFilter Bloom filter, provides some Bloom filters of Hash algorithm
  • hutool-cache cache
  • hutool-core core, including Bean operations, dates, various Utils, etc.
  • hutool-cron timing task module, providing timing tasks like Crontab expressions
  • hutool-crypto encryption and decryption module
  • Data operation after hutool-db JDBC encapsulation, based on the idea of ActiveRecord
  • hutool-dfa Multi-keyword search based on DFA model
  • hutool-extra extension module, package for third parties (template engine, email, etc.)
  • hutool-http Http client package based on HttpUrlConnection
  • hutool-log automatically recognizes the log facade implemented by the log
  • hutool-script script execution package, such as Javascript
  • hutool-setting More powerful Setting configuration file and Properties package
  • hutool-system system parameter call package (JVM information, etc.)
  • hutool-json JSON implementation
  • Implementation of hutool-captcha image verification code

Simple test

In the past two days, I have used Hutool to replace some of the code in Halo. I have to say that it is very smooth to use. Here is a brief introduction to some of the Hutool tools I used.

SecureUtil (encryption and decryption tool)

It is mainly used when logging in and modifying the password, because the password in the database is encrypted by md5, so when logging in, you need to encrypt it before querying the database. If you use Hutool, you only need to call SecureUtil. The md5 method will do.

user = userService.userLoginByName(loginName,SecureUtil.md5(loginPwd));

HtmlUtil (HTML tool class)

This tool class is more powerful, but the one I use most in Halo is HtmlUtil.encode, which can convert some characters into safe characters to prevent xss injection and SQL injection, such as the comment submission below.


This is to prevent a little bad guy from deliberately writing some executable js code, and then submit a comment, this code will be executed in the background panel, which is more dangerous. Use the encode method

In addition, HtmlUtil also provides the following methods, you can try it if you are interested.

  • HtmlUtil.restoreEscaped restores escaped HTML special characters
  • HtmlUtil.encode escapes HTML characters in text as safe characters
  • HtmlUtil.cleanHtmlTag clear all HTML tags
  • HtmlUtil.removeHtmlTag clears the specified HTML tag and the content surrounded by the tag
  • HtmlUtil.unwrapHtmlTag clears the specified HTML tag, excluding the content
  • HtmlUtil.removeHtmlAttr removes attributes in HTML tags
  • HtmlUtil.removeAllHtmlAttr remove all attributes of the specified tag
  • HtmlUtil.filter filters HTML text to prevent XSS attacks
  • CronUtil (timed task)

This tool is even more powerful. There is no need for a framework like quartz to do timing tasks, and CronUtil does not require any other dependencies. You only need to create a configuration file under resources, and then turn on the timing task when the program starts. , Such as Halo's scheduled backup function (one backup at 1:00 a.m. every day).

cc.ryanc.halo.web.controller.admin.BackupController.backupResources = 0 0 1 * * ?
cc.ryanc.halo.web.controller.admin.BackupController.backupDatabase = 0 0 1 * * ?
cc.ryanc.halo.web.controller.admin.BackupController.backupPosts = 0 0 1 * * ?
public void onApplicationEvent(ContextRefreshedEvent event){
    CronUtil.start();" ");

Okay, let s introduce these three tool classes. If you are interested, you can try other tools. It's quite comprehensive. This should be the best tool library I have ever used. It is worth a try.
Official website address:

Author: Ryan Wang

Welcome to follow my WeChat public account "Code Farmer Breakthrough", share Python, Java, big data, machine learning, artificial intelligence and other technologies, and pay attention to the improvement of code farmers' technology workplace breakthrough thinking transition, 200,000 + code farmers grow first Stand, grow up with you who have dreams