zoukankan      html  css  js  c++  java
  • java 特殊方法

     /**
         * 将请求入参中的 long类型日期转化为 标准日期
         * @param map
         * @param params
         */
        public static void filterDateTypeJsonString(Map<String, Object> map,String ... params)  {
            for (String key : params) {
                map.put(key, new Date((Long) map.get(key)));
            }
        }
    
        /**
         * keyvalue 22 toMap
         * @param arg
         * @return
         */
        public static Map<String,Object> parseMap(Object ... arg) {
            Map<String, Object> map = new HashMap<>();
            for (int i = 0; i < arg.length; i+=2) {
                map.put(arg[i]+"", arg[i + 1]);
            }
            return map;
        }
    
        /**
         * 去前后空格后是否为空
         * @param s
         * @return
         */
        public static boolean isNotEmptyAfterTrim(String s){
            if (StringUtils.isNotEmpty(s)){
                if (s.trim().length()!=0){
                    return true;
                }
            }
            return false;
        }
    
        /**
         * 将异常转化为字符串
         * @param e
         * @return
         */
        public static String parseException(Exception e) {
            try {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                e.printStackTrace(pw);
                return "
    " + sw.toString() + "
    ";
            } catch (Exception e2) {
                return "bad getErrorInfoFromException";
            }
        }
    
        /**
         * 判断是否含有特殊字符
         *
         * @param str
         * @return true为包含,false为不包含
         */
        public static boolean isContainSpecialChar(String str) {
            String regEx = "[ _`~!@#$%^&*()+=|{}':;',\[\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]|
    |
    |	";
            Pattern p = Pattern.compile(regEx);
            Matcher m = p.matcher(str);
            return m.find();
        }
    
        /**
         * 是否包含中文
         * @param str
         * @return
         */
        public static boolean isContainChinese(String str) {
    
            Pattern p = Pattern.compile("[u4e00-u9fa5]");
            Matcher m = p.matcher(str);
            if (m.find()) {
                return true;
            }
            return false;
        }
    

      

  • 相关阅读:
    Spring Security 自动装配
    Mysql学习
    java 学习路线(bilibili)
    Mac上配置idea的项目上传到GitHub
    vim安装自动补全插件
    spring aop 获取request、response对象
    centos7配置本地yum源 使用安装镜像安装软件
    eclipse启动速度优化
    spring-mvc springboot 使用MockMvc对controller进行测试
    java web 验证码-字符变形(推荐)
  • 原文地址:https://www.cnblogs.com/zfzf1/p/8431965.html
Copyright © 2011-2022 走看看