分页过滤SQL求总条数SQL正则
Posted 孟尧
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了分页过滤SQL求总条数SQL正则相关的知识,希望对你有一定的参考价值。
public static void main(String[] args) throws Exception { String queryForScanUsers_SQL = "select a.username AS user_name,b.* from tbl_aaa a left join tbl_bbb b where a.id=? limit 10"; //去除WHERE和LIMIT String sqlRegex = "(select\\s+)(.*)(\\s+from)(.+?(?=limit|where))"; Pattern p = Pattern.compile(sqlRegex, Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(queryForScanUsers_SQL); while (m.find()) { //SELECT System.out.println(m.group(1).trim()); //Columns,分页中求总条数需替换成COUNT(1) System.out.println(m.group(2).trim()); //FROM System.out.println(m.group(3).trim()); //Tables System.out.println(m.group(4).trim()); } HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat(); format.setCaseType(HanyuPinyinCaseType.LOWERCASE); //小写拼音字母 format.setToneType(HanyuPinyinToneType.WITHOUT_TONE); //不加语调标识 format.setVCharType(HanyuPinyinVCharType.WITH_V); //u:的声母替换为v StringBuilder sb = new StringBuilder(); System.out.println(PinyinHelper.toHanyuPinyinString("张三feng", format, "")); }
以上是关于分页过滤SQL求总条数SQL正则的主要内容,如果未能解决你的问题,请参考以下文章