锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲精品99久久久久中文字幕,亚洲aⅴ无码专区在线观看春色 ,亚洲av综合avav中文http://m.tkk7.com/keweibo/category/27080.html涓涓? Java 澶氳兘 Delphi,Powerbuilder ... zh-cnThu, 01 Dec 2011 01:53:39 GMTThu, 01 Dec 2011 01:53:39 GMT60mybatis3.05 鍒嗛〉鏀惰棌http://m.tkk7.com/keweibo/articles/355693.htmlKeKeWed, 03 Aug 2011 09:15:00 GMThttp://m.tkk7.com/keweibo/articles/355693.htmlhttp://m.tkk7.com/keweibo/comments/355693.htmlhttp://m.tkk7.com/keweibo/articles/355693.html#Feedback0http://m.tkk7.com/keweibo/comments/commentRss/355693.htmlhttp://m.tkk7.com/keweibo/services/trackbacks/355693.html浠ヤ笅鍏у渚嗚嚜:
http://zhaohe162.blog.163.com/blog/static/38216797201131262952990/

1.鎶奾ibernate涓嬬殑dialect鍖呭叏閮ㄦ嫹璐濆埌mybatis鍖呯殑jdbc鐩綍涓嬶紝濡備笅鍥炬墍紺猴細

mybatis涓嬬殑鍒嗛〉錛屾敮鎸佹墍鏈夌殑鏁版嵁搴?- 鏂皹浼ょ棔 - 鏂皹灞? style=
 



2.瀹氫箟涓涓猂esultSetHandler  Interceptor

package cn.machi.utils;

import java.sql.Statement;
import java.util.Properties;

import org.apache.ibatis.executor.resultset.FastResultSetHandler;
import org.apache.ibatis.executor.resultset.ResultSetHandler;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Plugin;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.session.RowBounds;

@Intercepts( {@Signature(type = ResultSetHandler.class, method = "handleResultSets", args = {Statement.class})})
public class DiclectResultSetHandlerInterceptor implements Interceptor
{
   
    public Object intercept(Invocation invocation) throws Throwable
    {
        FastResultSetHandler resultSet = (FastResultSetHandler)invocation.getTarget();
       
        RowBounds rowBounds = (RowBounds)ReflectUtil.getFieldValue(resultSet,
                "rowBounds");
       
        if (rowBounds.getLimit() > 0
                && rowBounds.getLimit() < RowBounds.NO_ROW_LIMIT)
        {
            ReflectUtil.setFieldValue(resultSet, "rowBounds", new RowBounds());
        }
        return invocation.proceed();
    }
   
    public Object plugin(Object target)
    {
        return Plugin.wrap(target, this);
    }
   
    public void setProperties(Properties properties)
    {
    }
}

 

3.瀹氫箟涓涓猄tatementHandler鐨処nterceptor

package cn.machi.utils;

import java.sql.Connection;
import java.util.Properties;

import org.apache.ibatis.executor.statement.PreparedStatementHandler;
import org.apache.ibatis.executor.statement.RoutingStatementHandler;
import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.jdbc.dialect.OracleDialect;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Plugin;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.session.RowBounds;

@Intercepts( {@Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class})})
public class DiclectStatementHandlerInterceptor implements Interceptor
{
   
    private static final String DIALECT = "org.apache.ibatis.jdbc.dialect.OracleDialect";
   
    public Object intercept(Invocation invocation) throws Throwable
    {
        RoutingStatementHandler statement = (RoutingStatementHandler)invocation.getTarget();
        PreparedStatementHandler handler = (PreparedStatementHandler)ReflectUtil.getFieldValue(statement,
                "delegate");
        RowBounds rowBounds = (RowBounds)ReflectUtil.getFieldValue(handler,
                "rowBounds");
       
        if (rowBounds.getLimit() > 0
                && rowBounds.getLimit() < RowBounds.NO_ROW_LIMIT)
        {
            BoundSql boundSql = statement.getBoundSql();
            String sql = boundSql.getSql();
           
            OracleDialect dialect = (OracleDialect)Class.forName(DIALECT)
                    .newInstance();
            sql = dialect.getLimitString(sql,
                    rowBounds.getOffset(),
                    rowBounds.getLimit());
           
            ReflectUtil.setFieldValue(boundSql, "sql", sql);
        }
        return invocation.proceed();
    }
   
    public Object plugin(Object target)
    {
        return Plugin.wrap(target, this);
    }
   
    public void setProperties(Properties properties)
    {
    }
}

4.瀹氫箟宸ュ叿綾籖eflectUtil

package cn.machi.utils;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

import org.apache.log4j.Logger;


public class ReflectUtil
{
    private static Logger log = Logger.getLogger(ReflectUtil.class);
   
