类 CommonUtil

java.lang.Object
net.sohelp.boot.admin.core.utils.CommonUtil

public class CommonUtil extends Object
常用工具方法
从以下版本开始:
2017-06-10 10:10:22
作者:
AaronFung
  • 构造器详细资料

    • CommonUtil

      public CommonUtil()
  • 方法详细资料

    • randomUUID8

      public static String randomUUID8()
      生成8位uuid
      返回:
      8位长度的UUID字符串
    • randomUUID16

      public static String randomUUID16()
      生成16位uuid
      返回:
      16位长度的UUID字符串
    • checkRepeat

      public static <T, R> boolean checkRepeat(List<T> list, Function<? super T,? extends R> mapper)
      检查List是否有重复元素
      类型参数:
      T - 数据的类型
      R - 需要检查的字段的类型
      参数:
      list - 要检查的列表
      mapper - 获取需要检查的字段的Function
      返回:
      存在重复元素返回true,否则返回false
    • eachTreeData

      public static <T> void eachTreeData(List<T> data, Consumer<T> consumer, Function<T,List<T>> mapper)
      遍历树形结构数据
      类型参数:
      T - 数据的类型
      参数:
      data - 树形结构数据列表
      consumer - 对每个节点执行的操作
      mapper - 获取子节点列表的Function
    • listGetOne

      public static <T> T listGetOne(List<T> records)
      获取集合中的第一条数据
      类型参数:
      T - 数据类型
      参数:
      records - 数据集合
      返回:
      集合中的第一条数据,如果集合为空则返回null
    • addCrossHeaders

      public static void addCrossHeaders(jakarta.servlet.http.HttpServletResponse response)
      添加跨域请求头信息
      参数:
      response - HttpServletResponse对象
    • responseError

      public static void responseError(jakarta.servlet.http.HttpServletResponse response, String code, String message, String error)
      向客户端输出错误信息
      参数:
      response - HttpServletResponse对象
      code - 错误码
      message - 提示信息
      error - 错误详细信息