要使用example类,先要在项目中导入mybatis.mapper的jar包。

Mapper接口中包含了单表的增删改查以及分页功能。

给出实例:

CountryMappermapper = sqlSession.getMapper(Country.class);

//Country.class是实体类

//查询操作

List<Country>cList = mapper.select(new Country());

现在使用Example查询

Example example =new Example(Country.class);

example.createCriteria().andEqualTo(“id”,100);

//这里给出查询为id=100

cList = mapper.selectByExample(example);

example.setOrderByClause(“字段名ASC”); 以某字段升序排序

example.setDistinct(false)//去除重复,boolean型,true为选择不重复的记录

selectByExample()返回的是一个集合

mybatis中mapper的实例函数:
int countByExample(UserExample example) thorws SQLException:按条件计数。
int deleteByPrimaryKey(Integer id) thorws SQLException:按主键删除。
int deleteByExample(UserExample example) thorws SQLException:按条件删除。
String/Integer insert(User record) thorws SQLException:插入(返回值为id值)
User selectByPrimaryKey(Integer id) thorws SQLException:按主键查询。
List<?>selectByExample(UserExample example) thorws SQLException:按条件查询
List<?>selectByExampleWithBLOGs(UserExample example) thorws SQLException:按

条件查询(包括BLOB字段)。只有当数据表中的字段类型有为二进制的才会产生。
int updateByPrimaryKey(User record) thorws SQLException:按主键更新
int updateByPrimaryKeySelective(User record) thorws SQLException:按主键更新值不为null的字段

int updateByExample(User record, UserExample example) thorws SQLException: 按条件更新

int updateByExampleSelective(User record, UserExample example)thorws

SQLException:按条件更新值不为null的字段

mybatis中mapper的实例函数详解:
 selectByPrimaryKey()

Country country = ##Mapper.selectByPrimaryKey(100);

相当于select * from user where id = 100

还有一些方法不在这里赘述,可以参考mybatis中的example

转自 http://blog.csdn.net/qq_36743013/article/details/71144508

Mybatis中example类的使用的更多相关文章

  1. Mybatis中实体类属性与数据库列表间映射方法介绍

               这篇文章主要介绍了Mybatis中实体类属性与数据列表间映射方法介绍,一共四种方法方法,供大家参考.         Mybatis不像Hibernate中那么自动化,通过@Co ...

  2. MyBatis中主要类的生命周期和应用范围

    转自:http://ccchhhlll1988-163-com.iteye.com/blog/1420026 MyBatis中常用的类就要数SqlSessionFactoryBuilder.SqlSe ...

  3. Mybatis 中实体类的编写

    一个实体类对应一个数据表 一个属性对应一个字段 默认情况下类名和属性名都采用 “下划线转驼峰” 的命名方式.但具体采用什么样的命名方式并不重要(方式一致即可),在后面使用这些对象的时候,可以通过 re ...

  4. mybatis中实体类跟数据库属性不一致解决方案

    1.在Mapper.xml映射配置文件中给sql语句起别名 select id as uid,username as name from user 2.mybatis中可以单独的配置查询结果的列名和实 ...

  5. Mybatis中实体类属性和数据列之间映射的四种办法

    http://blog.csdn.net/lmy86263/article/details/53150091 Mybatis不像hibernate中那么自动化,通过@Column注解或者直接使用实体类 ...

  6. Mybatis中实体类中的字段跟对应表的字段不一致时解决办法

    解决字段名与实体类属性名不相同的冲突 实体类字段: public class Order { private int id; private String orderNo; private float ...

  7. mybatis中的mapper接口文件以及selectByExample类的实例函数详解

    记录分为两个部分,第一部分主要关注selectByExample类的实例函数的实现:第二部分讨论Mybatis框架下基本的实例函数. (一)selectByExample类的实例函数的实现 当你启动项 ...

  8. 讨论!MyBatis中利用package自动扫描包中的类,默认别名不只是首字母小写!

    问题描述:这个问题我是在看书的时候碰到的.书上写着通过package标签扫描包中的类,将其第一个字母变为小写作为其别名.我在网上查了一些博主也是这么写的 但是!我发现,无论大小写,只要是类名就好,而且 ...

  9. Mybatis中多个参数的问题&&动态SQL&&查询结果与类的对应

    ### 1. 抽象方法中多个参数的问题 在使用MyBatis时,接口中的抽象方法只允许有1个参数,如果有多个参数,例如: Integer updatePassword( Integer id, Str ...

随机推荐

  1. C++对C的扩展、增强

    C++对C的扩展 1. 双冒号::作用域运算符 代码中对同一个变量多次声明,在代码块中使用时,局部变量会将全局变量隐藏.若在代码块使用变量前添加::,表示为全局变量. ::表示作用域运算符,如常见的s ...

  2. CentOS7.4 安装JDK 步骤

    1.先在官网下载jdk1.8的压缩文件 2.用putty将压缩文件拷到home目录下 3.新建一个/home/jdk1.8目录 :  mkdir  /home/jdk1.8 4.将压缩文件解压到hom ...

  3. PAT甲级——A1023 Have Fun with Numbers

    Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, wit ...

  4. JSP页面格式化timestamp时间

    timestamp类型返回并直接取值显示会带小尾巴 偶然发现 <fmt:formatDate value="${order.createTime}" type="b ...

  5. CentOS 6.5 Apache、MySQL、PHP环境配置(LAMP)

    yum -y install httpd mysql-server php #安装apache.mysql和PHP yum -y install php-mysql php-gd php-mbstri ...

  6. python-web-下载所有xkcd漫画

    下载所有xkcd漫画 # downloads every single xkcd comic import requests,os,bs4 url='http://xkcd.com' # start ...

  7. HBase的一些关于CRUD方法

    配置内容 static{configuration = HBaseConfiguration.create();  //创建配置文件(也就是load工程包目录下的配置文件hbase-site.xml) ...

  8. 创建Hadoop用户

  9. No module named 'sklearn.impute',更新scikit-learn

    -------我错了,本篇作废,我把自己的包更新坏了,大家不要往下看了------------------最终我是把anaconda卸载重装的--------- 使用scikit-learn模块进行缺 ...

  10. Laravel Carbon获取 某个时间后N个月的时间

    $time = "2020-11-20 00:00:00"; $res = (new Carbon)->setTimeFromTimeString($time)->ad ...