    private static Object operate(Object obj, String fieldName,
            Object fieldVal, String type)
    {
        Object ret = null;
        try
        {
            // 鑾峰緱瀵硅薄綾誨瀷 
            Class<? extends Object> classType = obj.getClass();
            // 鑾峰緱瀵硅薄鐨勬墍鏈夊睘鎬?nbsp;
            Field fields[] = classType.getDeclaredFields();
            for (int i = 0; i < fields.length; i++)
            {
                Field field = fields[i];
                if (field.getName().equals(fieldName))
                {
                   
                    String firstLetter = fieldName.substring(0, 1)
                            .toUpperCase(); // 鑾峰緱鍜屽睘鎬у搴旂殑getXXX()鏂規硶鐨勫悕瀛?nbsp;
                    if ("set".equals(type))
                    {
                        String setMethodName = "set" + firstLetter
                                + fieldName.substring(1); // 鑾峰緱鍜屽睘鎬у搴旂殑getXXX()鏂規硶 
                        Method setMethod = classType.getMethod(setMethodName,
                                new Class[] {field.getType()}); // 璋冪敤鍘熷璞$殑getXXX()鏂規硶 
                        ret = setMethod.invoke(obj, new Object[] {fieldVal});
                    }
                    if ("get".equals(type))
                    {
                        String getMethodName = "get" + firstLetter
                                + fieldName.substring(1); // 鑾峰緱鍜屽睘鎬у搴旂殑setXXX()鏂規硶鐨勫悕瀛?nbsp;
                        Method getMethod = classType.getMethod(getMethodName,
                                new Class[] {});
                        ret = getMethod.invoke(obj, new Object[] {});
                    }
                    return ret;
                }
            }
        }
        catch (Exception e)
        {
            log.warn("reflect error:" + fieldName, e);
        }
        return ret;
    }
   
    public static Object getVal(Object obj, String fieldName)
    {
        return operate(obj, fieldName, null, "get");
    }
   
    public static void setVal(Object obj, String fieldName, Object fieldVal)
    {
        operate(obj, fieldName, fieldVal, "set");
    }
   
   
    private static Method getDeclaredMethod(Object object, String methodName,
            Class<?>[] parameterTypes)
    {
        for (Class<?> superClass = object.getClass(); superClass != Object.class; superClass = superClass.getSuperclass())
        {
            try
            {
                //superClass.getMethod(methodName, parameterTypes);
                return superClass.getDeclaredMethod(methodName, parameterTypes);
            }
            catch (NoSuchMethodException e)
            {
                //Method 涓嶅湪褰撳墠綾誨畾涔? 緇х畫鍚戜笂杞瀷
            }
        }
       
        return null;
    }
   
   
    private static void makeAccessible(Field field)
    {
        if (!Modifier.isPublic(field.getModifiers()))
        {
            field.setAccessible(true);
        }
    }
   
   
    private static Field getDeclaredField(Object object, String filedName)
    {
        for (Class<?> superClass = object.getClass(); superClass != Object.class; superClass = superClass.getSuperclass())
        {
            try
            {
                return superClass.getDeclaredField(filedName);
            }
            catch (NoSuchFieldException e)
            {
                //Field 涓嶅湪褰撳墠綾誨畾涔? 緇х畫鍚戜笂杞瀷
            }
        }
        return null;
    }
   
   
    public static Object invokeMethod(Object object, String methodName,
            Class<?>[] parameterTypes, Object[] parameters)
            throws InvocationTargetException
    {
        Method method = getDeclaredMethod(object, methodName, parameterTypes);
       
        if (method == null)
        {
            throw new IllegalArgumentException("Could not find method ["
                    + methodName + "] on target [" + object + "]");
        }
       
        method.setAccessible(true);
       
        try
        {
            return method.invoke(object, parameters);
        }
        catch (IllegalAccessException e)
        {
           
        }
       
        return null;
    }
   
   
    public static void setFieldValue(Object object, String fieldName,
            Object value)
    {
        Field field = getDeclaredField(object, fieldName);
       
        if (field == null)
            throw new IllegalArgumentException("Could not find field ["
                    + fieldName + "] on target [" + object + "]");
       
        makeAccessible(field);
       
        try
        {
            field.set(object, value);
        }
        catch (IllegalAccessException e)
        {
            e.printStackTrace();
        }
    }
   
   
    public static Object getFieldValue(Object object, String fieldName)
    {
        Field field = getDeclaredField(object, fieldName);
        if (field == null)
            throw new IllegalArgumentException("Could not find field ["
                    + fieldName + "] on target [" + object + "]");
       
        makeAccessible(field);
       
        Object result = null;
        try
        {
            result = field.get(object);
        }
        catch (IllegalAccessException e)
        {
            e.printStackTrace();
        }
       
        return result;
    }
   
}

5.鏇存柊mapper configuration鏂囦歡錛屾坊鍔犲涓嬪嚑鏉★紝娉ㄦ剰plugins鍦ㄦ暣涓猚onfiguration鏂囦歡涓殑欏哄簭

<plugins>
<plugin interceptor="functionPoint.db.DiclectStatementHandlerInterceptor"/>
<plugin interceptor="functionPoint.db.DiclectResultSetHandlerInterceptor"/>
</plugins>

6.浣跨敤鏂規硶鍚宮ybatis閫昏緫鍒嗛〉錛屾嫤鎴櫒浼氳嚜鍔ㄦ嫤鎴墽琛孲QL鐨勫湴鏂癸紝鍔犱笂鍒嗛〉浠g爜錛?/strong>

getSqlSession().selectList(mapId, queryKey,new RowBounds(pageId, pageSize));


