This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.
Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
WangScaler: A writer with heart.
Declaration: uneducated, if there is a mistake, kindly correct.
Our daily development, will encapsulate some tools, these tools often used in the program, in fact you often need to use the tools, other people also may also be used, and Hutool is to encapsulate often use tools, for we are integrated into the project, so we don’t have to go to encapsulate the manually. Put the official website first so you can learn by yourself. The utility class provides a variety of simple utility classes that are ideal for integration into our project.
component
From the table below, you can see why I recommend this tool. It covers a wide range and is easy to use. By using this tool, we don’t have to package the tool library ourselves.
The module | introduce |
---|---|
hutool-aop | JDK dynamic proxy encapsulation, providing non-IOC aspect support |
hutool-bloomFilter | Bloom filtering, which provides some Hash algorithms for Bloom filtering |
hutool-cache | Simple cache implementation |
hutool-core | Core, including Bean operations, dates, various utils, and so on |
hutool-cron | Scheduled task module that provides scheduled tasks like Crontab expressions |
hutool-crypto | Encryption and decryption module, providing symmetric, asymmetric and digest algorithm encapsulation |
hutool-db | JDBC encapsulated data manipulation, based on ActiveRecord ideas |
hutool-dfa | Multi-keyword search based on DFA model |
hutool-extra | Extension module, encapsulation for third parties (template engine, mail, Servlet, TWO-DIMENSIONAL code, Emoji, FTP, word segmentation, etc.) |
hutool-http | Http client encapsulation based on HttpUrlConnection |
hutool-log | Automatic identification of log facade of log implementation |
hutool-script | Scripts perform encapsulation, such as Javascript |
hutool-setting | More powerful Setting profile and Properties wrapper |
hutool-system | System parameters call encapsulation (JVM information, etc.) |
hutool-json | JSON implementation |
hutool-captcha | Image verification code implementation |
hutool-poi | Excel and Word encapsulation for POI |
hutool-socket | NIO and AIO Socket encapsulation based on Java |
hutool-jwt | JSON Web Token (JWT) encapsulation implementation |
Each module can be imported individually as required, or all modules can be imported by hutool-all. Like our common development needs to use small tools, he can quickly achieve, such as time processing, various encryption methods for encryption, send mail, picture verification code and so on. Overall, introducing Hutool into the project greatly reduced our coding effort.
The introduction of the component
We can see that Hutool has a lot of components, so instead of listing them all, we’ll introduce them all.
<dependency> <groupId>cn. Hutool </groupId> <artifactId>hutool-all</artifactId> <version>5.6.1</version> </dependency>Copy the code
Demo
Let’s take a simple example, picture captcha as an example. Other tools can be written according to official documents.
/** * get the login verification code **@param response
* @param session
* @throws* /
@GetMapping("/captcha")
public void captcha(HttpServletResponse response, HttpSession session) throws IOException {
LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(116.36.4.10);
session.setAttribute("code", lineCaptcha.getCode());
try {
ServletOutputStream outputStream = response.getOutputStream();
lineCaptcha.write(outputStream);
outputStream.close();
} catch(IOException e) { e.printStackTrace(); }}Copy the code
test
Access the interface address, get the verification code we want, using Hutool so simple to achieve the verification code. My interference is not very much, you can configure more complicated interference line according to the official website.
The last
In short, this tool is very powerful, in the time module, even the zodiac signs are ready for you, you can get a code.
// "Capricorn"
String zodiac = DateUtil.getZodiac(Month.JANUARY.getValue(), 19);
/ / "dog"
String chineseZodiac = DateUtil.getChineseZodiac(1994);
Copy the code
The official recommended video teaching address: Hutool. Hutool’s mission: Hutool exists to reduce code search costs and avoid bugs caused by uneven code on the web. If there is a component you need, integrate it and enjoy it.
Come all come, click “like” and then go!
Follow WangScaler and wish you a promotion, a raise and no bucket!