Hutool is a small and comprehensive Java tool library

1. Introduction to Hutool

Hutool is a small and complete Java tool class library. Through static method encapsulation, it reduces the learning cost of related APIs and improves work efficiency, so that Java has the elegance of a functional language, and the Java language can also be "sweet".

The tools and methods in Hutool come from the meticulous craftsmanship of each user. It covers all aspects of the underlying code of Java development. It is not only a tool for solving small problems in large-scale project development, but also an efficiency responsibility in small projects;

Documentation

Official website

Chinese document

API documentation

Contains components

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

Module Introduction
hutool-aop JDK dynamic proxy package, providing non-IOC aspect support
hutool-bloomFilter Bloom filter, provide some Bloom filters of Hash algorithm
hutool-cache Simple cache implementation
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, providing symmetric, asymmetric and digest algorithm packaging
hutool-db Data manipulation after 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, Servlet, QR code, Emoji, FTP, word segmentation, etc.)
hutool-http Http client package based on HttpUrlConnection
hutool-log Log facade realized by auto-recognition 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
hutool-captcha Image verification code implementation
hutool-poi Encapsulation for Excel and Word in POI
hutool-socket Socket package of NIO and AIO based on Java

Each module can be introduced separately according to requirements, or all modules can be introduced by introducing hutool-all.

 

2. Hutool installation and use

installation

Use Maven to add relevant dependency files in the pom.xml configuration information file:

<!-- Hutool工具类库 -->
<dependency>
    <groupId>cn.hutool</groupId>
    <artifactId>hutool-all</artifactId>
    <version>5.5.8</version>
</dependency>

 

Determine whether the string is empty

@Test
public void strTest()
{
    String name = "pan_junbiao的博客";

    //字符串格式化的使用
    System.out.println(StrUtil.format("字符串内容:{}",name));

    //判断字符串是否为空
    System.out.println("字符串是否为空:" + StrUtil.isEmpty(name));
}

Results of the:

 

Use md5 encryption

@Test
public void md5Test()
{
    String content = "您好,欢迎访问 pan_junbiao的博客";
    String encrypt = SecureUtil.md5(content);

    System.out.println("加密前的内容:" + content);
    System.out.println("加密后的内容:" + encrypt);
}

Results of the:

 

BigDecimal addition, subtraction, multiplication and division operations

/**
 * BigDecimal的加减乘除运算
 * @author pan_junbiao
 */
@Test
public void operationTest()
{
    BigDecimal bigDecimal1 = new BigDecimal("10.2567");
    BigDecimal bigDecimal2 = new BigDecimal("2.236");

    //加法
    BigDecimal addResult = NumberUtil.add(bigDecimal1,bigDecimal2);
    System.out.println("加法运算结果:" + addResult);

    //减法
    BigDecimal subResult = NumberUtil.sub(bigDecimal1,bigDecimal2);
    System.out.println("减法运算结果:" + subResult);

    //乘法
    BigDecimal mulResult = NumberUtil.mul(bigDecimal1,bigDecimal2);
    System.out.println("乘法运算结果:" + mulResult);

    //除法
    BigDecimal divResult = NumberUtil.div(bigDecimal1,bigDecimal2);
    System.out.println("除法运算结果:" + divResult);

    //保留两位小数
    BigDecimal roundResult = NumberUtil.round(bigDecimal1,2);
    System.out.println("保留两位小数:" + roundResult);
}

Results of the:

 

Guess you like

Origin blog.csdn.net/pan_junbiao/article/details/113989598