Article directory
-
- 1. mall open source project
- 2. Hutool tool library
- 3. Source code analysis
-
- 3.1 Integration and configuration
- 3.2 Core tools
-
- 3.2.1 AnnotationUtil usage: annotation tool class
- 3.2.2 BeanUtil usage: JavaBean tool class
- 3.2.3 CaptchaUtil usage: graphic verification code
- 3.2.4 ClassPath single resource access class: find files under classPath
- 3.2.5 CollUtil usage: collection tool class
- 3.2.6 Convert usage: type conversion tool class
- 3.2.7 DateUtil usage: date and time tool
- 3.2.8 DigestUtil usage: summary algorithm tool class
- 3.2.9 HttpUtil usage: Http request tool class
- 3.2.10 JSONUtil usage: JSON parsing tool class
- 3.2.11 MapUtil usage: Map tool class
- 3.2.12 NumberUtil usage: number processing tool class
- 3.2.13 ReflectUtil usage: Java reflection tool class
- 3.2.14 SecureUtil usage: encryption and decryption tool class
- 3.2.15 StrUtil usage: string tool
- 3.2.16 Validator usage: field validator
- 4. Summary
1. mall open source project
1.1 Source
mall learning tutorial , comprehensive analysis of architecture, business and technical points. The mall project ( 50k+star ) is an e-commerce system that is implemented using current mainstream technologies. Covers SpringBoot 2.3.0, MyBatis 3.4.6, Elasticsearch 7.6.2, RabbitMQ 3.7.15, Redis 5.0, MongoDB 4.2.5, Mysql5.7 and other technologies, using Docker container deployment.
Project github address: github.com
1.2 Project transfer
You can transfer projects on github to gitee for easy cloning to idea.
Specific steps are as follows:
1.3 Project cloning
Since github is deployed abroad, although idea also supports pulling from github, the cloning speed is too slow, so it is recommended to clone the project to idea after importing gitee as mentioned above.
The specific cloning steps are too simple and routine. Readers can complete it by themselves, or search on Baidu~
2. Hutool tool library
API文档
:Overview (hutool-codeyun(gitee.com))
hutool开发文档
: Hutool (When you encounter needs during development, check the documentation yourself to get an impression first)
2.1 Introduction to Hutool
Hutool is a small and comprehensive Java tool class library. It uses static method encapsulation to reduce the learning cost of related APIs, improve work efficiency, and make Java as elegant as a functional language.
The tools and methods in Hutool come from the careful craftsmanship of each user. It covers all aspects of Java development of underlying code. It is not only a powerful tool for solving small problems in large-scale project development, but also a role in efficiency in small projects;
Hutool is a friendly alternative to the "util" package in the project. It saves developers time in encapsulating public classes and public tool methods in the project, allowing development to focus on business while minimizing bugs caused by incomplete encapsulation.
3. Source code analysis
mall-tiny-hutool
The project source code only shows some toolkits commonly used in development. For others that are not shown, you can learn about them by yourself hutool开发文档
. The document is quite detailed.
**Analysis content:** Most of the analysis content below is explained in the figure, and there will not be too much explanation outside.
3.1 Integration and configuration
Directly analyze the source code, only the parts related to hutool are analyzed, and the design business part will not be described too much. Readers please read the source code analysis by themselves for other parts.
**Project Startup:**Only need to start mall-tiny-hutool
the module part.
**Required for startup:** Start the mysql5 service, create the database, and import the table (the location of the sql file is in the document
folder of the same directory as the project).
**ps:** Remember to modify the configuration information of the database connection.
3.1.1 Import dependencies
pom文件
Import hutool's related dependencies in .
3.1.2 Add configuration
3.2 Core tools
For swagger接口文档
, since the interfaces are all get请求
, and all returned are successful operations and null data, we will not show too much, only show them once to understand the use of those tool classes next.
下面的例子
They are all a small part of the tool class . I first read the official development documents before analyzing the code. It is recommended that when you see that tool class, you should read the corresponding official documents to deepen your impression.
3.2.1 AnnotationUtil usage: annotation tool class
注解工具类开发文档定位
:Annotation tool-AnnotationUtil | Hutool
1、控制层接口
The AnnotationUtil tool class is used in the method to obtain the annotation information on the specified class, including the annotation list and the attribute value of the annotation, and prints the results.
2、idea控制台打印的日志信息
3.2.2 BeanUtil usage: JavaBean tool class
Bean工具类开发文档定位
: Bean tool-BeanUtil | Hutool
1、控制层接口
2、idea控制台打印的日志信息
3.2.3 CaptchaUtil usage: graphic verification code
CaptchaUtil工具类开发文档定位
: Overview | Hutool
1、控制层接口
2、生成图形验证码效果
3.2.4 ClassPath single resource access class: find files under classPath
ClassPath工具类开发文档定位
: ClassPath resource access-ClassPathResource | Hutool
1、控制层接口
2、idea控制台打印的日志信息
3.2.5 CollUtil usage: collection tool class
CollUtil工具类开发文档定位
:Collection tool-CollUtil | Hutool
1、控制层接口
2、idea控制台打印的日志信息
3.2.6 Convert usage: type conversion tool class
Convert工具类开发文档定位
:Type conversion tool class-Convert | Hutool
1、控制层接口
3.2.7 DateUtil usage: date and time tool
DateUtil工具类开发文档定位
:Date time tool-DateUtil | Hutool
1、控制层接口
3.2.8 DigestUtil usage: summary algorithm tool class
DigestUtil工具类开发文档定位
: Digest Encryption - Digester | Hutool
There are many other encryption algorithms in the official development documents , you can learn about them by yourself.
1、控制层接口
2、idea控制台打印的日志信息
3.2.9 HttpUtil usage: Http request tool class
HttpUtil工具类开发文档定位
: Http client tool class-HttpUtil | Hutool
There are many other usages of http clients in the official development documents , you can learn about them by yourself.
1、控制层接口
2、idea控制台打印的日志信息
3.2.10 JSONUtil usage: JSON parsing tool class
JSONUtil工具类开发文档定位
: JSON Tool-JSONUtil | Hutool
The official development documents also include the usage of JSON objects and JSON arrays , which you can learn by yourself.
1、控制层接口
2、idea控制台打印的日志信息
3.2.11 MapUtil usage: Map tool class
MapUtil工具类开发文档定位
:Map tool-MapUtil | Hutool
The official development documentation also has other uses of Map , you can learn about it yourself.
1、控制层接口
3.2.12 NumberUtil usage: number processing tool class
NumberUtil工具类开发文档定位
:Number tool-NumberUtil | Hutool
1、控制层接口
3.2.13 ReflectUtil usage: Java reflection tool class
ReflectUtil工具类开发文档定位
:Reflection tool-ReflectUtil | Hutool
1、控制层接口
2、idea控制台打印的日志信息
3.2.14 SecureUtil usage: encryption and decryption tool class
SecureUtil工具类开发文档定位
:Encryption and decryption tool-SecureUtil | Hutool
1、控制层接口
3.2.15 StrUtil usage: string tool
StrUtil工具类开发文档定位
: String Tool-StrUtil | Hutool
1、控制层接口
3.2.16 Validator usage: field validator
Validator工具类开发文档定位
: Field Validator-Validator | Hutool
1、控制层接口
2、idea控制台打印的日志信息
4. Summary
My impression is: first have a rough understanding of the 先查看
official development documents when the business needs it. If it is not solved, you can use the development documents as a guide to 定位到
the API documents to complete the business.
In this article, I first obtained the requirements from actual projects, so as to learn the Hutool tool library, combined with the source code to learn, and learned mall
Hutool from open source projects. I feel that I have gained a lot. I hope this article will be helpful to you.
In the future, I will also combine this framework to learn other technology stacks.
盈若安好,便是晴天