框架功能

  • 内置提供基础CRUD方法
  • 提供根据方法名自进行单表查询(包括查询、统计、删除等)

接入方法

Spring Boot
    <dependency>
<groupId>com.github.dreamroute</groupId>
<artifactId>mybatis-pro-boot-starter</artifactId>
<version>latest version</version>
</dependency>
Spring MVC

内置方法

1. 你的Mapper接口继承com.github.dream.mybatis.pro.sdk.Mapper接口
2. 在启动类上使用@MapperScan注解指明你的Mapper接口路径
3. 此时你的接口就拥有了Mapper接口的所有通用方法,如下:
    T selectById(ID id);                       // 根据主键id查询单个对象
List<T> selectByIds(List<ID> ids); // 根据主键id集合查询多个对象
List<T> selectAll(); // 查询全部 int insert(T entity); // 新增
int insertExcludeNull(T entity); // 新增,值为null的属性不进行保存,使用数据库默认值
int insertList(List<T> entityList); // 批量新增 int updateById(T entity); // 根据主键id修改
int updateByIdExcludeNull(T entity); // 根据主键id修改,值为null的属性不进行修改 int deleteById(ID id); // 根据id删除
int deleteByIds(List<ID> ids); // 根据id列表进行删除

实体对象注解

@Data
@Table(name = "smart_user")
public class User { @Id
private Long id;
private String name;
private String password;
private Long version;
@Transient
private Integer gender;
@Column(name = "phone_no")
private String phoneNo;
}
说明:
  • @com.github.dreamroute.mybatis.pro.core.annotations.Table:name属性表示表名
  • @com.github.dreamroute.mybatis.pro.core.annotations.Id:标记的字段表示主键(默认为自增,可根据@Id的属性type属性修改主键策略
  • @com.github.dreamroute.mybatis.pro.core.annotations.Transient:表示此字段无序持久化到数据库
  • @com.github.dreamroute.mybatis.pro.core.annotations.Column:实体属性与数据列的映射关系(默认:驼峰属性自动转成下划线风格)

灵魂功能

1、Mapper接口的方法名根据特定的书写规则进行查询,用户无需编写sql语句

2、方法名以findBy、countBy、existBy、deleteBy开头,属性首字母大写,多个属性使用And或者Or连接

比如:

public interface UserMapper extends Mapper<User, Long> {

    // select * from xx where name = #{name} and password = #{password}
User findByNameAndPassword(String name, String password); // select count(*) c from xx where name = #{name}
int countByName(String name); // select * from xx where name = #{name} and password like '%#{password}%'
List<User> findByNameAndPasswordLike(String name, String password); // delete from xx where name = #{name} and version = #{version}
int deleteByNameAndVersion(String name, Long version); }

全部功能

一个方法可以有多个and或者or拼接多个条件,

如:findByNameLikeOrPasswordIsNotNullAndVersion(String name, String password, version)

效果:where name like '%#{name}%' or password is not null and version #{version}

关键字 示例 效果
and findByNameAndPassword(String name, String password) where name = #{name} and #{password}
or findByNameOrPassword(String name, String password) where name = #{name} or #{password}
count countByName(String name) select count(*) c from xx where name = #{name}
exist existByName(String name) 查询结果大于等于1,那么返回true,否则返回false
delete deleteByName(String name) delete from x where name = #{name}
Between findByAge(Integer start, Integer end ) where age between #{start} and #{end}
LT(LessThan) findByAgeLT(Integer age) where age < #{age}
LTE(LessThanEqual) findByAgeLTE(Integer age) where age <= #{age}
GT(GreaterThan) findByAgeGT(Integer age) where age > #{age}
GTE(GreaterThanEqual) findByAgeLTE(Integer age) where age >= #{age}
IsNull findByNameIsNull where name is null
IsNotNull findByNameIsNotNull where name is not null
IsBlank findByNameIsBlank where name is null or name = ''
IsNotBlank findByNameIsNotBlank where name is not null and name != ''
Like findByNameAndPasswordLike(String name, String password) where name = #{name} and password like '%#{password}%'
NotLike findByNameNotLike(String name) where name not like '%#{name}%'
StartWith findByNameStartWith(String name) where name like '#{name}%'
EndWith findByNameEndWith(String name) where name like '%#{name}'
Not findByNameNot(String name) where name <> #{name}
In findByNameIn(List<String> names) where name in ('A', 'B', 'C')
NotIn findByNameNotIn(List<String> names) where name not in ('A', 'B', 'C')
OrderBy findByNameOrderById(String name) where name = #{name} order by id
Desc findByNameOrderByIdDesc(String name) where name = #{name} order by id desc

MyBatis-Pro,新一代的MyBatis增强框架的更多相关文章

  1. Spring+Mybatis+Mysql搭建分布式数据库访问框架

    一.前言 用Java开发企业应用软件, 经常会采用Spring+MyBatis+Mysql搭建数据库框架.如果数据量很大,一个MYSQL库存储数据访问效率很低,往往会采用分库存储管理的方式.本文讲述如 ...

  2. MyBatis学习(一)、MyBatis简介与配置MyBatis+Spring+MySql

    一.MyBatis简介与配置MyBatis+Spring+MySql 1.1MyBatis简介 MyBatis 是一个可以自定义SQL.存储过程和高级映射的持久层框架.MyBatis 摒除了大部分的J ...

  3. MyBatis学习总结(七)——Mybatis缓存(转载)

      孤傲苍狼 只为成功找方法,不为失败找借口! MyBatis学习总结(七)--Mybatis缓存 一.MyBatis缓存介绍 正如大多数持久层框架一样,MyBatis 同样提供了一级缓存和二级缓存的 ...

  4. MyBatis学习 之 一、MyBatis简介与配置MyBatis+Spring+MySql

    目录(?)[-] 一MyBatis简介与配置MyBatisSpringMySql MyBatis简介 MyBatisSpringMySql简单配置 搭建Spring环境 建立MySql数据库 搭建My ...

  5. 【转】MyBatis学习总结(七)——Mybatis缓存

    [转]MyBatis学习总结(七)——Mybatis缓存 一.MyBatis缓存介绍 正如大多数持久层框架一样,MyBatis 同样提供了一级缓存和二级缓存的支持 一级缓存: 基于PerpetualC ...

  6. 【转】MyBatis学习总结(一)——MyBatis快速入门

    [转]MyBatis学习总结(一)——MyBatis快速入门 一.Mybatis介绍 MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC ...

  7. mybatis系列笔记(1)---mybatis入门

    mybatis入门   MyBatis是什么? MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了goog ...

  8. Mybatis配置信息浅析 MyBatis简介(二)

    官方文档入门篇中有明确说明 每个基于 MyBatis 的应用都是以一个 SqlSessionFactory 的实例为中心的. SqlSessionFactory 的实例可以通过 SqlSessionF ...

  9. springmvc 项目完整示例04 整合mybatis mybatis所需要的jar包 mybatis配置文件 sql语句 mybatis应用

    百度百科: MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名为MyBat ...

随机推荐

  1. T3 难题 题解

    小王在考试中遇到一道难题:方程 a1+a2+„„+an=m 的非负整数解有几个,请你帮他算 一下(这也可以算作他作弊吧). 输入格式 一行,两个以空格隔开的数 n,m,表示方程 a1+a2+„„+an ...

  2. IDEA 2020版破解

    这期教一下大家如何破解IDEA 最新版破解教程 有以前的idea建议卸载哈~安装最新版的版本 一:我们首先去idea官网下载最新版 下方是idae官网2020最新链接 https://www.jetb ...

  3. 食用Win系统自带的PowerShell登录服务器

    运行powershell输入ssh root@你的服务器ip -p你的端口 切换rm ~/.ssh/known_hosts cmd 运行 ping 你的ip -t一直ping ctrl+c停止 tra ...

  4. 【JVM之内存与垃圾回收篇】堆

    堆 堆的核心概念 堆针对一个 JVM 进程来说是唯一的,也就是一个进程只有一个 JVM,但是进程包含多个线程,他们是共享同一堆空间的. 一个 JVM 实例只存在一个堆内存,堆也是 Java 内存管理的 ...

  5. matplotlib常见图表绘制——极坐标图-雷达图、极轴图

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:斑点鱼 极坐标轴 调用subplot()创建子图时通过设置proje ...

  6. Elasticsearch源码解析:环境搭建

    在之前学习Redis的过程中,我就是一边通过文档/视频学习,一边阅读源码.我发现两种方法可以相辅相成,互相补充.阅读文档可以帮助我们快速了解某个功能,阅读源码有助于我们更深入的理解这一功能的实现及思想 ...

  7. 关于node-sass安装失败问题

    在进行Vue开发中npm run dev报错,按照提示尝试进行npm以及cnpm安装均失败 解决办法:npm uninstall node-sass卸载模块 指定淘宝镜像源安装 npm i node- ...

  8. 数据库(十二):pymysql

    进击のpython ***** 数据库--pymysql 数据库就算是学习完毕了,但是我们学习数据库的本质是什么? 是想让数据库像文件存储一样将信息存储起来供我们调用 那回归本行,我就应该是用pyth ...

  9. android获取各种系统路径的方法

    链接https://blog.csdn.net/qq_26296197/article/details/51909423 通过Environment获取的 Environment.getDataDir ...

  10. 还不懂mysql的undo log和mvcc?算我输!

    最近一直没啥时间写点东西,坚持分享真的好难,也不知道该分享点啥,正好有人要问我这些东西,所以腾出点时间,写一下这个主题.同样本篇可以给读者承诺,听不懂或者没收获算我输,哈哈! 众所周知,mysql中读 ...