跳到主要内容

API 索引

返回文档导航


JSONMap

构造方法

  • JSONMap() - 空对象
  • JSONMap(Object obj) - 从对象构造,支持 Map、JSON 字符串、普通对象
  • JSONMap(String json) - 从 JSON 字符串构造
  • JSONMap(String key, Object val, ...) - 交替键值对构造
  • createWithJson(String json) - 静态工厂方法

读取方法

  • getStr(String key) - 获取字符串
  • getInt(String key) / getInt(String key, int def) - 获取整数
  • getLong(String key) / getLong(String key, long def) - 获取长整数
  • getDouble(String key) / getDouble(String key, double def) - 获取小数
  • getFloat(String key) - 获取浮点数
  • getBigDecimal(String key) - 获取 BigDecimal
  • getBoolean(String key) / getBoolean(String key, boolean def) - 获取布尔值
  • getDate(String key) - 获取日期
  • getMap(String key) - 获取子对象(返回 JSONMap)
  • getList(String key) / getList(String key, Class<T> clazz) - 获取数组
  • getArray(String key, Class<T> clazz) - 获取数组
  • getObj(String key, Class<T> clazz) - 获取指定类型对象
  • at(String key) - 通用路径取值
  • as(Class<T> clazz) - 转换为 Bean

写入方法

  • put(String key, Object value) - 普通写入(key 不解析路径)
  • set(String key, Object value) - 深层路径写入
  • add(String key, Object obj) - 追加到数组
  • adds(Object... values) - 链式追加
  • remove(String key) / removes(String... keys) / removeAll() - 删除
  • clearEmptyProp() - 清理空值属性

判断方法

  • containsKey(Object key) - 是否包含 key
  • isNull(String key) - 值是否为 null
  • isEmpty() - Map 是否为空
  • nonEmpty(String key) - 值是否非 null 且非空字符串

JSONList

构造方法

  • JSONList() - 空列表
  • JSONList(String json) - 从 JSON 字符串构造
  • JSONList(Collection<?> collection) - 从集合构造
  • JSONList(Object obj) - 从对象构造

读取方法

  • getStr(int index) - 获取字符串
  • getInt(int index) / getInt(int index, int def) - 获取整数
  • getLong(int index) / getLong(int index, long def) - 获取长整数
  • getDouble(int index) / getDouble(int index, double def) - 获取小数
  • getFloat(int index) - 获取浮点数
  • getBigDecimal(int index) - 获取 BigDecimal
  • getBoolean(int index) / getBoolean(int index, boolean def) - 获取布尔值
  • getDate(int index) - 获取日期
  • getMap(int index) - 获取子对象
  • getList(int index) - 获取嵌套列表
  • getString(int index) - 获取 String 值
  • asList(Class<T> clazz) - 转换为列表

写入方法

  • adds(Object... values) - 链式追加

ValUtil

  • toInt(Object obj) / toInt(Object obj, Integer def) - 转整数
  • toLong(Object obj) / toLong(Object obj, Long def) - 转长整数
  • toDouble(Object obj) / toDouble(Object obj, Double def) - 转小数
  • toFloat(Object obj) / toFloat(Object obj, Float def) - 转浮点数
  • toBigDecimal(Object obj) / toBigDecimal(Object obj, BigDecimal def) - 转 BigDecimal
  • toStr(Object obj) / toStr(Object obj, String def) - 转字符串
  • toBoolean(Object obj) / toBoolean(Object obj, Boolean def) - 转布尔值
  • toDate(Object obj) - 转日期
  • toList(Object obj) - 转 JSONList
  • toList(Object obj, Class<T> clazz) - 转指定类型的列表
  • toArray(Object obj, Class<T> clazz) - 转数组
  • toObj(Object obj, Class<T> clazz) - 转指定类型对象

JacksonUtil

  • getJson(Object obj) - 序列化为 JSON 字符串
  • readValue(String json) - JSON → JSONMap
  • readValue(String json, Class<T> clazz) - JSON → 指定类型
  • readList(String json) - JSON → JSONList
  • at(Object data, String key) - 路径取值
  • at(Object data, String key, Class<T> clazz) - 路径取值并转换
  • splitKey(String key) - 路径拆分为 VAL
  • convertValue(Object obj, Class<T> clazz) - 类型转换

DateUtil

  • now() - 当前时间 Date
  • format(Date date, String pattern) - 格式化
  • format(Date date) - 格式化为 yyyy-MM-dd HH:mm:ss
  • getDate(String str) - 智能解析日期
  • getDate(String str, String pattern) - 按格式解析
  • getDate(LocalDateTime ldt) - LocalDateTime → Date
  • getLocalDateTime(Date date) - Date → LocalDateTime
  • parseUTCDate(String str) - 解析 UTC 日期
  • dateline() - 当前时间戳(秒)

StringUtils

  • isBlank(String str) / isNotBlank(String str) - 判空
  • isEmpty(String str) / isNotEmpty(String str) - 判空(不含空白)
  • isAnyEmpty(String... strs) - 任意为空
  • join(String sep, Object... values) - 连接
  • join(List<?> list, String sep) - 列表连接
  • formatMsg(String msg, Object... params) - 占位符格式化
  • formatMsg(String msg, JSONMap params) - ${key} 模板替换
  • isNumber(String str) - 数值格式校验
  • isLongOrInt(String str) - 整数格式校验
  • startsWith(String str, String prefix) - 前缀判断
  • capitalize(String str) - 首字母大写
  • addZeroBefor(Number num, int length) - 数字前补零
  • leftPad(String str, int len, char pad) - 左侧补齐
  • getBeanId(String className) / getBeanId(Class<?> clazz) - Bean ID 生成

BeanUtil

  • copyProperties(Object src, Object target) - 属性复制
  • copyProperties(Object src, Object target, boolean ignoreNull) - 属性复制(可选忽略 null)
  • copyAsSource(Object bean, JSONMap target, boolean onlySetValue) - Bean → JSONMap
  • copyAsTarget(Object map, Object bean) - JSONMap → Bean

上一节:贡献指南 | 返回文档导航 | 下一节:术语表 →