博主首页

mybatis循环、mybatis传map

 

 

       <build>
              <resources>
                  <resource>
                      <directory>src/main/resources</directory>
                      <includes>
                          <include>**/*.properties</include>
                          <include>*.yml</include>
                          <include>**/*.md</include>
                          <include>*</include>
                          <include>**/*.xml</include>
                      </includes>
                      <filtering>false</filtering>
                  </resource>
              </resources>

 

mapper-locations: classpath:mapper/*.xml
mapper-locations: mapper/*.xml

mybatis中使用循环、mybatis传入map案例

               <!-- 根据id修改商户提成配置-->
    <update id="editStopAll" parameterType="pd">
       update tb_member_join
        <set>
            <if test="status !=null and status !=''">
                status=#{status},
            </if>
            <if test="update_time!=null and update_time!=''">
                update_time=#{update_time},
            </if>
            <if test="createtor!=null and createtor!=''">
                createtor=#{createtor},
            </if>
        </set>
        where id  in
       <foreach item="item" collection="list" separator="," open="(" close=")" index="">  
         #{item.id}  
       </foreach>    
    </update>
        PageData pd = new PageData();//这里就是一个map
        pd.put("list", list);
        pd.put("status","0");
        pd.put("update_time", DateUtil.getTime());
        pd.put("createtor",u_id);        
        return (Integer)dao.update("franchiseeMapper.editStopAll", pd);
mybatisplus  分组查询。分组查询求和,分组查询再过滤
        query.orderByDesc("open_pr","id");
        if(user.getLevel()!=0){
            query.like("proxy_ids",user.getUserId()+",");
        }
        if(StringUtil.isNotBlank(countByTeam.getProxyName())){
            query.like("proxy_name",countByTeam.getProxyName());
        }
        query.groupBy("team_code")
        .select("proxy_name proxyName,team_name teamName,IFNULL(count(cabinet_no),0) cabinetCount,IFNULL(sum(pay_amountsum),0) payAmountsum," +
            "IFNULL(sum(days),0) days ,team_code teamCode," +
            "IFNULL(sum(totol_order),0) totolOrder," +
            "format(IFNULL(sum(totol_order),0)/IFNULL(sum(days),0)/IFNULL(count(cabinet_no),0),2) openPr," +
            "format(IFNULL(sum(pay_amountsum),0)/IFNULL(sum(days),0)/IFNULL(count(cabinet_no),0),2) singleAmount," +
            "format(IFNULL(sum(pay_amountsum),0)/IFNULL(sum(totol_order),0),2) singlePrice");
        if(StringUtil.isNotBlank(countByTeam.getSopenPr())){
            query.having("openPr>={0}",countByTeam.getSopenPr());
        }

        if(StringUtil.isNotBlank(countByTeam.getEopenPr())){
            query.having("openPr<={0}",countByTeam.getEopenPr());
        }

        if(StringUtil.isNotBlank(countByTeam.getSsingleAmount())){
            query.having("singleAmount>={0}",countByTeam.getSsingleAmount());
        }

        if(StringUtil.isNotBlank(countByTeam.getEsingleAmount())){
            query.having("singleAmount<={0}",countByTeam.getEsingleAmount());
        }

 

    
排序获取第一条
    LambdaQueryWrapper<PayInfo> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(PayInfo::getUserId,userId)
            .orderByDesc(PayInfo::getCreateDate).last("limit 1");
        PayInfo payInfo = payInfoMapper.selectOne(queryWrapper);

 

//and 和 or  一起用

LambdaQueryWrapper<UserBindWechat> lambdaQuery1 = Wrappers.lambdaQuery();
        lambdaQuery1.eq(UserBindWechat::getAppid,dto.getAppid())
            .and(wr->wr.eq(UserBindWechat::getPhone,dto.getPhone()).or().eq(UserBindWechat::getOpenId,dto.getOpenId()))
            .orderByDesc(UserBindWechat::getCreateDate)
            .last("limit 1");

 代码里自定义sql

   @SelectProvider(type= HotelServiceImpl.class,method="selectPageOrderDifferenceNumSql")
    List<HotelDO> selectPageOrderDifferenceNum(HotelPageReqVO reqVO);

    @SelectProvider(type= HotelServiceImpl.class,method="selectPageOrderDifferenceNumCountSql")
    Long selectPageOrderDifferenceNumCount(HotelPageReqVO reqVO);
    public String selectPageOrderDifferenceNumSql(HotelPageReqVO reqVO){
            String sql="SELECT t1.*, sum(t2.difference_num) differenceNum from  w_hotel t1 " +
                    "LEFT JOIN w_order_detail t2 " +
                    "on t1.id=t2.hotel_id " +
                    "where t2.damaged_num>0 ";
            if(reqVO.getName()!=null){
                sql+="and t1.`name` like \"%"+reqVO.getName()+"%\"";
            }

 

posted @ 2019-03-22 10:09  笑~笑  阅读(380)  评论(0编辑  收藏  举报