类 SaFoxUtil

java.lang.Object
cn.dev33.satoken.util.SaFoxUtil

public class SaFoxUtil extends Object
Sa-Token 内部工具类
作者:
kong
  • 字段详细资料

    • URL_REGEX

      public static final String URL_REGEX
      验证URL的正则表达式
      另请参阅:
    • logLevelList

      public static List<String> logLevelList
  • 方法详细资料

    • printSaToken

      public static void printSaToken()
      打印 Sa-Token 版本字符画
    • getRandomString

      public static String getRandomString(int length)
      生成指定长度的随机字符串
      参数:
      length - 字符串的长度
      返回:
      一个随机字符串
    • isEmpty

      public static boolean isEmpty(Object str)
      指定元素是否为null或者空字符串
      参数:
      str - 指定元素
      返回:
      是否为null或者空字符串
    • isNotEmpty

      public static boolean isNotEmpty(Object str)
      指定元素是否不为 (null或者空字符串)
      参数:
      str - 指定元素
      返回:
      是否为null或者空字符串
    • isEmpty

      public static <T> boolean isEmpty(T[] array)
      指定数组是否为null或者空数组
      类型参数:
      T - /
      参数:
      array - /
      返回:
      /
    • equals

      public static boolean equals(Object a, Object b)
      比较两个对象是否相等
      参数:
      a - 第一个对象
      b - 第二个对象
      返回:
      两个对象是否相等
    • notEquals

      public static boolean notEquals(Object a, Object b)
      比较两个对象是否不相等
      参数:
      a - 第一个对象
      b - 第二个对象
      返回:
      两个对象是否不相等
    • getMarking28

      public static String getMarking28()
      以当前时间戳和随机int数字拼接一个随机字符串
      返回:
      随机字符串
    • formatDate

      public static String formatDate(Date date)
      将日期格式化 (yyyy-MM-dd HH:mm:ss)
      参数:
      date - 日期
      返回:
      格式化后的时间
    • formatDate

      public static String formatDate(ZonedDateTime zonedDateTime)
      将日期格式化 (yyyy-MM-dd HH:mm:ss)
      参数:
      zonedDateTime - 日期
      返回:
      格式化后的时间
    • formatAfterDate

      public static String formatAfterDate(long ms)
      指定毫秒后的时间(格式化 :yyyy-MM-dd HH:mm:ss)
      参数:
      ms - 指定毫秒后
      返回:
      格式化后的时间
    • searchList

      public static List<String> searchList(Collection<String> dataList, String prefix, String keyword, int start, int size, boolean sortType)
      从集合里查询数据
      参数:
      dataList - 数据集合
      prefix - 前缀
      keyword - 关键字
      start - 起始位置 (-1代表查询所有)
      size - 获取条数
      sortType - 排序类型(true=正序,false=反序)
      返回:
      符合条件的新数据集合
    • searchList

      public static List<String> searchList(List<String> list, int start, int size, boolean sortType)
      从集合里查询数据
      参数:
      list - 数据集合
      start - 起始位置
      size - 获取条数 (-1代表从start处一直取到末尾)
      sortType - 排序类型(true=正序,false=反序)
      返回:
      符合条件的新数据集合
    • vagueMatch

      public static boolean vagueMatch(String patt, String str)
      字符串模糊匹配

      example:

      user* user-add -- true

      user* art-add -- false

      参数:
      patt - 表达式
      str - 待匹配的字符串
      返回:
      是否可以匹配
    • isWrapperType

      public static boolean isWrapperType(Class<?> cs)
      判断类型是否为8大包装类型
      参数:
      cs - /
      返回:
      /
    • isBasicType

      public static boolean isBasicType(Class<?> cs)
      判断类型是否为基础类型:8大基本数据类型、8大包装类、String
      参数:
      cs - /
      返回:
      /
    • getValueByType

      public static <T> T getValueByType(Object obj, Class<T> cs)
      将指定值转化为指定类型
      类型参数:
      T - 泛型
      参数:
      obj - 值
      cs - 类型
      返回:
      转换后的值
    • joinParam

      public static String joinParam(String url, String parameStr)
      在url上拼接上kv参数并返回
      参数:
      url - url
      parameStr - 参数, 例如 id=1001
      返回:
      拼接后的url字符串
    • joinParam

      public static String joinParam(String url, String key, Object value)
      在url上拼接上kv参数并返回
      参数:
      url - url
      key - 参数名称
      value - 参数值
      返回:
      拼接后的url字符串
    • joinSharpParam

      public static String joinSharpParam(String url, String parameStr)
      在url上拼接锚参数
      参数:
      url - url
      parameStr - 参数, 例如 id=1001
      返回:
      拼接后的url字符串
    • joinSharpParam

      public static String joinSharpParam(String url, String key, Object value)
      在url上拼接锚参数
      参数:
      url - url
      key - 参数名称
      value - 参数值
      返回:
      拼接后的url字符串
    • spliceTwoUrl

      public static String spliceTwoUrl(String url1, String url2)
      拼接两个url

      例如:url1=http://domain.cn,url2=/sso/auth,则返回:http://domain.cn/sso/auth

      参数:
      url1 - 第一个url
      url2 - 第二个url
      返回:
      拼接完成的url
    • arrayJoin

      public static String arrayJoin(String[] arr)
      将数组的所有元素使用逗号拼接在一起
      参数:
      arr - 数组
      返回:
      字符串,例: a,b,c
    • isUrl

      public static boolean isUrl(String str)
      使用正则表达式判断一个字符串是否为URL
      参数:
      str - 字符串
      返回:
      拼接后的url字符串
    • encodeUrl

      public static String encodeUrl(String url)
      URL编码
      参数:
      url - see note
      返回:
      see note
    • decoderUrl

      public static String decoderUrl(String url)
      URL解码
      参数:
      url - see note
      返回:
      see note
    • convertStringToList

      public static List<String> convertStringToList(String str)
      将指定字符串按照逗号分隔符转化为字符串集合
      参数:
      str - 字符串
      返回:
      分割后的字符串集合
    • convertListToString

      public static String convertListToString(List<?> list)
      将指定集合按照逗号连接成一个字符串
      参数:
      list - 集合
      返回:
      字符串
    • convertStringToArray

      public static String[] convertStringToArray(String str)
      String 转 Array,按照逗号切割
      参数:
      str - 字符串
      返回:
      数组
    • convertArrayToString

      public static String convertArrayToString(String[] arr)
      Array 转 String,按照逗号连接
      参数:
      arr - 数组
      返回:
      字符串
    • emptyList

      public static <T> List<T> emptyList()
      返回一个空集合
      类型参数:
      T - 集合类型
      返回:
      空集合
    • toList

      public static List<String> toList(String... strs)
      String数组转集合
      参数:
      strs - String数组
      返回:
      集合
    • translateLogLevelToInt

      public static int translateLogLevelToInt(String level)
      将日志等级从 String 格式转化为 int 格式
      参数:
      level - /
      返回:
      /
    • translateLogLevelToString

      public static String translateLogLevelToString(int level)
      将日志等级从 String 格式转化为 int 格式
      参数:
      level - /
      返回:
      /