要使用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. 洛谷 P1155 双栈排序

    题面 解题思路 这道题乍一看还以为是个模拟..怒写一发30分(noip提高组t4有模拟吗?). 其实很好hack,如 10 10 2 8 1 7 9 3 4 5 6 按模拟的思路,应该是10入第一个栈 ...

  2. [转]模块化——Common规范及Node模块实现

    Node在实现中并非完全按照CommonJS规范实现,而是对模块规范进行了一定的取舍,同时也增加了少许自身需要的特性.本文将详细介绍NodeJS的模块实现 引入 nodejs是区别于javascrip ...

  3. c++容器中map的应用

    原文链接:https://www.cnblogs.com/fnlingnzb-learner/p/5833051.html Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关 ...

  4. PAT甲级——A1022 Digital Library

    A Digital Library contains millions of books, stored according to their titles, authors, key words o ...

  5. WhaleCTF之web密码泄露

    WhaleCTF之密码泄露 前往题目 没有思路,习惯看一下源码,拉到最后,发现有惊喜 直接把index.php 换成password.txt,访问 这是要让我密码爆破吗?直接把密码保存成passwor ...

  6. 前端算法题:找出数组中第k大的数字出现多少次

    题目:给定一个一维数组,如[1,2,4,4,3,5],找出数组中第k大的数字出现多少次. 例如:第2大的数是4,出现2次,最后输出 4,2 function getNum(arr, k){ // 数组 ...

  7. Mybatis编写初始化Dao代码

    第一步:创建User实体类(POJO) package com.xu.pojo; import java.util.Date; /** * * @author 徐亮亮 * Title: User * ...

  8. php实现的支持断点续传的文件下载类

    通常来说,php支持断点续传,主要依靠HTTP协议中 header HTTP_RANGE实现. HTTP断点续传原理: Http头 Range.Content-Range()HTTP头中一般断点下载时 ...

  9. Django项目:CRM(客户关系管理系统)--24--16PerfectCRM实现King_admin日期过滤

    登陆密码设置参考 http://www.cnblogs.com/ujq3/p/8553784.html list_filter = ('date','source','consultant','con ...

  10. light7结合jquery实现开关按钮

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...