温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-07-21 10:04:36 来源:网络 阅读:1037 作者:Bighead0829 栏目:关系型数据库

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)字段。只有当数据表中的字段类型有为二进制时才会产生。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI