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

相关文章

这篇文章主要介绍“hive和mysql的区别是什么”,在日常操作中...
这篇“MySQL数据库如何改名”文章的知识点大部分人都不太理解...
这篇文章主要介绍“mysql版本查询命令是什么”的相关知识,小...
本篇内容介绍了“mysql怎么修改字段的内容”的有关知识,在实...
这篇文章主要讲解了“mysql怎么删除unique约束”,文中的讲解...
今天小编给大家分享一下mysql怎么查询不为空的字段的相关知识...