跳到主要内容

工具类速查表

← 返回文档导航


工具类概览

工具类用途核心方法
ValUtil类型转换toInt(), toStr(), toList(), toBoolean(), toBigDecimal()
JacksonUtilJSON 处理getJson(), readValue(), at(), splitKey()
DateUtil日期处理format(), getDate(), now(), dateline(), getLocalDateTime()
StringUtils字符串处理isBlank(), join(), formatMsg(), isNumber(), getBeanId()
BeanUtilBean 工具copyAsSource(), copyAsTarget(), copyProperties()
Cache缓存工具get(), put(), remove(), getAndSet()

ValUtil

ValUtil.toInt(obj); // → Integer 或 null
ValUtil.toInt(obj, 0); // → Integer 或 默认值
ValUtil.toStr(obj); // → String 或 null
ValUtil.toStr(obj, "default");
ValUtil.toLong(obj);
ValUtil.toDouble(obj);
ValUtil.toBigDecimal(obj);
ValUtil.toBoolean(obj);
ValUtil.toList(obj); // → JSONList
ValUtil.toList("1,2,3", Integer.class); // → [1,2,3]
ValUtil.toArray(obj, Integer.class); // → Integer[]
ValUtil.toDate("2024-01-01"); // → Date
ValUtil.toObj(map, User.class); // → User

JacksonUtil

JacksonUtil.getJson(obj); // 序列化
JacksonUtil.readValue(json); // JSON → JSONMap
JacksonUtil.readValue(json, User.class);
JacksonUtil.readList(json); // JSON → JSONList
JacksonUtil.at(data, "a.b.c"); // 路径取值
JacksonUtil.at(data, "a.b.c", String.class);
JacksonUtil.splitKey("a.b[1].c"); // 路径拆分 → VAL(a, b[1].c)
JacksonUtil.convertValue(obj, Target.class);

DateUtil

DateUtil.now();
DateUtil.format(date, "yyyy-MM-dd");
DateUtil.getDate("2024-01-01 12:00:00");
DateUtil.getDate("2024/01/01", "yyyy/MM/dd");
DateUtil.getLocalDateTime(date);
DateUtil.parseUTCDate("2024-01-01T12:00:00.000Z");
DateUtil.dateline(); // 当前时间戳(秒)

StringUtils

StringUtils.isBlank(str);
StringUtils.isEmpty(str);
StringUtils.join(",", "a", "b", "c");
StringUtils.formatMsg("Hello {}", name);
StringUtils.formatMsg("${name}", params);
StringUtils.isNumber("123.45");
StringUtils.isLongOrInt("123");
StringUtils.capitalize("hello"); // "Hello"
StringUtils.addZeroBefor(42, 5); // "00042"
StringUtils.leftPad("5", 3, '0'); // "005"
StringUtils.getBeanId(UserService.class); // "userService"

BeanUtil

BeanUtil.copyProperties(src, target); // Bean → Bean
BeanUtil.copyAsSource(bean, targetMap, false); // Bean → JSONMap
BeanUtil.copyAsSource(bean, targetMap, true); // 只复制 @SetValue 字段
BeanUtil.copyAsTarget(sourceMap, bean); // JSONMap → Bean

Cache

cache.get(name, key, User.class);
cache.put(name, key, value, seconds);
cache.remove(name, key);
cache.removeAll(name);
cache.keys(name, "prefix*");
cache.all(name, "prefix*");
cache.getAndSet(name, key, () -> VAL.of(data, 3600));

← 上一节:Cache | 返回文档导航 | 下一章:高级特性 →