==============================================================
鎸夌収涓婇潰鐨勫仛浜?浣嗛亱琛屾檪鍗繪媼鍑虹己灝?IN OUT鍙冩暩涔嬮鐨勯尟瑾?
寰屼締鎻涗簡Dialect欏炴枃浠跺氨OK浜?OracleDialect鍏у鍙冭冭嚜:
http://rapid-framework.googlecode.com/svn/trunk/rapid-framework/src/rapid_framework_common/cn/org/rapid_framework/jdbc/dialect/




Ke 2011-08-03 17:15 鍙戣〃璇勮
]]>
鐢⊿pring鐨凧dbcTemplate瀹炵幇鍒嗛〉鍔熻兘http://m.tkk7.com/keweibo/articles/194354.htmlKeKeSun, 20 Apr 2008 11:32:00 GMThttp://m.tkk7.com/keweibo/articles/194354.htmlhttp://m.tkk7.com/keweibo/comments/194354.htmlhttp://m.tkk7.com/keweibo/articles/194354.html#Feedback0http://m.tkk7.com/keweibo/comments/commentRss/194354.htmlhttp://m.tkk7.com/keweibo/services/trackbacks/194354.htmlOracle鏁版嵁搴擄紝浣跨敤浼垪ROWNUM鏉ュ疄鐜板垎欏點傚垎欏典唬鐮佸涓嬶細
銆銆
銆銆package com.deity.ranking.util;
        import java.util.List;
銆銆import org.springframework.jdbc.core.JdbcTemplate;
銆銆import org.springframework.jdbc.core.support.JdbcDaoSupport;
銆銆/** * 鍒嗛〉鍑芥暟 *銆
        * @author allenpan */
