当前位置 : 首页 » 文章分类 :  开发  »  Hutool

Hutool

Hutool

https://hutool.cn/

https://github.com/dromara/hutool/


DateUtil

formatDateTime() 格式化日期

格式 yyyy-MM-dd HH:mm:ss

parse() 解析日期字符串

支持几乎所有格式

offset/offsetSecond/offsetDay 日期差值

public static DateTime offset(Date date, DateField dateField, int offset)
public static DateTime offsetSecond(Date date, int offset)
public static DateTime offsetDay(Date date, int offset)

beginOfDay/endOfDay 一天的开始/结束时间

public static DateTime beginOfDay(Date date)
public static DateTime endOfDay(Date date)


CharPool 字符池

SLASH 斜杠


StrPool 字符串池

DOT 点


SpringUtil

getBeansOfType() 从Spring上下文获取指定类型的Bean

hutool-all 包的 spring.factories 中启用了 SpringUtil 自动配置,可无需注入直接使用 SpringUtil.getBean


ThreadUtil

createThreadFactory() 指定前缀创建线程工厂


URLUtil

encode()

java.net.URLEncoder 会把所有特殊字符包括:和/都编码,带中文的连接编码后无法访问。
cn.hutool.core.util.URLUtil.encode() 可实现只编码中文和空格,不编码 http://


CollectionUtil

distinct() 集合按指定字段去重

public static <T, K> List<T> distinct(Collection<T> collection, Function<T, K> uniqueGenerator, boolean override)
override=true 有重复时保留后面的,删除前面的
override=false 有重复时保留前面的,删除后面的

例如 users 列表按 name 去重

List<User> users = CollectionUtil.distinct(users, User::getName, true);

IdUtil

fastSimpleUUID() 无横线的uuid


上一篇 H2

下一篇 JsonPath

阅读
评论
302
阅读预计1分钟
创建日期 2023-08-28
修改日期 2023-08-28
类别
标签

页面信息

location:
protocol:
host:
hostname:
origin:
pathname:
href:
document:
referrer:
navigator:
platform:
userAgent:

评论