下面把 Hutool 5.x 最常用、面试/开发问得最多的 6 大类工具梳理成一张速查表,复制即可用。
(如需其它类别,再告诉我补充即可)
| 类别 | 典型静态方法(链式/重载未全列) | 一句话作用 | 示例代码(极简) |
|----|-----------------------------|------------|------------------|
| 日期时间 DateUtil | `now()` / `today()` | 当前时间/日期字符串 | `String n = DateUtil.now();` |
| | `parse(String)` | 任意格式→Date | `Date d = DateUtil.parse("2026-01-21 18:00");` |
| | `format(Date, "yyyy-MM-dd")` | Date→自定义字符串 | `DateUtil.format(d, "MM/dd");` |
| | `offsetDay(Date, ±n)` | 日期前后偏移 n 天 | `DateUtil.offsetDay(d, -7);` |
| | `between(d1, d2, DateUnit.DAY)` | 两日期差(天/时/分) | `long days = DateUtil.between(d1,d2,DateUnit.DAY);` |
| | `beginOfDay(Date)` / `endOfDay(Date)` | 获取某日 00:00:00 / 23:59:59 | `DateUtil.beginOfDay(d);` |
| 字符串 StrUtil | `hasBlank(...)` | 多字符串任一空白 | `StrUtil.hasBlank(a, b);` |
| | `removePrefix/Suffix` | 去前缀/后缀 | `StrUtil.removeSuffix(file, ".tmp");` |
| | `sub(string, start, end)` | 安全子串(不抛异常) | `StrUtil.sub(str, 0, 8);` |
| | `format(template, obj...)` | 占位符替换 | `StrUtil.format("Hi {}", name);` |
| 类型转换 Convert | `toInt/Long/Double/Date/...` | 万能转目标类型 | `int age = Convert.toInt("18");` |
| | `toStrArray / toList` | 数组/集合互转 | `List<String> list = Convert.toList(String.class, arr);` |
| 数字 NumberUtil | `add/sub/mul/div(String, String)` | 高精度加减乘除 | `NumberUtil.add("0.1", "0.2");` |
| | `round(double, 2)` / `formatPercent` | 保留小数/百分比 | `NumberUtil.round(3.1415, 2);` |
| | `isNumber / isInteger` | 快速判断数字格式 | `NumberUtil.isNumber("123.45");` |
| Bean 拷贝 BeanUtil | `copyProperties(source, Target::new)` | 对象属性复制 | `User u = BeanUtil.copyProperties(dto, User::new);` |
| | `beanToMap / mapToBean` | Bean↔Map 互转 | `Map<?,?> map = BeanUtil.beanToMap(entity);` |
| 集合 CollUtil | `newArrayList(...)` | 快速建可变 List | `List<String> ls = CollUtil.newArrayList("a", "b");` |
| | `isEmpty / isNotEmpty` | 空集合判断 | `CollUtil.isEmpty(list);` |
| | `partition(List, size)` | 按 size 切分批次 | `List<List<T>> batch = CollUtil.partition(list, 100);` |
| 文件/IO FileUtil | `file(String)` / `readUtf8String` | 一行代码读文件 | `String txt = FileUtil.readUtf8String("a.txt");` |
| | `writeUtf8String(String, File)` | 写文件 | `FileUtil.writeUtf8String("hi", new File("a.txt"));` |
| | `copy / move / del` | 文件复制/移动/删除 | `FileUtil.copy(src, dest, true);` |
| 加密 Digester | `DigestUtil.md5Hex / sha256Hex` | 快速 MD5/SHA | `String md5 = DigestUtil.md5Hex("123");` |
| HTTP HttpUtil | `get / post` | 一行发 GET/POST | `String resp = HttpUtil.get("https://api.x.com");` |
| JSON JSONUtil | `toJsonStr(obj)` | 对象→JSON 字符串 | `String j = JSONUtil.toJsonStr(user);` |
| | `toBean(json, Class)` | JSON→对象 | `User u = JSONUtil.toBean(j, User.class);` |
| 邮件* MailUtil | `send(to, subject, body, isHtml, File...)` | 发文本/Html/附件 | `MailUtil.send("a@qq.com", "Hi", "<h1>hello</h1>", true, file);` |
| 二维码* QrCodeUtil | `generate(url, config, file)` | 生成二维码 | `QrCodeUtil.generate("https://x.cn", config, FileUtil.file("q.jpg"));` |
> 带 * 工具需额外引入依赖(JavaMail、ZXing 等),其余只需 `hutool-all` 即可。
使用方法:
1. 先加依赖
```xml
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.32</version> <!-- 写稿时最新 -->
</dependency>
```
2. 静态导入或直接 `类名.方法` 即可。
完整 API 见官方文档:https://www.hutool.cn/docs/
- 环境配置
- window怎么配置java环境变量?
- SQL学习
- 字段类型
- 1、 所有可声明的字段类型
- 2、常用的可声明的字段类型
- 创建表和表内字段
- 1、整个创建表语句
- 2、设置id主键
- 3、设置业务主键,唯一索引
- 4、设置业务字段
- 5、普通索引
- 6、唯一索引与普通索引的区别
- 7、表的引擎、字符集、排序规则和注释的设置
- Java基础语法
- 数据类型
- Java中的数据类型
- LocalDate
- 常用的数据类型
- Java 常用数据类型方法
- Java中数组、list、Map、HashMap
- 如何用Map来优化那些复杂的“双重 for 循环”查询?
- Java 8 中steam()操作流
- Java中HashMap和JSON
- Java中的JSONObject
- 工具类
- Java 常用工具类
- Arrays工具类
- Java 时间工具类
- 泛型
- Java中泛型概念
- Java中的泛型容器
- 泛型参数与函数参数的区别
- 推断出泛型实参
- Lambda表达式
- 数据分层
- 异常处理
- Java8 异常处理类总结表
- MyBatis-Plus 常用异常类总结表
- Java高级特性
- Maven
- jib-maven-plugin
- 什么是Spring Boot 的 parent pom?
- maven中各个生命周期的含义
- Spring Boot
- maven与spring boot 的关系
- Java中的连接池
- Spring JDBC
- Spring JDBC的概念
- JdbcTemplate常用的方法
- Spring中Bean的概念
- Spring中的抽象,通俗解释一下
- Spring中的事物
- Spring中的事物,通俗解释一下
- Spring中的事物抽象,常见的有哪些,列举一下
- Spring中常用的事物场景有哪些,列举一下
- Spring事务管理有哪些注解?
- Spring中使用事物处理订单的案例,列举说明一下
- Spring中声明式事务、分布式事务以及编程式事务的区别,列举一下
- 配置文件
- application-properties配置文件
- Spring Boot 的启动
- spring boot项目如何启动?
- 列举一下Spring Boot的启动过程
- SpringApplication.run方法
- Spring Boot 启动时有哪些接口?
- CommandLineRunner
- Spring Boot 的常用注解
- 系统注解
- 表格:系统注解
- @Override
- @Deprecated
- @SuppressWarnnings
- 使用在类名上的注解
- 表格:使用在类名上的注解
- @RestController
- @Controller
- @Service
- @Repository
- @Component
- @Configuration
- @Resource
- @Autowired
- @RequestMapping
- @GetMapping
- @PostMapping
- @Transactional
- @Qualifier
- 使用在方法上的注解
- 表格:使用在方法上的注解
- @RequestBody
- @PathVariable
- @Bean
- @ResponseBody
- @PreAuthorize
- 其他常用注解
- 表格:其他常用注解
- @EnableAutoConfiguration
- @SpringBootApplication
- @EnableScheduling
- @EnableAsync
- @ComponentScan
- @Aspec
- @ControllerAdvice
- @ExceptionHandler
- @Value
- @ConfigurationProperties
- @EnableConfigurationProperties
- @MapperScan
- @ApiOperation
- @Produces
- Validator验证的常用注解
- spring IoC容器
- Spring IoC容器依赖注入实现方式
- 常用依赖
- RESTEasy
- resteasy简介
- RESTEasy框架(依赖)的功能和常用注解
- MyBatis
- 简介
- paginationInterceptor
- @TableName
- @TableId
- @Param
- MyBatis-Plus
- MyBatis-Plus简介
- MyBatis-Plus的工具类
- Mybatis-Plus扩展的工具类和方法
- MyBatis-Plus中最常用的工具类方法
- MyBatis-Plus 中最常用的 4 大核心工具类
- Wrapper条件构造器
- Wrapper条件构造器详解
- Wrapper条件构造器eq等方法的参数说明
- LambdaQueryWrapper与QueryWrapper
- 日期格式是否必须转换
- Lombok
- Lombok作用详解
- @Data
- @Slf4j
- @Builder
- @EqualsAndHashCode
- @Accessors
- Jackson
- Jackson简介
- @JsonFormat
- Jackson高效地在 HashMap 和 JSON 字符串之间进行相互转换
- Hutool
- Hutool简介
- hutool依赖常用的方法
- fastjson2
- fastjson2简介
- UrlBasedCorsConfigurationSource
- 生态相关
- JBoss 社区
- 支付系统
- 1. 初始化mysql数据库流程
- 2. 初始化redis数据库的流程
- 3. 初始化rabbitmq服务
- 环球置业
- 1.模块目录结构分析
- 2. DTO(数据传输层)的核心作用
- 3. VO(视图对象层)
- 4. VO(视图对象层)和 DTO 数据传输层 的区别
