mybatis generator:example的举例说明

generator生成对象和xml的时候,会生成一个example对象,看一下example在查询、修改当中的使用,本文在这里进行记载,方便以后使用:

一、常用的方法举例:

所需依赖:

<!-- 映射关系:自动生成实体 -->
<dependency>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-core</artifactId>
    <version>1.3.7</version>
</dependency>

*搭建过程略,后期会专门出一个搭建过程的文章。*

1、简单查询

DemoExample example = new DemoExample();
example.createCriteria().andIdEqualTo(1L);
List<Demo> demos = demoMapper.selectByExample(example);
System.out.println(demos);

2、模糊查询

DemoExample example = new DemoExample();
//注意条件
example.createCriteria().andUserNameLike("%" + "l" + "%");
List<Demo> demos = demoMapper.selectByExample(example);
System.out.println(demos);

3、分页

DemoExample example = new DemoExample();
RowBounds rowBounds = new RowBounds(0, 10);
List<Demo> demos = demoMapper.selectByExampleWithRowbounds(example,rowBounds);
System.out.println(demos)

4、复杂的其它查询:

DemoExample example = new DemoExample();
//年龄在0~40之间
DemoExample.Criteria criteria = example.createCriteria();
criteria.andUserNameLike("%" + "l" + "%").andAgeBetween(0L,40L);
//createAt不在【0~10】
DemoExample.Criteria criteria2 = example.createCriteria();
criteria2.andCreateAtNotBetween(0L,10L);
example.or(criteria2);
List<Demo> demos = demoMapper.selectByExample(example);
System.out.println(demos);

二、方法列表

1、mapper文件:

2、example文件:

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值