码迷,mamicode.com
首页 > 数据库 > 详细

分页过滤SQL求总条数SQL正则

时间:2016-05-16 19:53:45      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:

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正则

标签:

原文地址:http://www.cnblogs.com/mengyao/p/5498994.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!