mybatis逆向工程进行不同条件查询的应用处理

21 篇文章 0 订阅

在沒有critia条件下的应用

<select id="selectDataByDifferentTime"resultMap="BaseResultMap1" parameterType="com.adtec.db.yizooo.entity.ReceiptExample">

    select

    <if test="distinct">

      distinct

    </if>

    <include refid="Base_Column_List"/>

    from plat2_receipt

    where

    addressis not null

    and

    part_type= "01"

    <if test="receiptTime=0">

    and

    <![CDATA[ DATE_SUB(CURDATE(), INTERVAL 7 DAY) <=date(receipt_time) ]]>

    </if>

    <if test="receiptTime=1">

    and

    DATE_SUB(CURDATE(),INTERVAL 30 DAY) &lt;= date(receipt_time)

    </if>

    <if test="receiptType=1">

    and

    logistic_codeis not null

    </if>

    <if test="receiptType=0">

    and

    logistic_codeis null

    </if>

    <if test="orderByClause !=null" >

      order by ${orderByClause}

    </if>

    limit #{offset}, #{rows}

  </select>

以上是mapper.xml中的文件

Example文件中

privateStringreceiptType;

 

    publicStringgetReceiptType() {

                  returnreceiptType;

         }

 

         publicvoidsetReceiptType(StringreceiptType) {

                  this.receiptType = receiptType;

         }

        

         privateStringrecriptTime;

         publicStringgetRecriptTime() {

                  returnrecriptTime;

         }

mapper.xml中sql语句用到的<if test=”字段”>必须和exmaple中定义的字段一致即实体类中的字段

在业务层中

ReceiptExampleexample=newReceiptExample();

                          example.setOffset(offset);

                          example.setRows(rows);

                          example.setOrderByClause("receipt_time desc");

                         

//                        Criteria cri=example.createCriteria();

//                        cri.andAddressIsNotNull();

//                        cri.andPartTypeEqualTo(Constants.DIFFERENT_DRAW);

                          if(StringUtils.hasText(po.getReceiptType())){

                                   if(po.getReceiptType().equals("0"))

                                   {

                                            example.setReceiptType("0");

                                   }elseif(po.getReceiptType().equals("1"))

                                   {

                                            example.setReceiptType("1");

                                   }

                          }

                         

                          if (po.getReceiptTime()!=null || !"".equals(po.getReceiptTime())) {

                                   if (po.getReceiptTime().equals("0")) {

                                            example.setRecriptTime("0");

                                   }elseif(po.getReceiptTime().equals("1")) {

                                            example.setRecriptTime("1");

                                   }

                          }

                          List<ReceiptPo> receiptList=receiptMapper.selectDataByDifferentTime(example);

                          for(ReceiptPoreceipt : receiptList)//遍历receiptList

                          {

                                   //

                                   DrawPodrawPo=drawMapper.selectByMyDrawLucy(receipt.getPeriodId());

                                   intbetCnt = drawBetService.sumDrawBetCnt(receipt.getPeriodId(), receipt.getCid());

                                   receipt.setCmdtName(drawPo.getCmdtName());

                                   receipt.setBetCount(betCnt);

                          }

在业务层中 

if(StringUtils.hasText(po.getReceiptType())){

                                   if(po.getReceiptType().equals("0"))

                                   {

                                            example.setReceiptType("0");

                                   }elseif(po.getReceiptType().equals("1"))

                                   {

                                            example.setReceiptType("1");

                                   }

                          }

通过上述代码决定mapper.xml中的文件sql语句执行条件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

乐观的Terry

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值