Java格式化mysql语句问题

问题遇到的现象和发生背景

想利用jexlEngine将sql当成代码执行,遇到格式化转换问题;

jexlEngine的等号(=)要两个等号(==)才能正常转换,当where条件是(==)则正常,如果是一个(=)或者(= =)中间有空格,我怎么判断将=好转两个==

遇到的现象和发生背景

代码如下:怎么修改才能判断到是一个=还是两个=,怎么去 = = 中间的空格?



String where = "pay_time >= '2019/10/21' and pay_time <= '2019/10/22' and pay_time = = '2019/10/22'";


public static String formatWhere(String where){

   if (where.contains("=")) {
//            where = where.replace(" ", "");
            List<Integer> strAllIndex = getStrAllIndex(where, "=");
            for (int i = 0; i < strAllIndex.size(); i++) {
                Integer index = strAllIndex.get(i);
                String targetBefore = Character.toString(where.charAt(index - 1));
                String targetEnd = Character.toString(where.charAt(index + 1));
                if (!">".equals(targetBefore) && !"<".equals(targetBefore) && !"=".equals(targetBefore) && !"!".equals(targetBefore)) {
                    if (!"=".equals(targetEnd)) {
                        where = where.substring(0, index) + "==" + where.substring(index + 1);
                    }
                }
            }
        }

        if (where.contains(" and ")) {
            where = where.replace(" and ", " && ");
        }

        if (where.contains(" AND ")) {
            where = where.replace(" AND ", " && ");
        }

        if (where.contains(" or ")) {
            where = where.replace(" or ", " || ");
        }

        if (where.contains(" OR ")) {
            where = where.replace(" OR ", " || ");
        }

//        System.out.println("where:" + where);
//        return where;

}

回答:实际判断 "= =",非常简单,且转换起来也很容易,只需要得到“=”的下标,并判断在"="后面接着出现的是否是" ="即可,如果是的话,就将这三个下标改为"=="即可,这里的话需要用到字符串拼接了,拼接出新的字符串,采用StringBuffer即可