Mybatis的Example常用函数和Mapper常用接口

1.Example常用函数
        mybatis的逆向工程中会生成实例以及实例对应的example,example用于添加条件,相当于where后面的部分。
        Example    example    =new    Example(实体类.class);
        example.createCriteria().添加条件
        常用函数如下:
        (1)example.setDistinct(false):去除重复,boolean类型,true表示选择不重复的记录。
        (2)example.setOrderByClause(“字段名  ASC ”):添加升序排列条件,DESC为降序。
        (3)example.createCriteria().andEqualTo("xxx字段",value):添加xxx字段等于value的条件。
        (4)example.createCriteria().andNotEqualTo("xxx字段",value):添加xxx字段不等于value的条件。
        (5)example.createCriteria().andCreaterThan("xxx字段",value):添加xxx字段大于value的条件。
        (6)example.createCriteria().andLessThan("xxx字段",value):添加xxx字段名小于value的条件。
        (7)example.createCriteria().andLessThanOrEqualTo("xxx字段",value):添加字段名小于等于value的条件。
        (8)example.createCriteria().andIn(List<?>):添加字段值在List<?>中的条件。
        (9)example.createCriteria().andNotIn(List<?>):添加字段值不在List<?>中的条件。
        (10)example.createCriteria().andLike("xxx字段","%"+value+"%"):添加xxx字段值为value的模糊查询。
        (11)example.createCriteria().andNotLike("xxx字段","%"+value+"%"):添加xxx字段值不为value的模糊查询。
        (12)example.createCriteria().andBetween("value1,value2):添加xxx字段值在value1和value2之间的条件。
        (13)example.createCriteria().andNotBetween("value1,value2):添加xxx字段值不在value1和value2之间的条件。
        (14)example.createCriteria().andIsNull("xxx字段",value):添加xxx字段值为null的条件。
        (15)example.createCriteria().andIsNotNull("xxx字段",value):添加xxx字段值不为null的条件。
2.Mapper常用接口
        (1)int  countByExample(example):按条件计数。
        (2)int  updateByExample(实体类,example):按条件更新。
        (3)int  updateByExampleSelective(实体类,example):按条件更新部位null的字段。
        (4)int  updateByPrimaryKey(实体类):按主键更新。
        (5)int  countByPrimaryKeySelective(实体类):按主键更新不为null的字段。
        (6)int  deleteByPrimaryKey(id):按主键删除。
        (7)int  deleteByExample(example):按条件删除。
        (8)String/Integer  insert(实体类):插入数据(返回值为id)。
        (9)返回值类型  selectByPrimaryKey(id):按主键查询。
        (10)返回值类型  selectByExample(example):按条件查询。
        (11)int  selectByExampleWithBLOGS(example):按条件查询(包括BLOB)字段。只有当数据表中的字段类型有为二进制时才会产生。

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值