1. [my] mybatis 全局配置文件
<플러그인> <플러그인 인터셉터 = "com.has.core.page.paginationinterceptor" /> < /plugins>
2. [pag] Pagination Interceptor.java
@intercepts ({@signature (type = stationhandler. class, method = "repary", args = {connection. class}}) public class pageinationinterceptor interceptor {@overridepublic 객체 intercept (invocation intercept (invocation) invocation {stateHandler haterHandler = (stateHandler) invocation.getTarget (); stateHandler.getBoundSql (); metaobject metastatementHandler = metaObject.forObject (stateHandler); rowBounds rowbounds = (rowbounds) metastatementHandler.getValue ( "delegate.rowbounds"); invocation.proeuse ();} configuration configuration = (configuration) metastatementhandler.getValue ( "delegate.configuration"); dialect.type databasetype = null; try {databasetype = divelect.type.valueof (succiveration.variberty ()).) (예외 e) if (databaseType == null) {새로운 runtimeexception 던지기 ( "configuration.xml의 방언 속성 값은 정의되지 않습니다 :"+ configuration.getVariables (). getProperty ( "dialect"); mysql5dialect (); break; case oracle : dialect = new oracledialect (); break;} string originalsql = (string) metastatementhandler.getValue ( "delegate.boundsql.sql"); metastatementHandler.setValue ( "delegate.boundsql.sql", delect.getLimittring, rowbounds.getOffset (), rowbounds.getLimit ())); metastatementHandler.setValue ( "delegate.rowbounds.offset", rowbounds.no_row_offset); metastatementHandler.setValue ( "delegate.rowbeds.limit", rowbounds.no_row_limit); invocation.proceed ();}@overridepublic 객체 플러그인 (객체 대상) {return plugin.wrap (target, this);}@attradepublic void setProperties (속성 속성) {}}3. [dial] Dialect.java
/******/public static enum clistect {public static enum yfect {mysql, oracle} public acpract string getLimitstring (String SQL, int skipresults, int maxresults);}4. [my] mysql5dialect.java
/*** mysql 方言分页类*/public class mysql5dialect는 방언 {보호 된 정적 최종 문자열 sql_end_delimiter = ";" ; public String getLimitstring (String SQL, Boolean Hasoffset) {return mysql5pagehepler.getlimitstring (sql, -1, -1);} public string getLimitstring (String sql, int offset, int limit) {return mysql5pageHepler.getlimitstring (sql, leture, offset, intlimitstring); supportSlimit () {return true;}}5. [or] oracledialect.java
package com.chyjr.has.core.page.dialect;/*** oracel 方言分页**/public class oracledialect는 방언 {public string getLimitstring (String SQL, int Offset, Int Limit) {// todo 未实现 return ";}}6. [my] mysql5pagehepler.java
import java.util.regex.matcher; import java.util.regex.pattern;/*** mysql*/public class mysql5pagehepler {/*** 得到查询总数的 sql*/public string getCountstring (string QuerySelect) {querySelect = getLinesQl (queryTect); getLastOrderInsertPoint (QuerySelect); int formIndex = getAfterformInsertPoint (QuerySelect); String select = QuerySelect.subString (0, formIndex); // select 中包含 contret 只能在外层包含 countif (select.tolowercase ( "select sorpt")! = - 1 || querySelect.tolowercase ()). {새 StringBuffer (QuerySelect.length ()). Append ( "Count (1) Count From (") .append (QuerySelect.SubString (0, OrderIndex)). Append ( ") T") .ToString ();} else {return new stringBuffer (QuerySelect.length ()). Count ( "Count (1) Count (1) Count (1)". )) ! isbracketCanPartNership (QuerySelect.subString (OrderIndex, QuerySelect.length ())) {새로운 runtimeexception ( "나의 sql 分页必须要有 주문 语句! getLimitstring (String QuerySelect, int Offset, int Limit) {querySelect = getLinesql (QuerySelect); // String SQL = QuerySelect.Replaceall ( "[^// s,] + //", ",") + " + // offset +", " + limit +" + " +" + " +" + " +" + "QueryTect; sql;}/*** 将 sql 语句变成一条语句 语句变成一条语句, 并且每个单词的间隔都是 1 个空格 ** @param sql* sql* @return 如果 sql 是 null 返回空, 否则返回转化后的 sql*/private static string getLinesql (string sql) {return sql.replaceall ( "[/r/n]", "", "", "). "// s {2,}", "");}/***} 得到 得到 得到 sql 第一个正确的/private static int getafterforminsertpoint (string querySelect) {string regex = "// s+from // s+"; Pattern.compile (regex, pattern.case_insensitive); matcher (qupernect); {int fromstartIndex = matcher.start (0); String text = QuerySelect.SubString (0, fromstartIndex); if (isbracketCanPartNership (텍스트)) {return in}} 반환 0;}/*** 判断括号 "()"() ""是否匹配 ** @Param text* @retren, @reteren an true, @reteren an true, isbracketcanpartnership (문자열 텍스트) {if (text == null || (getIndexOfCount (텍스트, '(')! = getIndexOfCount (text, '' ')))) {return false;} return true;}/*** 得到一个字符在另一个字符串中出现的次数 ** @param text* 文本* @param ch* 字符*/private int gettatic int {static chount (string) {strat gettatic int gettatic int gettic int i = 0; i <text.length (); count = (text.charat (i) == ch)? count + 1 : count;} return count;}}2. [my] mybatis.jpg