mybatis多参数传递且其中一个参数传多个值用in

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

1.当查询的参数只有一个时findByIds(ListLongids)1.a如果参数的类型是List,则在使用时,collection属性要必须指定为listselectid=findByIdsMapresultMap=BaseResultMapSelectincluderefid=Base_Column_List/fromjriawhereIDinforeachitem=itemindex=indexcollection=listopen=(separator=,close=)#{item}/foreach/selectfindByIds(Long[]ids)1.b如果参数的类型是Array,则在使用时,collection属性要必须指定为arrayselectid=findByIdsMapresultMap=BaseResultMapselectincluderefid=Base_Column_List/fromjriawhereIDinforeachitem=itemindex=indexcollection=arrayopen=(separator=,close=)#{item}/foreach/select2.当查询的参数有多个时,例如findByIds(Stringname,Long[]ids)这种情况需要特别注意,在传参数时,一定要改用Map方式,这样在collection属性可以指定名称下面是一个示例MapString,Objectparams=newHashMapString,Object(2);params.put(name,name);params.put(ids,ids);mapper.findByIdsMap(params);selectid=findByIdsMapresultMap=BaseResultMapselectincluderefid=Base_Column_List/fromjriawhereIDinforeachitem=itemindex=indexcollection=idsopen=(separator=,close=)#{item}/foreach/select完整的示例如下:例如有一个查询功能,Mapper接口文件定义如下方法:ListJriafindByIds(Long...ids);使用in查询的sql拼装方法如下:selectid=findbyIdsresultMap=BaseResultMapselectincluderefid=Base_Column_List/fromjriawhereIDinforeachitem=itemindex=indexcollection=arrayopen=(separator=,close=)#{item}/foreach/select例子:Mapper.xml中!--根据库存状态和设备状态查询设备--selectid=selectByStockAndEquipmentStatusparameterType=TbiEquipmentresultMap=resultMapSELECTincluderefid=Base_Column_List/FROMt_bi_equipmentwhere0=0iftest=equipmentStockStatue!=nullandequipmentStockStatue!=''andEQUIPMENT_STOCK_STATUS=#{equipmentStockStatue,jdbcType=INTEGER}/ififtest=equipmentStatue!=nullandequipmentStatue!=''andEQUIPMENT_STATUSinforeachitem=itemindex=indexcollection=equipmentStatueopen=(separator=,close=)#{item}/foreach/if/selectMapper中ListTbiEquipmentselectByStockAndEquipmentStatus(MapString,Objectparams);Service中ListTbiEquipmentselectByStockAndEquipmentStatus(intequipmentStockStatue,int[]equipmentStatue);这个中的equipmentStockStatue和equipmentStatue要和mapper.xml中的参数名保持一致,且controller中也要保持一致ServiceImpl中@OverridepublicListTbiEquipmentselectByStockAndEquipmentStatus(intequipmentStockStatue,int[]equipmentStatue){MapString,Objectparams=newHashMapString,Object();params.put(equipmentStockStatue,equipmentStockStatue);params.put(equipmentStatue,equipmentStatue);returntbiEquipmentMapper.selectByStockAndEquipmentStatus(params);}Controller中tbiEquipmentService.selectByStockAndEquipmentStatus(equipmentStockStatue,equipmentStatue)equipmentStockStatue的值要定义,equipmentStatue也要定个集合,里面也得定义值

1 / 4
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功