zoukankan      html  css  js  c++  java
  • springboot 注解版案例

    1、dao层

     /**
         * 查询列表
         * @param dataRequest
         * @return
         */
        @SelectProvider(type = CuiShouSqlProvider.class, method = "cuiShouList")
        @Options(useGeneratedKeys = true)
        public List<Map<String,String>> selectCuiShouOrderList(@Param("CuiKuanRequest") CuiKuanRequest dataRequest);
        //public List<Map<String,String>> selectCuiShouOrderList(@Param("CuiKuanRequest") CuiKuanRequest dataRequest);
    
        /**
         * 查询条数
         * @param dataRequest
         * @return
         */
        @SelectProvider(type = CuiShouSqlProvider.class, method = "cuiShouListCountNum")
        @Options(useGeneratedKeys = true)
        public int CuiShouOrderListCountNum(@Param("CuiKuanRequest") CuiKuanRequest dataRequest);

    2、sql拼接类

    /**
     * @author wuhongpu
     * 催收动态sql拼接
     */
    
    public class  CuiShouSqlProvider {
    
        private Logger logger = LoggerFactory.getLogger(CuiShouSqlProvider.class);
        /**
         * 查询list列表方法
         * @param dataRequest
         * @return
         */
        public String cuiShouList(CuiKuanRequest dataRequest){
            StringBuilder selectSql = new StringBuilder();
            selectSql.append("select * from (SELECT w.`status` AS clearStatus,w.thirdType,w.createTime,o.uuid,o.`status` AS orderStatus,o.lendingTime,o.refundTime,o.amountApply,u.realName,u.mobileNumber,u.idCardNo,datediff(now(),DATE_FORMAT(o.refundTime, '%Y-%m-%d')) AS DAY ");
            selectSql.append("FROM wk_cuishou w LEFT JOIN orderorder o ON w.orderNo = o.uuid LEFT JOIN useruser u ON o.userUuid = u.uuid)t where 1=1 ");
    
            StringBuilder conditionSql = this.generateCondition(dataRequest);
    
            if (dataRequest.getPageNo() != null && dataRequest.getPageSize() != null) {
                Integer num = (dataRequest.getPageNo() - 1) * dataRequest.getPageSize();
                conditionSql.append(" limit ").append(num.toString()).append(",")
                        .append(dataRequest.getPageSize().toString());
            }
    
            selectSql.append(conditionSql);
            logger.info(selectSql.toString());
            return selectSql.toString();
        }
    
    
        /**
         * 统计条数方法
         * @param dataRequest
         * @return
         */
        public String cuiShouListCountNum(CuiKuanRequest dataRequest) {
            StringBuilder selectSql = new StringBuilder();
            selectSql.append("select count(1) from (SELECT w.`status` AS clearStatus,w.thirdType,w.createTime,o.uuid,o.`status` AS orderStatus,o.lendingTime,o.refundTime,o.amountApply,u.realName,u.mobileNumber,u.idCardNo,datediff(now(),DATE_FORMAT(o.refundTime, '%Y-%m-%d')) AS DAY ");
            selectSql.append("FROM wk_cuishou w LEFT JOIN orderorder o ON w.orderNo = o.uuid LEFT JOIN useruser u ON o.userUuid = u.uuid)t where 1=1 ");
    
            StringBuilder conditionSql = this.generateCondition(dataRequest);
            selectSql.append(conditionSql);
            this.logger.info(selectSql.toString());
            return selectSql.toString();
        }
    
        /**
         * 条数分页方法
         * @param dataRequest
         * @return
         */
        public String cuiShouListListByPage(CuiKuanRequest dataRequest) {
            StringBuilder selectSql = new StringBuilder();
            selectSql.append("select * from (SELECT w.`status` AS clearStatus,w.thirdType,w.createTime,o.uuid,o.`status` AS orderStatus,o.lendingTime,o.refundTime,o.amountApply,u.realName,u.mobileNumber,u.idCardNo,datediff(now(),DATE_FORMAT(o.refundTime, '%Y-%m-%d')) AS DAY ");
            selectSql.append("FROM wk_cuishou w LEFT JOIN orderorder o ON w.orderNo = o.uuid LEFT JOIN useruser u ON o.userUuid = u.uuid)t where 1=1 ");
    
    
            StringBuilder conditionSql = this.generateCondition(dataRequest);
    
            Integer num = (dataRequest.getPageNo() - 1) * dataRequest.getPageSize();
            conditionSql.append("limit ").append(num.toString()).append(",")
                    .append(dataRequest.getPageSize().toString());
    
            selectSql.append(conditionSql);
            logger.info(selectSql.toString());
            return selectSql.toString();
        }
    
        /**
         * 参数动态拼接方法
         * @param dataRequest
         * @return
         */
        private StringBuilder generateCondition(CuiKuanRequest dataRequest) {
            StringBuilder conditionSql = new StringBuilder();
    
            if(dataRequest.getOrderStatus()!=null){
                conditionSql.append("t.orderStatus=#{CuiKuanRequest.orderStatus} and ");
            }
            if(dataRequest.getClearStatus()!=null){
                conditionSql.append("t.clearStatus=#{CuiKuanRequest.clearStatus} and ");
            }
            if(dataRequest.getDay()!=null  ){
                if(dataRequest.getDay()>=7){
                    conditionSql.append("t.day>#{CuiKuanRequest.day} ");
                }else{
                    conditionSql.append("t.day=#{CuiKuanRequest.day} ");
                }
    
            }
           conditionSql.append("order by t.day desc");
    
            return conditionSql;
        }
    }
  • 相关阅读:
    解决spring配置文件没有提示的问题
    SpringMVC 中HttpMessageConverter简介和Http请求415 Unsupported Media Type的问题
    在编辑Spring的配置文件时的自动提示
    Java注释@interface的用法【转】
    spring-autowire机制
    一些汇编指令
    Windows底层开发前期学习准备工作
    log4j.properties中的这句话“log4j.logger.org.hibernate.SQL=DEBUG ”该怎么写在log4j.xml里面呢?
    log4j 配置文件 (XML/.properties)
    [VC]C++ operator 两种用法
  • 原文地址:https://www.cnblogs.com/a8457013/p/9087074.html
Copyright © 2011-2022 走看看