public class Pagination extends JdbcDaoSupport{
銆銆public static final int NUMBERS_PER_PAGE = 10;
銆銆//涓欏墊樉紺虹殑璁板綍鏁?br /> 銆銆private int numPerPage;
銆銆//璁板綍鎬繪暟
銆銆private int totalRows;
銆銆//鎬婚〉鏁?br /> 銆銆private int totalPages;
銆銆//褰撳墠欏電爜
銆銆private int currentPage;
銆銆//璧峰琛屾暟
銆銆private int startIndex;
銆銆//緇撴潫琛屾暟
銆銆private int lastIndex;
銆銆//緇撴灉闆嗗瓨鏀綥ist
銆銆private List resultList;
銆銆//JdbcTemplate jTemplate
銆銆private JdbcTemplate jTemplate;
銆銆/**
銆銆* 姣忛〉鏄劇ず10鏉¤褰曠殑鏋勯犲嚱鏁?浣跨敤璇ュ嚱鏁板繀欏誨厛緇橮agination璁劇疆currentPage錛宩Template鍒濆?br /> 銆銆* @param sql oracle璇彞
銆銆*/
銆銆public Pagination(String sql){
銆銆if(jTemplate == null){
銆銆throw new IllegalArgumentException("com.deity.ranking.util.Pagination.jTemplate is null,please initial it first. ");
銆銆}else if(sql.equals("")){
銆銆throw new IllegalArgumentException("com.deity.ranking.util.Pagination.sql is empty,please initial it first. ");
銆銆}
銆銆new Pagination(sql,currentPage,NUMBERS_PER_PAGE,jTemplate);
銆銆}
銆銆/**鍒嗛〉鏋勯犲嚱鏁?br /> 銆銆* @param sql 鏍規嵁浼犲叆鐨剆ql璇彞寰楀埌涓浜涘熀鏈垎欏典俊鎭?br /> 銆銆* @param currentPage 褰撳墠欏?br /> 銆銆* @param numPerPage 姣忛〉璁板綍鏁?br /> 銆銆* @param jTemplate JdbcTemplate瀹炰緥
銆銆*/
銆銆public Pagination(String sql,int currentPage,int numPerPage,JdbcTemplate jTemplate){
銆銆if(jTemplate == null){
銆銆throw new IllegalArgumentException("com.deity.ranking.util.Pagination.jTemplate is null,please initial it first. ");
銆銆}else if(sql == null || sql.equals("")){
銆銆throw new IllegalArgumentException("com.deity.ranking.util.Pagination.sql is empty,please initial it first. ");
銆銆}
銆銆//璁劇疆姣忛〉鏄劇ず璁板綍鏁?br /> 銆銆setNumPerPage(numPerPage);
銆銆//璁劇疆瑕佹樉紺虹殑欏墊暟
銆銆setCurrentPage(currentPage);
銆銆//璁$畻鎬昏褰曟暟
銆銆StringBuffer totalSQL = new StringBuffer(" SELECT count(*) FROM ( ");
銆銆totalSQL.append(sql);
銆銆totalSQL.append(" ) totalTable ");
銆銆//緇橨dbcTemplate璧嬪?br /> 銆銆setJdbcTemplate(jTemplate);
銆銆//鎬昏褰曟暟
銆銆setTotalRows(getJdbcTemplate().queryForInt(totalSQL.toString()));
銆銆//璁$畻鎬婚〉鏁?br /> 銆銆setTotalPages();
銆銆//璁$畻璧峰琛屾暟
銆銆setStartIndex();
銆銆//璁$畻緇撴潫琛屾暟
銆銆setLastIndex();
銆銆System.out.println("lastIndex="+lastIndex);//////////////////
銆銆//鏋勯爋racle鏁版嵁搴撶殑鍒嗛〉璇彞
銆銆StringBuffer paginationSQL = new StringBuffer(" SELECT * FROM ( ");
銆銆paginationSQL.append(" SELECT temp.* ,ROWNUM num FROM ( ");
銆銆paginationSQL.append(sql);
銆銆paginationSQL.append("銆) temp where ROWNUM <= " + lastIndex);
銆銆paginationSQL.append(" ) WHERE銆num > " + startIndex);
銆銆//瑁呭叆緇撴灉闆?br /> 銆銆setResultList(getJdbcTemplate().queryForList(paginationSQL.toString()));
銆銆}
銆銆/**
銆銆* @param args
銆銆*/
銆銆public static void main(String[] args) {
銆銆// TODO Auto-generated method stub銆銆銆銆}
銆銆public int getCurrentPage() {
銆銆return currentPage;
銆銆}
銆銆public void setCurrentPage(int currentPage) {
銆銆this.currentPage = currentPage;
銆銆}
銆銆public int getNumPerPage() {
銆銆return numPerPage;
銆銆}
銆銆public void setNumPerPage(int numPerPage) {
銆銆this.numPerPage = numPerPage;
銆銆}
銆銆public List getResultList() {
銆銆return resultList;銆銆銆銆}
銆銆public void setResultList(List resultList) {
銆銆this.resultList = resultList;
銆銆}
銆銆public int getTotalPages() {
銆銆return totalPages;
銆銆}
銆銆//璁$畻鎬婚〉鏁?br /> 銆銆public void setTotalPages() {
銆銆if(totalRows % numPerPage == 0){
銆銆this.totalPages = totalRows / numPerPage;
銆銆}else{
銆銆this.totalPages銆= (totalRows / numPerPage) + 1;
銆銆}
銆銆}
銆銆public int getTotalRows() {
銆銆return totalRows;
銆銆}
銆銆public void setTotalRows(int totalRows) {
銆銆this.totalRows = totalRows;
銆銆}
銆銆public int getStartIndex() {
銆銆return startIndex;
銆銆}
銆銆public void setStartIndex() {
銆銆this.startIndex = (currentPage - 1) * numPerPage;
銆銆}
銆銆public int getLastIndex() {
銆銆return lastIndex;
銆銆}
銆銆public JdbcTemplate getJTemplate() {
銆銆return jTemplate;
銆銆}
銆銆public void setJTemplate(JdbcTemplate template) {
銆銆jTemplate = template;
銆銆}
銆銆//璁$畻緇撴潫鏃跺欑殑绱㈠紩
銆銆public void setLastIndex() {
銆銆System.out.println("totalRows="+totalRows);///////////
銆銆System.out.println("numPerPage="+numPerPage);///////////
銆銆if( totalRows < numPerPage){
銆銆this.lastIndex = totalRows;
銆銆}else if((totalRows % numPerPage == 0) || (totalRows % numPerPage != 0 && currentPage < totalPages)){
銆銆this.lastIndex = currentPage * numPerPage;
銆銆}else if(totalRows % numPerPage != 0 && currentPage == totalPages){//鏈鍚庝竴欏?br /> 銆銆this.lastIndex = totalRows ;
銆銆}
銆銆}}鍦ㄦ垜鐨勪笟鍔¢昏緫浠g爜涓細
銆銆/**
銆銆* find season ranking list from DC
銆銆* @param areaId 閫夋墜鍖哄煙id
銆銆* @param rankDate 璧涘
銆銆* @param category 綾誨埆
銆銆* @param characterName 瑙掕壊鍚?br /> 銆銆* @return List
銆銆*/
銆銆public List findSeasonRankingList(Long areaId, int rankYear,int rankMonth,
銆銆Long categoryId,String characterName) {
銆銆//SQL璇彞
銆銆StringBuffer sql = new StringBuffer(" SELECT C.USERID userid,D.POSNAME posname,C.GAMEID gameid,C.AMOUNT amount,C.RANK rank FROM ");
銆銆//琛ㄣ銆銆銆銆銆銆銆銆銆銆銆sql.append(" (SELECT B.USERID USERID,");
銆銆sql.append(" B.POSID POSID,");
銆銆sql.append(" A.DISTRICT_CODE DISTRICTCODE,");
銆銆sql.append(" A.GAMEID GAMEID,");
銆銆sql.append(" AMOUNT AMOUNT,");
銆銆sql.append(" RANK RANK ");
銆銆sql.append(" FROM TB_FS_RANK A ");
銆銆sql.append(" LEFT JOIN TB_CHARACTER_INFO B ");
銆銆sql.append(" ON A.DISTRICT_CODE = B.DISTRICT_CODE ");
銆銆sql.append(" AND A.GAMEID = B.GAMEID ");
銆銆//闄勫姞鏉′歡
銆銆if(areaId != null && areaId.intValue() != 0){
銆銆sql.append(" and A.DISTRICT_CODE = " + areaId.intValue());
銆銆}
銆銆if( rankYear > 1970 && rankMonth > 0){
銆銆//hql.append(" and sas.id.dt >= to_date('" + rankYear + "-" + rankMonth + "-01 00:00:00'," + "YYYY-MM-DD HH24:MI:SS");
銆銆//hql.append(" and sas.id.dt <= to_date('" + rankYear + "-" + rankMonth + "-" + TimeTool.findMaxDateInMonth(rankYear,rankMonth) + " 23:59:59'," + "YYYY-MM-DD HH24:MI:SS");
銆銆sql.append(" and A.DT = fn_time_convert(to_date('" + rankYear + "-" + rankMonth + "'," + "'YYYY-MM')) ");
銆銆}
銆銆if(categoryId != null && categoryId.intValue() != 0){
銆銆sql.append(" and A.CID = " + categoryId.intValue());
銆銆}
銆銆if(characterName != null && !characterName.trim().equals("")){
銆銆sql.append(" and A.GAMEID = '" + characterName.trim()+"' ");
銆銆}
銆銆sql.append(" ORDER BY RANK ASC) C ");
銆銆sql.append(" LEFT JOIN TB_FS_POSITION D ");
銆銆sql.append(" ON C.POSID = D.POSID ");
銆銆sql.append(" ORDER BY C.RANK ");
銆銆System.out.println("hql="+sql.toString());////////////////
銆銆//浣跨敤鑷繁鐨勫垎欏電▼搴忔帶鍒剁粨鏋滈泦
銆銆Pagination pageInfo = new Pagination(sql.toString(),1,10,getJdbcTemplate());
銆銆return pageInfo.getResultList();
銆銆//return getJdbcTemplate().queryForList(sql.toString());
銆銆}
鏂囩珷渚嗘簮錛歨ttp://java.chinaitlab.com/Spring/38091.html

