其他分享
首页 > 其他分享> > MyBatis多条件查询赋值问题

MyBatis多条件查询赋值问题

作者:互联网

MyBatis多条件查询赋值一般有三种方式,这里是比较常用的。

  1. 散装参数,即三个参数不封装,直接传入,需要用到我们的@Param注解,其实@Param注解相当于给那些原来定义的名称换一下,换成我们自己的,可读性更强一些。
  2. 对象集合,传入一个List对象,list对象是我经常使用的,因为比较简单,可以用对象list,转json也比较方便。
  3. map集合,传入一个map对象,Map对象我用的很少,看视频这个是New了一个HashMap,用put方法传入键值对也很方便,结合自己的情况使用。

 

1.散装参数

   List <Brand> selectByCondition(@Param("status") int status ,@Param("companyName") String companyName , @Param("brandName") String brandName);

 

List<Brand> brands = brandMapper.selectByCondition(status, companyName, brandName);

 

2.对象集合

   List <Brand> selectByCondition(Brand brand);

 

List<Brand> brands = brandMapper.selectByCondition(brand);

3.map集合

List <Brand> selectByCondition(Map map);

 

Map map =new HashMap();
        map.put("status",status);
        map.put("companyName",companyName);
        map.put("brandName",brandName);

List<Brand> brands = brandMapper.selectByCondition(map);

 

标签:status,map,companyName,selectByCondition,List,Param,查询,MyBatis,赋值
来源: https://www.cnblogs.com/wjingbo/p/16416992.html