框架功能

  • 内置提供基础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. Linux 后台启动 Redis

    1. 修改 redis.conf 首先,这里有一个坑 ! 不同的 redis版本,在安装的时候,redis.conf 的路径稍微有些不同 redis.conf 可能出现的三个位置: /etc/redi ...

  2. day10:函数的实参&形参

    函数的参数 (参数:配合函数运算的值)参数:      (1)形参:形式参数,在函数的定义处      (2)实参:实际参数,在函数的调用处 形参: 普通形参(位置) , 默认形参 , 普通收集形参 ...

  3. javascript : 复杂数据结构拷贝实验

    数组深拷贝看起来很简单. array.concat()就行了. 但是,如果数组里有对象呢? 实际上,你以为你拷贝了对象,但实际上你只拷贝了对象的引用(指针)! 我们可以做个试验. // test le ...

  4. .net core 拦截socket

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net ...

  5. MySQL之高级操作

     新增数据: 基本语法: insert into 表名 [(字段列表)] values(列表值) 在数据插入的时候,假设主键对应的值已经存在,插入一定会失败 主键冲突: 当主键存在冲突的时候(Dupl ...

  6. BUUCTF-web ZJCTF,不过如此

    很明显要利用伪协议读next.php base64解码后查看源码 <?php $id = $_GET['id']; $_SESSION['id'] = $id; function complex ...

  7. 小书MybatisPlus第8篇-逻辑删除实现及API细节精讲

    本文为Mybatis Plus系列文章的第8篇,前7篇访问地址如下: 小书MybatisPlus第1篇-整合SpringBoot快速开始增删改查 小书MybatisPlus第2篇-条件构造器的应用及总 ...

  8. form表单两种提交方式的不同

      我们在使用<Form>表单的时候,最常用的提交方式就是Get和Post.我们都知道这两种方式最大的差别就是安全性,除此之外,它们还有哪些其他的区别,你知道吗?   在<Form& ...

  9. for循环运用,三角形

    用for循环打出三角形.倒三角形.金字塔.99乘法表 三角形: 打出如图三角形,分析行数与*个数的关系,用for循环 for(var i=0;i<5;++i){//i表示行数 var str=& ...

  10. LQB2013A04倒置的标签

    这个题,一开始犯了一个很幼稚的错误 贴贴代码 #include<iostream> #include<stdio.h> #include<stdlib.h> #in ...