Ke 2008-04-20 19:32 鍙戣〃璇勮
]]>
浣跨敤JSTL鏍囩綆鍖栧垎欏墊樉紺?/title><link>http://m.tkk7.com/keweibo/articles/158303.html</link><dc:creator>Ke</dc:creator><author>Ke</author><pubDate>Mon, 05 Nov 2007 09:14:00 GMT</pubDate><guid>http://m.tkk7.com/keweibo/articles/158303.html</guid><wfw:comment>http://m.tkk7.com/keweibo/comments/158303.html</wfw:comment><comments>http://m.tkk7.com/keweibo/articles/158303.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/keweibo/comments/commentRss/158303.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/keweibo/services/trackbacks/158303.html</trackback:ping><description><![CDATA[    鍙湁娉ㄥ唽鐢ㄦ埛鐧誨綍鍚庢墠鑳介槄璇昏鏂囥?a href='http://m.tkk7.com/keweibo/articles/158303.html'>闃呰鍏ㄦ枃</a><img src ="http://m.tkk7.com/keweibo/aggbug/158303.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/keweibo/" target="_blank">Ke</a> 2007-11-05 17:14 <a href="http://m.tkk7.com/keweibo/articles/158303.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>涓涓垎欏靛疄鐜頒緥瀛?/title><link>http://m.tkk7.com/keweibo/articles/156515.html</link><dc:creator>Ke</dc:creator><author>Ke</author><pubDate>Sun, 28 Oct 2007 11:05:00 GMT</pubDate><guid>http://m.tkk7.com/keweibo/articles/156515.html</guid><wfw:comment>http://m.tkk7.com/keweibo/comments/156515.html</wfw:comment><comments>http://m.tkk7.com/keweibo/articles/156515.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/keweibo/comments/commentRss/156515.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/keweibo/services/trackbacks/156515.html</trackback:ping><description><![CDATA[    鍙湁娉ㄥ唽鐢ㄦ埛鐧誨綍鍚庢墠鑳介槄璇昏鏂囥?a href='http://m.tkk7.com/keweibo/articles/156515.html'>闃呰鍏ㄦ枃</a><img src ="http://m.tkk7.com/keweibo/aggbug/156515.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/keweibo/" target="_blank">Ke</a> 2007-10-28 19:05 <a href="http://m.tkk7.com/keweibo/articles/156515.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>搴旂敤Hibernate3鐨凞etachedCriteria瀹炵幇鍒嗛〉鏌ヨ http://m.tkk7.com/keweibo/articles/154776.htmlKeKeSun, 21 Oct 2007 13:51:00 GMThttp://m.tkk7.com/keweibo/articles/154776.htmlhttp://m.tkk7.com/keweibo/comments/154776.htmlhttp://m.tkk7.com/keweibo/articles/154776.html#Feedback0http://m.tkk7.com/keweibo/comments/commentRss/154776.htmlhttp://m.tkk7.com/keweibo/services/trackbacks/154776.htmlHibernate3鎻愪緵浜咲etachedCriteria錛屼嬌寰楁垜浠彲浠ュ湪Web灞傛瀯閫燿etachedCriteria錛岀劧鍚庤皟鐢ㄤ笟鍔″眰Bean錛岃繘琛屽姩鎬佹潯浠舵煡璇紝鏍規嵁榪欎竴鍔熻兘錛屾垜璁捐浜嗛氱敤鐨勬娊璞ean鍩虹被鍜屽垎欏電被鏀寔錛屼唬鐮佹潵鑷簬Quake Wang鐨刯avaeye-core鍖呯殑鐩稿簲綾伙紝鐒跺悗鍙堝仛浜嗗緢澶氫慨鏀廣?/p>

