Mybatis中example类的使用
要使用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类的使用的更多相关文章
- Mybatis中实体类属性与数据库列表间映射方法介绍
这篇文章主要介绍了Mybatis中实体类属性与数据列表间映射方法介绍,一共四种方法方法,供大家参考. Mybatis不像Hibernate中那么自动化,通过@Co ...
- MyBatis中主要类的生命周期和应用范围
转自:http://ccchhhlll1988-163-com.iteye.com/blog/1420026 MyBatis中常用的类就要数SqlSessionFactoryBuilder.SqlSe ...
- Mybatis 中实体类的编写
一个实体类对应一个数据表 一个属性对应一个字段 默认情况下类名和属性名都采用 “下划线转驼峰” 的命名方式.但具体采用什么样的命名方式并不重要(方式一致即可),在后面使用这些对象的时候,可以通过 re ...
- mybatis中实体类跟数据库属性不一致解决方案
1.在Mapper.xml映射配置文件中给sql语句起别名 select id as uid,username as name from user 2.mybatis中可以单独的配置查询结果的列名和实 ...
- Mybatis中实体类属性和数据列之间映射的四种办法
http://blog.csdn.net/lmy86263/article/details/53150091 Mybatis不像hibernate中那么自动化,通过@Column注解或者直接使用实体类 ...
- Mybatis中实体类中的字段跟对应表的字段不一致时解决办法
解决字段名与实体类属性名不相同的冲突 实体类字段: public class Order { private int id; private String orderNo; private float ...
- mybatis中的mapper接口文件以及selectByExample类的实例函数详解
记录分为两个部分,第一部分主要关注selectByExample类的实例函数的实现:第二部分讨论Mybatis框架下基本的实例函数. (一)selectByExample类的实例函数的实现 当你启动项 ...
- 讨论!MyBatis中利用package自动扫描包中的类,默认别名不只是首字母小写!
问题描述:这个问题我是在看书的时候碰到的.书上写着通过package标签扫描包中的类,将其第一个字母变为小写作为其别名.我在网上查了一些博主也是这么写的 但是!我发现,无论大小写,只要是类名就好,而且 ...
- Mybatis中多个参数的问题&&动态SQL&&查询结果与类的对应
### 1. 抽象方法中多个参数的问题 在使用MyBatis时,接口中的抽象方法只允许有1个参数,如果有多个参数,例如: Integer updatePassword( Integer id, Str ...
随机推荐
- Ionic login简单登录页面
1.login.html <ion-view view-title="登录" hide-nav-bar="true"> <div class= ...
- light oj 1084 线性dp
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> ...
- ERROR:ORA-30076: 对析出来源无效的析出字段
DEBUG:key: sql: select count(*) as col_0_0_ from jc_user cmsuser0_ where 1=1 and cmsuser0_.register_ ...
- oracle创建新的连接(表空间?数据库?)
一.创建用户名密码 create user username identified by password --username 是用户名:password 是密码 二.给用户附权.撤权 gra ...
- bootstrap-table的简要使用
bttable功能强大!同时支持申明方式和编程方式来使用!是wenzhixin主导开发一款开源的表格控件! 文档比较详尽,但要求初学者已经比较熟悉js,jquey等基本内容,否则可能许多代码无法阅读! ...
- Luogu P1314 聪明的质监员(二分+前缀和)
P1314 聪明的质监员 题意 题目描述 小\(T\)是一名质量监督员,最近负责检验一批矿产的质量.这批矿产共有\(n\)个矿石,从\(1\)到\(n\)逐一编号,每个矿石都有自己的重量\(w_i\) ...
- Leetcode506.Relative Ranks相对名次
给出 N 名运动员的成绩,找出他们的相对名次并授予前三名对应的奖牌.前三名运动员将会被分别授予 "金牌","银牌" 和" 铜牌"(" ...
- 【转载】TSN简介及相关资源
原文:https://blog.csdn.net/u012692537/article/details/86188392 一.简介 1.1 什么是TSN TSN(Time Sensitive Netw ...
- HDU6200 mustedge mustedge mustedge
不用看题就知道这是和什么tarjan.缩点或桥一类有关的题. 谁让他取题目叫一个mustedge还连续写3次的(哦,似乎是因为那个比赛的题目都是这个画风) 必须的边 >必须要经过的边 > ...
- 在Vmware安装虚拟机WindowsServer 2003
一.创建并安装虚拟机 新建Windows2003server系统 按照下面操作即可 https://www.cnblogs.com/color-blue/p/8525710.html 二.安装虚拟机 ...