【蜕变之路】第46天 字符串校验与SQL查询(2019年10月26日)

    Hello,大家好!我是程序员阿飞!今天主要给大家分享一下上周项目中遇见的字符串校验以及多个重复字段只保留一条数据的SQL写法。

    一、判断字符串是否为汉字

        1、判断字符串是否包含汉字   

        public boolean checkcountname(String countname)

            {

                 Pattern p = Pattern.compile("[\u4e00-\u9fa5]");

                    Matcher m = p.matcher(countname);

                    if (m.find()) {

                        return true;

                    }

                    return false;

          }

        2、判断字符串是否都是由汉字组成

        public boolean checkname(String name)

            {

                int n = 0;

                for(int i = 0; i < name.length(); i++) {

                    n = (int)name.charAt(i);

                    if(!(19968 <= n && n <40869)) {

                        return false;

                    }

                }

                return true;

            }

        3、参考网址:https://blog.csdn.net/changjiale110/article/details/78915969

    二、UUID的校验

        1、生产UUID的方法     

        public static UUID getRandomUUID(String str) {

            // 产生UUID

            if (str == null) {

                return UUID.randomUUID();

            } else {

            return UUID.nameUUIDFromBytes(str.getBytes());

            }

        }

        2、判断是否为UUID        

        public static boolean isValidUUID(String uuid) {

            // UUID校验

            if (uuid == null) {

                System.out.println("uuid is null");

            }

            String regex = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";

            if (uuid.matches(regex)) {

                return true;

            }

            return false;

        }

        3、参考网址:https://blog.csdn.net/Kangyucheng/article/details/86498341

    三、SQL多个重复字段只保留一条数据

        SELECT * FROM test1 GROUP BY  factory_name,model_name,hard_version HAVING count(*)>=1

    参考网址:https://blog.csdn.net/sxf_123456/article/details/77509201

    四、分享时刻

        1、https://u.tools/

    2、https://cloudstudio.net/

    3、http://yearning.io/





猜你喜欢

转载自blog.51cto.com/12388374/2445720