鍒嗛〉鏀寔綾伙細

java 浠g爜
  1. package com.javaeye.common.util;   
  2.   
  3. import java.util.List;   
  4.   
  5. public class PaginationSupport {   
  6.   
  7.     public final static int PAGESIZE = 30;   
  8.   
  9.     private int pageSize = PAGESIZE;   
  10.   
  11.     private List items;   
  12.   
  13.     private int totalCount;   
  14.   
  15.     private int[] indexes = new int[0];   
  16.   
  17.     private int startIndex = 0;   
  18.   
  19.     public PaginationSupport(List items, int totalCount) {   
  20.         setPageSize(PAGESIZE);   
  21.                 setTotalCount(totalCount);   
  22.         setItems(items);           
  23.         setStartIndex(0);   
  24.     }   
  25.   
  26.     public PaginationSupport(List items, int totalCount, int startIndex) {   
  27.                 setPageSize(PAGESIZE);   
  28.         setTotalCount(totalCount);   
  29.         setItems(items);           
  30.         setStartIndex(startIndex);   
  31.     }   
  32.   
  33.     public PaginationSupport(List items, int totalCount, int pageSize, int startIndex) {   
  34.                 setPageSize(pageSize);   
  35.         setTotalCount(totalCount);   
  36.         setItems(items);   
  37.         setStartIndex(startIndex);   
  38.     }   
  39.   
  40.     public List getItems() {   
  41.         return items;   
  42.     }   
  43.   
  44.     public void setItems(List items) {   
  45.         this.items = items;   
  46.     }   
  47.   
  48.     public int getPageSize() {   
  49.         return pageSize;   
  50.     }   
  51.   
  52.     public void setPageSize(int pageSize) {   
  53.         this.pageSize = pageSize;   
  54.     }   
  55.   
  56.     public int getTotalCount() {   
  57.         return totalCount;   
  58.     }   
  59.   
  60.     public void setTotalCount(int totalCount) {   
  61.         if (totalCount > 0) {   
  62.             this.totalCount = totalCount;   
  63.             int count = totalCount / pageSize;   
  64.             if (totalCount % pageSize > 0)   
  65.                 count++;   
  66.             indexes = new int[count];   
  67.             for (int i = 0; i < count; i++) {   
  68.                 indexes[i] = pageSize * i;   
  69.             }   
  70.         } else {   
  71.             this.totalCount = 0;   
  72.         }   
  73.     }   
  74.   
  75.     public int[] getIndexes() {   
  76.         return indexes;   
  77.     }   
  78.   
  79.     public void setIndexes(int[] indexes) {   
  80.         this.indexes = indexes;   
  81.     }   
  82.   
  83.     public int getStartIndex() {   
  84.         return startIndex;   
  85.     }   
  86.   
  87.     public void setStartIndex(int startIndex) {   
  88.         if (totalCount <= 0)   
  89.             this.startIndex = 0;   
  90.         else if (startIndex >= totalCount)   
  91.             this.startIndex = indexes[indexes.length - 1];   
  92.         else if (startIndex < 0)   
  93.             this.startIndex = 0;   
  94.         else {   
  95.             this.startIndex = indexes[startIndex / pageSize];   
  96.         }   
  97.     }   
  98.   
  99.     public int getNextIndex() {   
  100.         int nextIndex = getStartIndex() + pageSize;   
  101.         if (nextIndex >= totalCount)   
  102.             return getStartIndex();   
  103.         else  
  104.             return nextIndex;   
  105.     }   
  106.   
  107.     public int getPreviousIndex() {   
  108.         int previousIndex = getStartIndex() - pageSize;   
  109.         if (previousIndex < 0)   
  110.             return 0;   
  111.         else  
  112.             return previousIndex;   
  113.     }   
  114.   
  115. }  

 

鎶借薄涓氬姟綾?

