类 Utils

java.lang.Object
com.gdxsoft.easyweb.utils.Utils

public class Utils extends Object
  • 构造器详细资料

    • Utils

      public Utils()
  • 方法详细资料

    • getJavascript

      public static String getJavascript(String s1)
    • getAlertScript

      public static String getAlertScript(String s1)
    • randomStr

      public static String randomStr(int length)
      利用随机数生成字符串
      参数:
      length - 生成的长度
      返回:
      随机数生成字符串
    • toJsonPair

      public static String toJsonPair(String name, String value)
      生成Json成对表达式
      参数:
      name - 名称
      value - 值
      返回:
      Json成对表达式
    • timeDiffHours

      public static long timeDiffHours(Date t1, Date t2)
      t1-t2的间隔小时数
      参数:
      t1 - 时间1
      t2 - 时间2
      返回:
      t1-t2的间隔小时数
    • timeDiffDays

      public static long timeDiffDays(Date t1, Date t2)
      t1-t2的间隔天数
      参数:
      t1 - 时间1
      t2 - 时间2
      返回:
      t1-t2的间隔天数
    • timeDiffMinutes

      public static long timeDiffMinutes(Date t1, Date t2)
      t1-t2的间隔分钟数
      参数:
      t1 - 时间1
      t2 - 时间2
      返回:
      t1-t2的间隔分钟数
    • timeDiffSeconds

      public static long timeDiffSeconds(Date t1, Date t2)
      t1-t2的间隔秒数
      参数:
      t1 - 时间1
      t2 - 时间2
      返回:
      t1-t2的间隔秒数
    • timeDiffMSeconds

      public static long timeDiffMSeconds(Date t1, Date t2)
      t1-t2的间隔毫秒
      参数:
      t1 - 时间1
      t2 - 时间2
      返回:
      t1-t2的间隔毫秒
    • split2String

      public static String[][] split2String(String s1, String splitString0, String splitString1)
      分割双重数组
      参数:
      s1 - 字符串
      splitString0 - 第一层数组分割符
      splitString1 - 第二层数组分割符
      返回:
      双重数组
    • splitString

      public static String[] splitString(String s1, String splitString)
      分割字符串,内容中若保留分割符,则表示两次,如“,”分割的话,内容中保留则通过",,"表示
      参数:
      s1 - 字符
      splitString - 分割符
      返回:
      数组
    • cvtBool

      public static boolean cvtBool(Object object)
      Converts a Object to a boolean
      Utils.cvtBool(null) = false
      Utils.cvtBool("true") = true
      Utils.cvtBool("TRUE") = true
      Utils.cvtBool("tRUe") = true
      Utils.cvtBool("on") = true
      Utils.cvtBool("yes") = true
      Utils.cvtBool("是") = true
      Utils.toBoolean("y") = true
      Utils.toBoolean("t") = true
      参数:
      object - the Object to check
      返回:
      boolean result
    • cvtInteger

      public static Integer cvtInteger(String v)
      将字符串转换为整型,并忽略错误
      参数:
      v - 对象
      返回:
      整型
    • cvtInt

      public static int cvtInt(String v)
      将字符串转换为整数,并忽略错误
      参数:
      v - 对象
      返回:
      如果为null, 返回 0
    • arrayJoin

      public static String arrayJoin(String[] arr, String joinString)
      将数组拼接为字符串
      参数:
      arr - 字符串数组
      joinString - 拼接字符串
      返回:
      数组拼接为字符串
    • createEncryptString

      @Deprecated public static String createEncryptString(String s1)
      已过时。
      同 sha1, sha1 摘要
      参数:
      s1 - 原始字符
      返回:
      sha1 摘要(HEX)
    • sha1

      public static String sha1(byte[] bytes)
      取bytes的 sha1 摘要
      参数:
      bytes - 二进制数组
      返回:
      sha1 摘要(HEX)
    • sha1

      public static String sha1(String str)
      取str的 sha1 摘要
      参数:
      str - 字符串
      返回:
      sha1 摘要(HEX)
    • md5

      public static String md5(byte[] bytes)
      取bytes的md5摘要
      参数:
      bytes - 二进制数组
      返回:
      md5摘要(HEX)
    • md5

      public static String md5(String str)
      取str的md5摘要
      参数:
      str - 字符串
      返回:
      md5摘要(HEX)
    • bytes2hex

      public static String bytes2hex(byte[] b)
      将byte数组转换为16进制字符串
      参数:
      b - byte数组
      返回:
      16进制字符串
    • byte2hex

      @Deprecated public static String byte2hex(byte[] b)
      已过时。
      拼写错误,请用 bytes2hex 将byte数组转换为16进制字符串
      参数:
      b - byte数组
      返回:
      16进制字符串
    • hex2bytes

      public static byte[] hex2bytes(String hexs)
      转换 hex字符串为二进制
      参数:
      hexs - hex字符串
      返回:
      二进制
    • getUtf8

      public static String getUtf8(String s1)
      转换为utf8
      参数:
      s1 - iso8859编码字符串
      返回:
      utf8字符串
    • getGbk

      public static String getGbk(String s1)
      转换为gbk
      参数:
      s1 - iso8859编码字符串
      返回:
      gbk字符串
    • getParameters

      public static ArrayList<String> getParameters(String s1, String tagStart, String tagEnd)
      获取被前后标记包围的内容,例如{12121}
      参数:
      s1 - 原始内容
      tagStart - 开始字符串
      tagEnd - 结束字符串
      返回:
      参数数组
    • getParameters

      public static MListStr getParameters(String sql, String tag)
      获取字符串中的参数(含中文)
      例如:{CALL PR_EWA_HOR_STR (@a, @CO_UNID, @姓名, @姓名.hash)}
      参数:
      sql - 字符串
      tag - 参数前导字符例如 @
      返回:
      参数表
    • testString

      public static boolean testString(String sourceString, String regexString)
      正则测试
      参数:
      sourceString - 字符串
      regexString - 正则
      返回:
      测试结果
    • getSqlSplit

      public static String[] getSqlSplit(String sql, String tag)
      分割字符串为数组
      参数:
      sql - 字符串
      tag - 分割标记
      返回:
      数组
    • textToInputValue

      public static String textToInputValue(String text)
      将纯文本转换成input/textarea所需格式
      参数:
      text - 文本
      返回:
      input/textarea所需格式
    • textToHtml

      public static String textToHtml(String text)
      将纯文本转换为HTML
      参数:
      text -
      返回:
      HTML
    • textToJscript

      public static String textToJscript(String text)
      生成脚本可以使用的文字,替换回车,双引号和 ”\“符
      参数:
      text - 原始文字
      返回:
      替换后的js文字
    • textToUrl

      public static String textToUrl(String text)
      URLEncoder.encode (UTF-8)编码
      参数:
      text - 明文
      返回:
      编码后的字符串
    • urlToText

      public static String urlToText(String urlEncoder)
      URLDecoder.decode (UTF-8) 解码
      参数:
      urlEncoder - URLEncoder的字符串
      返回:
      解码后的字符串
    • encodeUrl

      public static String encodeUrl(String s)
      生成编码的URL
      参数:
      s - 字符串
      返回:
      编码后的url
    • getTimeDiffValue

      public static Object getTimeDiffValue(Object oriValue, int timeDiffMinutes)
      获取时间与时差计算后的结果
      参数:
      oriValue -
      timeDiffMinutes -
      返回:
      新时间(根据oriValue 的 class,创建 JAVA.SQL.TIMESTAMP/java.util.Date)
    • getDateString

      public static String getDateString(Timestamp t1, String dateformatString)
      获取时间格式
      参数:
      t1 - 时间
      dateformatString - 格式
      返回:
      格式后的时间
    • getDateGMTString

      public static String getDateGMTString(Date date)
      获取GMT(0)时间表达式,用于 Last-Modified等
      参数:
      date - 时间
      返回:
      GMT时间
    • getDateGMTString

      public static String getDateGMTString(Timestamp t1)
      获取GMT(0)时间表达式,用于 Last-Modified等
      参数:
      t1 - 时间
      返回:
      GMT时间
    • getDateGMTString

      public static String getDateGMTString(Calendar calendar)
      获取GMT(0)时间表达式,用于 Last-Modified等
      参数:
      calendar - 时间
      返回:
      GMT时间
    • getDateXmlString

      public static String getDateXmlString(Object t1)
      返回时间的xml格式,yyyy-mm-ddTHH:MM:SS
      参数:
      t1 - 时间
      返回:
      xml格式,yyyy-mm-ddTHH:MM:SS
    • getDateString

      public static String getDateString(Calendar calendar, String dateformatString)
      获取指定格式的 日期字符串
      格式例如 yyyy-MM-dd HH:mm:ss
      参数:
      calendar - 时间
      dateformatString - (yyyy-MM-dd HH:mm:ss)
      返回:
      格式的 日期字符串
    • getDateString

      public static String getDateString(Date date, String dateformatString)
      获取指定格式的 日期字符串
      格式例如 yyyy-MM-dd HH:mm:ss
      参数:
      date - 时间
      dateformatString - (yyyy-MM-dd HH:mm:ss)
      返回:
      格式的 日期字符串
    • getDateString

      public static String getDateString(Date date)
      获取默认格式 日期 ,例如2011-04-02
      参数:
      date - 时间
      返回:
      默认格式 日期
    • getDateTimeString

      public static String getDateTimeString(Date date)
      获取默认格式 日期和时间 ,例如 2011-04-02 11:29:31
      参数:
      date - 时间
      返回:
      默认格式 日期和时间
    • getTimeString

      public static String getTimeString(Date date)
      获取默认格式 时间 ,例如 11:29:31
      参数:
      date - 时间
      返回:
      默认格式 时间
    • getGuid

      public static String getGuid()
      获取 UUID
      返回:
      UUID字符串
    • getOptions

      public static String getOptions(String valueList, String textList, String v1)
      获取SELECT的OPTION列表
      参数:
      valueList - Option 的 value列表,用”,“分割
      textList - Option 的 text列表,用”,“分割
      v1 - 当前值
      返回:
      Options
    • getDays

      public static int getDays(Date date1)
      获取和当天的日期天数
      参数:
      date1 -
      返回:
      天数
    • getDays

      public static int getDays(Date date1, Date date2)
      返回两个日期之间的天数
      参数:
      date1 -
      date2 -
      返回:
      两个日期之间的天数
    • getDate

      public static Date getDate(String dateString)
      根据字符串返回日期
      参数:
      dateString - yyyy-MM-dd,MM/dd/yyyy,8位数字
      返回:
      日期
    • getDate

      public static Date getDate(String dateString, String dateFormat)
      根据字符返回日期
      参数:
      dateString - 日期字符串
      dateFormat - 日期格式
      返回:
      日期
    • getTimestamp

      public static Timestamp getTimestamp(String s1, String lang, boolean isUKFormat)
      获取sql的timestamp
      参数:
      s1 - 日期字符串
      lang - 语言
      isUKFormat - 当lang=enus时,是否为英式
      返回:
      sql的timestamp
    • getDisplayWidth

      public static int getDisplayWidth(String s1)
      计算显示的宽度
      参数:
      s1 - 字符串
      返回:
      显示的宽度
    • replaceStringBuilder

      public static void replaceStringBuilder(StringBuilder source, String findString, String replaceString)
      替换 StringBuilder 的字符串
      参数:
      source - StringBuilder源
      findString - 需要替换的文字
      replaceString - 替换的内容
    • deleteStr

      public static String deleteStr(String source, String find1, String find2)
      删除字符串中的内容
      参数:
      source - 源
      find1 - 开始查找的字符串
      find2 - 后面查找的字符串
      返回:
      删除字符串中的内容
    • filterHtml

      public static String filterHtml(String str)
      基本功能:过滤所有以"<"开头以">"结尾的标签
      参数:
      str - 字符串
      返回:
      String 过滤后的结果
    • replaceHtmlTag

      public static String replaceHtmlTag(String str, String beforeTag, String tagAttrib, String startTag, String endTag)
      基本功能:替换指定的标签

      参数:
      str -
      beforeTag - 要替换的标签
      tagAttrib - 要替换的标签属性值
      startTag - 新标签开始标记
      endTag - 新标签结束标记
      返回:
      String @如:替换img标签的src属性值为[img]属性值[/img]