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()+"%\""; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
2018-03-22 Spring框架中的Quartz定时任务使用笔记(通过@Scheduled注解的方式实现)
2018-03-22 postman使用