java 浠g爜
  1. /**  
  2.  * Created on 2005-7-12  
  3.  */  
  4. package com.javaeye.common.business;   
  5.   
  6. import java.io.Serializable;   
  7. import java.util.List;   
  8.   
  9. import org.hibernate.Criteria;   
  10. import org.hibernate.HibernateException;   
  11. import org.hibernate.Session;   
  12. import org.hibernate.criterion.DetachedCriteria;   
  13. import org.hibernate.criterion.Projections;   
  14. import org.springframework.orm.hibernate3.HibernateCallback;   
  15. import org.springframework.orm.hibernate3.support.HibernateDaoSupport;   
  16.   
  17. import com.javaeye.common.util.PaginationSupport;   
  18.   
  19. public abstract class AbstractManager extends HibernateDaoSupport {   
  20.   
  21.     private boolean cacheQueries = false;   
  22.   
  23.     private String queryCacheRegion;   
  24.   
  25.     public void setCacheQueries(boolean cacheQueries) {   
  26.         this.cacheQueries = cacheQueries;   
  27.     }   
  28.   
  29.     public void setQueryCacheRegion(String queryCacheRegion) {   
  30.         this.queryCacheRegion = queryCacheRegion;   
  31.     }   
  32.   
  33.     public void save(final Object entity) {   
  34.         getHibernateTemplate().save(entity);   
  35.     }   
  36.   
  37.     public void persist(final Object entity) {   
  38.         getHibernateTemplate().save(entity);   
  39.     }   
  40.   
  41.     public void update(final Object entity) {   
  42.         getHibernateTemplate().update(entity);   
  43.     }   
  44.   
  45.     public void delete(final Object entity) {   
  46.         getHibernateTemplate().delete(entity);   
  47.     }   
  48.   
  49.     public Object load(final Class entity, final Serializable id) {   
  50.         return getHibernateTemplate().load(entity, id);   
  51.     }   
  52.   
  53.     public Object get(final Class entity, final Serializable id) {   
  54.         return getHibernateTemplate().get(entity, id);   
  55.     }   
  56.   
  57.     public List findAll(final Class entity) {   
  58.         return getHibernateTemplate().find("from " + entity.getName());   
  59.     }   
  60.   
  61.     public List findByNamedQuery(final String namedQuery) {   
  62.         return getHibernateTemplate().findByNamedQuery(namedQuery);   
  63.     }   
  64.   
  65.     public List findByNamedQuery(final String query, final Object parameter) {   
  66.         return getHibernateTemplate().findByNamedQuery(query, parameter);   
  67.     }   
  68.   
  69.     public List findByNamedQuery(final String query, final Object[] parameters) {   
  70.         return getHibernateTemplate().findByNamedQuery(query, parameters);   
  71.     }   
  72.   
  73.     public List find(final String query) {   
  74.         return getHibernateTemplate().find(query);   
  75.     }   
  76.   
  77.     public List find(final String query, final Object parameter) {   
  78.         return getHibernateTemplate().find(query, parameter);   
  79.     }   
  80.   
  81.     public PaginationSupport findPageByCriteria(final DetachedCriteria detachedCriteria) {   
  82.         return findPageByCriteria(detachedCriteria, PaginationSupport.PAGESIZE, 0);   
  83.     }   
  84.   
  85.     public PaginationSupport findPageByCriteria(final DetachedCriteria detachedCriteria, final int startIndex) {   
  86.         return findPageByCriteria(detachedCriteria, PaginationSupport.PAGESIZE, startIndex);   
  87.     }   
  88.   
  89.     public PaginationSupport findPageByCriteria(final DetachedCriteria detachedCriteria, final int pageSize,   
  90.             final int startIndex) {   
  91.         return (PaginationSupport) getHibernateTemplate().execute(new HibernateCallback() {   
  92.             public Object doInHibernate(Session session) throws HibernateException {   
  93.                 Criteria criteria = detachedCriteria.getExecutableCriteria(session);   
  94.                 int totalCount = ((Integer) criteria.setProjection(Projections.rowCount()).uniqueResult()).intValue();   
  95.                 criteria.setProjection(null);   
  96.                 List items = criteria.setFirstResult(startIndex).setMaxResults(pageSize).list();   
  97.                 PaginationSupport ps = new PaginationSupport(items, totalCount, pageSize, startIndex);   
  98.                 return ps;   
  99.             }   
  100.         }, true);   
  101.     }   
  102.   
  103.     public List findAllByCriteria(final DetachedCriteria detachedCriteria) {   
  104.         return (List) getHibernateTemplate().execute(new HibernateCallback() {   
  105.             public Object doInHibernate(Session session) throws HibernateException {   
  106.                 Criteria criteria = detachedCriteria.getExecutableCriteria(session);   
  107.                 return criteria.list();   
  108.             }   
  109.         }, true);   
  110.     }   
  111.   
  112.     public int getCountByCriteria(final DetachedCriteria detachedCriteria) {   
  113.         Integer count = (Integer) getHibernateTemplate().execute(new HibernateCallback() {   
  114.             public Object doInHibernate(Session session) throws HibernateException {   
  115.                 Criteria criteria = detachedCriteria.getExecutableCriteria(session);   
  116.                 return criteria.setProjection(Projections.rowCount()).uniqueResult();   
  117.             }   
  118.         }, true);   
  119.         return count.intValue();   
  120.     }   
  121. }   

 

鐢ㄦ埛鍦╳eb灞傛瀯閫犳煡璇㈡潯浠禿etachedCriteria錛屽拰鍙夌殑startIndex錛岃皟鐢ㄤ笟鍔ean鐨勭浉搴攆indByCriteria鏂規硶錛岃繑鍥炰竴涓狿aginationSupport鐨勫疄渚媝s銆?/p>

ps.getItems()寰楀埌宸插垎欏靛ソ鐨勭粨鏋滈泦
ps.getIndexes()寰楀埌鍒嗛〉绱㈠紩鐨勬暟緇?
ps.getTotalCount()寰楀埌鎬葷粨鏋滄暟
ps.getStartIndex()褰撳墠鍒嗛〉绱㈠紩
ps.getNextIndex()涓嬩竴欏電儲寮?
ps.getPreviousIndex()涓婁竴欏電儲寮?br />
鏂囩珷鍑哄:http://www.javaeye.com/topic/14657



