zoukankan      html  css  js  c++  java
  • 查询数据时,根据不同查询条件的情况,重载方法的一种写法(不知道怎么描述了!!!!)

    做了一小段用友的项目,看到的写法,记录一下,供参考:

        /**
         * 不带条件查询,也即查询获得所有的VO对象列表,不带翻页,默认排序
         *
         * 
    @return 查询到的VO列表
         
    */
        public List queryByCondition() {
            return queryByCondition(null);
        }

        /**
         * 通过查询条件获得所有的VO对象列表,不带翻页,默认排序
         * 
         * 
    @param queryCondition 查询条件
         * 
    @return 查询到的VO列表
         
    */
        public List queryByCondition(String queryCondition) {
            return queryByCondition(queryCondition, null);
        }

        /**
         * 通过查询条件获得所有的VO对象列表,不带翻页,带排序字符
         * 
         * 
    @param queryCondition 查询条件
         * 
    @param orderStr 排序字符
         * 
    @return 查询到的VO列表
         
    */
        public List queryByCondition(String queryCondition, String orderStr) {
            return queryByCondition(-1, -1, queryCondition, orderStr);
        }

        /**
         * 通过查询条件获得所有的VO对象列表,带翻页,默认排序
         * 
         * 
    @param no 当前页数
         * 
    @param size 每页记录数
         * 
    @param queryCondition 查询条件
         * 
    @return 查询到的VO列表
         
    */
        public List queryByCondition(int no, int size, String queryCondition) {
            return queryByCondition(no, size, queryCondition, null);
        }
        
            /**
         * 通过查询条件获得所有的VO对象列表,带翻页,带排序字符
         * 
         * 
    @param no 当前页数
         * 
    @param size 每页记录数
         * 
    @param queryCondition 查询条件
         * 
    @param orderStr 排序字符 
         * 
    @return 查询到的VO列表
         
    */
        public List queryByCondition(int no, int size, String queryCondition, String orderStr) {
            String strsql = SQL_QUERY_ALL + DEFAULT_QUERY_WHERE_ENABLE;
            if (queryCondition != null && queryCondition.length() > 0 && queryCondition.trim().length() > 0) {
                strsql += " AND " + queryCondition; //where后加上查询条件
            }
            if(orderStr == null ) {
                strsql += ORDER_BY_SYMBOL + DESC_ORDER_CODE;
            } else {
                strsql += ORDER_BY_SYMBOL + orderStr;
            }
            if(no <= 0 || size <= 0) {
                return query(strsql, new RowMapper() {
                    public Object mapRow(ResultSet rs, int i) throws SQLException {
                        ProjConfigurationListVo vo = new ProjConfigurationListVo();
                        Helper.populate(vo, rs);
                        return vo;
                    }
                });
            } else {
                return query(strsql, new RowMapper() {
                    public Object mapRow(ResultSet rs, int i) throws SQLException {
                        ProjConfigurationListVo vo = new ProjConfigurationListVo();
                        Helper.populate(vo, rs);
                        return vo;
                    }
                }, (no - 1) * size, size); 
            }
        }

     
  • 相关阅读:
    赠与今年的大学毕业生(胡适先生30年代的文章,仍不过时)
    统一管理磁盘上的开源代码
    生成sqlite导入库的做法
    提高二维矢量绘图效率之一般做法
    boost库命名规则的优点
    如何把腾讯微博挂到CSDN博客上
    fatal error C1902 Program database manager mismatch; please check your installation问题的解决
    智能指针变量做函数参数的一个值得注意的地方
    PC会消亡吗?
    软件制造问题的微软答案
  • 原文地址:https://www.cnblogs.com/allen76615519/p/2479225.html
Copyright © 2011-2022 走看看