Loading

mybatis动态sql id in sids

在使用mybatis动态sql查询时,如果传递的参数为List,比如List<Long>,或者一个对象,对象的一个属性为List.使用如下方式

1.aaaMapper.java

中参数的写法:这里可以不加@param,但是最好加上

  1 @Param("isAsc")Boolean isAsc,String gxlx, List<String> flsids 

2.aaaMapper.xml

这里我想用sid in sids ,需要这样写

1 <if test="flsids != null and flsids.size>0 ">
2 and wj.flsid in
3     <foreach item="item" index="index" collection="flsids" open="(" separator=","     close=")">
4     #{item}
5     </foreach>
6 </if>

3.controller.java

这里传参必须加上@RequestParam(value = "sids"),否则会报错:No primary or default constructor found for interface java.util.List

 1 @RequestParam(value = "sids") List<Long>sids, 

如果sids不是必须的,应该加上required = false,否则会报错:Required List parameter 'sids' is not present 

 1 @RequestParam(value = "sids",required = false)List<Long>sids 

posted @ 2021-01-25 20:55  风萧萧5  阅读(354)  评论(0编辑  收藏  举报