Ke 2007-10-21 21:51 鍙戣〃璇勮
]]>
鍒嗛〉鏄劇ずhttp://m.tkk7.com/keweibo/articles/142446.htmlKeKeMon, 03 Sep 2007 13:49:00 GMThttp://m.tkk7.com/keweibo/articles/142446.htmlhttp://m.tkk7.com/keweibo/comments/142446.htmlhttp://m.tkk7.com/keweibo/articles/142446.html#Feedback0http://m.tkk7.com/keweibo/comments/commentRss/142446.htmlhttp://m.tkk7.com/keweibo/services/trackbacks/142446.htmlpackage org.util;

//鍒嗛〉鏄劇ず
public class Pager {

 private int currentPage;     //褰撳墠欏?/span>
 private int pageSize = 5;    //姣忛〉鏄劇ず鐨勮褰曟暟
 private int  totalSize;    //鎬昏褰曟暟
 private int totalPage;    //鎬婚〉鏁?br />  

 private boolean hasFirst;    //鏄惁鏈夐欏?/span>
 private boolean hasPrevious;    // 鏄惁鏈変笂涓欏?/span>
 private boolean hasNext;    // 鏄惁鏈変笅涓欏?/span>
 private boolean hasLast;    // 鏄惁鏈夊熬欏?br />
/**鏋勯犲嚱鏁板繀欏諱紶鍏ヤ袱涓弬鏁板綋鍓嶉〉鍜屾昏褰曟暟
鏍規嵁褰撳墠欏靛彲浠ュ垽鏂槸鍚︽湁涓婁竴欏典笅涓欏電瓑絳?
鏍規嵁鎬昏褰曟暟鍙互綆楀嚭鎬婚〉鏁?/

 public Pager(int currentPage,int totalSize){
  
  this.currentPage = currentPage;
  this.totalSize = totalSize;
 }

 
 public int getCurrentPage() {
  return currentPage;
 }
 public void setCurrentPage(int currentPage) {
  this.currentPage = currentPage;
 }
 public boolean isHasFirst() {
  
  if(currentPage == 1)
   return false;
  return true;
 }
 public void setHasFirst(boolean hasFirst) {
  this.hasFirst = hasFirst;
 }
 public boolean isHasLast() {
  
  if(currentPage == getTotalPage())
   return false;
  return true;
 }
 public void setHasLast(boolean hasLast) {
  this.hasLast = hasLast;
 }
 public boolean isHasNext() {
  
  if(isHasLast())
   return true;
  return false;
 }
 public void setHasNext(boolean hasNext) {
  this.hasNext = hasNext;
 }
 public boolean isHasPrevious() {
  
  if(isHasFirst())
   return true;
  return false;
 }
 public void setHasPrevious(boolean hasPrevious) {
  this.hasPrevious = hasPrevious;
 }
 public int getPageSize() {
  return pageSize;
 }
 public void setPageSize(int pageSize) {
  this.pageSize = pageSize;
 }
 public int getTotalPage() {
  //璁$畻鍑烘婚〉鏁?/span>
  totalPage = totalSize / pageSize;
  if(totalSize % pageSize != 0)
   totalPage++;
  return totalPage;
 }
 public void setTotalPage(int totalPage) {
  this.totalPage = totalPage;
 }
 public int getTotalSize() {
  return totalSize;
 }
 public void setTotalSize(int totalSize) {
  this.totalSize = totalSize;
 }
}



Ke 2007-09-03 21:49 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 中文无码日韩欧免费视频| 国产成人+综合亚洲+天堂| 无码国产精品一区二区免费16| 亚洲伊人成无码综合网 | 国产亚洲老熟女视频| 一级特黄a免费大片| 亚洲最大av无码网址| 两个人www免费高清视频| 亚洲精品国产成人片| 日本在线看片免费| 91亚洲国产在人线播放午夜| 天天影视色香欲综合免费| 亚洲AV成人噜噜无码网站| 四虎永久在线精品免费网址| 亚洲国产成人久久精品软件 | 亚洲字幕AV一区二区三区四区| 成年人在线免费看视频| 亚洲AV无码国产剧情| 亚洲AV无码乱码在线观看牲色| 一级毛片大全免费播放| 亚洲av永久无码精品秋霞电影影院| 日韩精品免费在线视频| 亚洲1234区乱码| 免费成人在线观看| 在线观看免费播放av片| 亚洲国产精品免费在线观看| 丁香花在线观看免费观看| 免费精品视频在线| 亚洲精品国产成人专区| 91在线视频免费播放| 成人在线免费视频| 亚洲视频在线观看不卡| 国产免费变态视频网址网站| 成人网站免费大全日韩国产| 亚洲男人的天堂在线| 亚洲男人av香蕉爽爽爽爽| 57pao国产成视频免费播放| 美女黄频a美女大全免费皮| 亚洲人成电影福利在线播放| 日美韩电影免费看| 一级毛片免费毛片一级毛片免费|