程序包 com.mbap.core.ct

类 CommonUtil

java.lang.Object
com.mbap.core.ct.CommonUtil

public class CommonUtil extends Object
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    关于script的脚本正则匹配集合
  • 构造器概要

    构造器
    构造器
    说明
     
  • 方法概要

    修饰符和类型
    方法
    说明
    static String
    清除script脚本和事件如onclick等
    static String
    cleanScript(String paramValue)
    清除参数中的script脚本语句
    static List<Object>
    convertSql(String searchCondition, String initSql, List<Object> valList)
    功能描述:转换sql,防止sql注入,把前端的查询条件和自定义的查询条件拼接,并分离为带占位符的语句和参数
    static String
    escape(String html)
    功能描述:对带有特殊符号的内容转义<>空格和"
    static String
    getSqlStr(int size)
    功能描述:根据参数个数参数形如“?,?”这样的语句串
    static String
    功能描述:把逗号分割的参数按其格式产生形如“?,?,?”的语句
    static String
    功能描述:利用jsoup清除不可信任的危险标签和属性,属性如onclick 标签如iframe,script,style
    static <T> List<T>
    parseArrToList(T[] arr)
    功能描述:将数组转化为list
    static String
    preventAttack(String[] characterParams, String paramValue)
    功能描述:防止跨站攻击
    static String
    过滤参数中,可能的scrip脚本语句,主要常见于,在前台如果在自己的script标签内,用el表达式接收存储过的值时,参数项可能被解析为脚本,例如: 在编辑 页面存入一行代码 test=\" alert(1);\" 前台用el表达式在script标签里接收为 var test="${test}" ===> var test="" alert(1); ""
    static String
    preventAttackWithRegx(String regx, String paramValue)
    使用正则表达式,分组匹配替换参数中的非法字符
    static String
    replaceAllIgnoreCase(String str, String regex, String replacement)
    忽略大小写的替换字符串中的特征字符串
    static String
    teshfhClean(String parameter, String paramValue)
    功能描述:根据参数名称,参数值 对入参的值进行拦截过滤
    static String
    transOrSQL(String column, int argSize)
    功能描述:根据入参argSize,生成对应个数的带有or的hql串如 or id= ?
    static String
    功能描述:去掉字符串中所有的空格、制表符、换行、回车

    从类继承的方法 java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 字段详细资料

    • regxMap

      public static HashMap<String,String> regxMap
      关于script的脚本正则匹配集合
  • 构造器详细资料

    • CommonUtil

      public CommonUtil()
  • 方法详细资料

    • getSqlStr

      public static String getSqlStr(int size)
      功能描述:根据参数个数参数形如“?,?”这样的语句串
      参数:
      size - 参数个数
      返回:
      形如“?,?,?”的sql拼接
    • getSqlStr

      public static String getSqlStr(String str)
      功能描述:把逗号分割的参数按其格式产生形如“?,?,?”的语句
      参数:
      str - 形如 2,4,3这样逗号分割的参数
      返回:
      形如“?,?,?”的sql拼接
    • transOrSQL

      public static String transOrSQL(String column, int argSize)
      功能描述:根据入参argSize,生成对应个数的带有or的hql串如 or id= ?
      参数:
      column - 列名
      argSize - 个数
      返回:
      形如“id=? or id=? or id=?”的sql拼接
    • convertSql

      public static List<Object> convertSql(String searchCondition, String initSql, List<Object> valList)
      功能描述:转换sql,防止sql注入,把前端的查询条件和自定义的查询条件拼接,并分离为带占位符的语句和参数
      参数:
      searchCondition -
      initSql -
      valList -
      返回:
      List 第一个值为查询条件 第二个值为查询条件对应的val数组(取出该值,强转为object数组)
    • preventAttack

      public static String preventAttack(String[] characterParams, String paramValue)
      功能描述:防止跨站攻击
      参数:
      characterParams - 过滤字符
      paramValue - 参数值
      返回:
    • preventAttackScript

      public static String preventAttackScript(String paramValue)
      过滤参数中,可能的scrip脚本语句,主要常见于,在前台如果在自己的script标签内,用el表达式接收存储过的值时,参数项可能被解析为脚本,例如: 在编辑 页面存入一行代码 test=\" alert(1);\" 前台用el表达式在script标签里接收为 var test="${test}" ===> var test="" alert(1); ""
      参数:
      paramValue -
      返回:
    • cleanScript

      public static String cleanScript(String paramValue)
      清除参数中的script脚本语句
      参数:
      paramValue -
      返回:
    • preventAttackWithRegx

      public static String preventAttackWithRegx(String regx, String paramValue)
      使用正则表达式,分组匹配替换参数中的非法字符
      参数:
      regx - 正则表达式
      paramValue - 需过滤的参数项
      返回:
    • cleanForCms

      public static String cleanForCms(String html)
      清除script脚本和事件如onclick等
      参数:
      html - 待处理文本
      返回:
      清理过的文本
    • JsoupClean

      public static String JsoupClean(String html)
      功能描述:利用jsoup清除不可信任的危险标签和属性,属性如onclick 标签如iframe,script,style
      参数:
      html - 原始内容
      返回:
    • escape

      public static String escape(String html)
      功能描述:对带有特殊符号的内容转义<>空格和"
      参数:
      html - 原文本
      返回:
    • trimAll

      public static String trimAll(String str)
      功能描述:去掉字符串中所有的空格、制表符、换行、回车
      参数:
      str - 需要替换的字符串
      返回:
      匹配替换后的字符串
    • parseArrToList

      public static <T> List<T> parseArrToList(T[] arr)
      功能描述:将数组转化为list
      参数:
      arr -
      返回:
    • teshfhClean

      public static String teshfhClean(String parameter, String paramValue)
      功能描述:根据参数名称,参数值 对入参的值进行拦截过滤
      参数:
      parameter - 参数名
      paramValue - 参数值
      返回:
    • replaceAllIgnoreCase

      public static String replaceAllIgnoreCase(String str, String regex, String replacement)
      忽略大小写的替换字符串中的特征字符串
      参数:
      str - 原字符串
      regex - 等待被替换的字符串
      replacement - 替换的字符串
      返回: