官网配置参数说明地址:https://mp.baomidou.com/config/#logicdeletevalue
本地配置:yml
mybatis-plus:
mapper-locations: classpath*:mybatis/*.xml
type-aliases-package: com.genergy.cloud.model.entity
global-config:
db-config:
field-strategy: not_empty
id-type: auto
db-type: mysql
banner: false
super-mapper-class: com.genergy.cloud.mapper.BaseMapper
package com.genergy.cloud.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param; import java.io.Serializable;
import java.util.Collection;
import java.util.List; /**
* BaseMapper 基于 MP 删减
*
* @author Caratacus
* @see com.baomidou.mybatisplus.core.mapper.BaseMapper
*/
public interface BaseMapper<T> { /**
* <p>
* 插入一条记录
* </p>
*
* @param entity 实体对象
*/
int insert(T entity); /**
* <p>
* 批量插入数据
* </p>
*
* @param entityList 实体对象集合
*/
int insertBatchSomeColumn(@Param("list") Collection<T> entityList); /**
* <p>
* 根据 ID 删除
* </p>
*
* @param id 主键ID
*/
int deleteById(Serializable id); /**
* <p>
* 根据 entity 条件,删除记录
* </p>
*
* @param queryWrapper 实体对象封装操作类(可以为 null)
*/
int delete(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper); /**
* <p>
* 根据 ID 修改
* </p>
*
* @param entity 实体对象
*/
int updateById(@Param(Constants.ENTITY) T entity); /**
* <p>
* 根据 ID 修改
* </p>
*
* @param entity 实体对象
*/
int updateAllColumnById(@Param(Constants.ENTITY) T entity); /**
* <p>
* 根据 whereEntity 条件,更新记录
* </p>
*
* @param entity 实体对象 (set 条件值,不能为 null)
* @param updateWrapper 实体对象封装操作类(可以为 null,里面的 entity 用于生成 where 语句)
*/
int update(@Param(Constants.ENTITY) T entity, @Param(Constants.WRAPPER) Wrapper<T> updateWrapper); /**
* <p>
* 根据 ID 查询
* </p>
*
* @param id 主键ID
*/
T selectById(Serializable id); /**
* <p>
* 根据 Wrapper 条件,查询总记录数
* </p>
*
* @param queryWrapper 实体对象
*/
Integer selectCount(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper); /**
* <p>
* 根据 entity 条件,查询全部记录
* </p>
*
* @param queryWrapper 实体对象封装操作类(可以为 null)
*/
List<T> selectList(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper); /**
* <p>
* 根据 Wrapper 条件,查询全部记录
* 注意: 只返回第一个字段的值
* </p>
*
* @param queryWrapper 实体对象封装操作类(可以为 null)
*/
List<Object> selectObjs(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper); /**
* <p>
* 根据 entity 条件,查询全部记录(并翻页)
* </p>
*
* @param page 分页查询条件(可以为 RowBounds.DEFAULT)
* @param queryWrapper 实体对象封装操作类(可以为 null)
*/
IPage<T> selectPage(IPage<T> page, @Param(Constants.WRAPPER) Wrapper<T> queryWrapper); }
package com.genergy.cloud.mybatisplus;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.AbstractSqlInjector;
import com.baomidou.mybatisplus.core.injector.methods.*;
import com.baomidou.mybatisplus.extension.injector.methods.additional.InsertBatchSomeColumn; import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream; /**
* <p>
* MybatisPlusSql注入器
* </p>
*
* @author Caratacus
*/
public class MybatisPlusSqlInjector extends AbstractSqlInjector { @Override
public List<AbstractMethod> getMethodList() {
return Stream.of(
new Insert(),
new InsertBatchSomeColumn(t -> true),
new Delete(),
new DeleteById(),
new Update(),
new UpdateById(),
new UpdateAllColumnById(),
new SelectById(),
new SelectCount(),
new SelectObjs(),
new SelectList(),
new SelectPage()
).collect(Collectors.toList());
} }
package com.genergy.cloud.mybatisplus.config;

import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.genergy.cloud.mybatisplus.CommonMetaObjectHandler;
import com.genergy.cloud.mybatisplus.MybatisPlusSqlInjector;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; /**
* MybatisPlus 配置
*
* @author Caratacus
*/
@Configuration
public class MybatisPlusAutoConfiguration { /**
* 分页
*
* @return
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
} /**
* 乐观锁
*
* @return
*/
@Bean
public OptimisticLockerInterceptor optimisticLockerInterceptor() {
return new OptimisticLockerInterceptor();
} /**
* 自动填充
*
* @return
*/
@Bean
public CommonMetaObjectHandler commonMetaObjectHandler() {
return new CommonMetaObjectHandler();
} /**
* 自定义注入语句
*
* @return
*/
@Bean
public MybatisPlusSqlInjector mybatisPlusSqlInjector() {
return new MybatisPlusSqlInjector();
}
}
注意:
super-mapper-class: com.genergy.cloud.mapper.BaseMapper 官网好像没有找到super-mapper-class配置说明,如果不配置该项会导致明明继承了basemapper 但是里面的方法一直报找不到。原因好像在controller时 调用aop,通过sql注入器寻到方法。
 
 
 


 
 
 

mybatis-plus 3.X 配置的更多相关文章

  1. Mybatis的二级缓存配置

    一个项目中肯定会存在很多共用的查询数据,对于这一部分的数据,没必要每一个用户访问时都去查询数据库,因此配置二级缓存将是非常必要的.  Mybatis的二级缓存配置相当容易,要开启二级缓存,只需要在你的 ...

  2. 【转】MyBatis学习总结(三)——优化MyBatis配置文件中的配置

    [转]MyBatis学习总结(三)——优化MyBatis配置文件中的配置 一.连接数据库的配置单独放在一个properties文件中 之前,我们是直接将数据库的连接配置信息写在了MyBatis的con ...

  3. Mybatis非mapper代理配置

    转: Mybatis非mapper代理配置 2017年04月26日 20:13:48 待长的小蘑菇 阅读数:870   版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog. ...

  4. MyBatis 源码分析——配置信息

    MyBatis框架的启动前期需要加载相关的XML配置信息.从官网上我们可以了解到他具有十几个节点.其中笔者认为比较重要的节点是settings节点.properties节点.environments节 ...

  5. Mybatis系列(二):优化MyBatis配置文件中的配置和解决字段名与实体类属性名不相同的冲突

    原文链接:http://www.cnblogs.com/xdp-gacl/p/4264301.html     http://www.cnblogs.com/xdp-gacl/p/4264425.ht ...

  6. mybatis generator配置,Mybatis自动生成文件配置,Mybatis自动生成实体Bean配置

    mybatis generator配置,Mybatis自动生成文件配置,Mybatis自动生成实体Bean配置 ============================== 蕃薯耀 2018年3月14 ...

  7. MyBatis—mapper.xml映射配置

    SQL文件映射(mapper文件),几个顶级元素的配置: mapper元素:根节点只有一个属性namespace(命名空间)作用: 1:用于区分不同的mapper,全局唯一. 2:绑定DAO接口,即面 ...

  8. Java Web开发之Spring | SpringMvc | Mybatis | Hibernate整合、配置、使用

    1.Spring与Mybatis整合 web.xml: <?xml version="1.0" encoding="UTF-8"?> <web ...

  9. mybatis mapper xml文件配置resultmap时,id行和result行有什么区别?

    mybatis mapper xml文件配置resultmap时,id行和result行有什么区别? <resultMap id = "CashInvoiceMap" typ ...

  10. mybatis与spring整合配置

    mybatis与spring整合配置: 第一种方式:(此处配置扫描的包路径.注解.每个mapper类上面需要加@Repository才能纳入spring的bean管理器中) <!-- 自动扫描m ...

随机推荐

  1. c#实现文件写入数据表/以二进制流保存到数据库,并实现下载

    上传: 1.上传文件先保存到服务器   File.SaveAs(path) 2.sql(文件和sql在一个服务器上)进行保存操作: insert into File(filename,filebody ...

  2. Jquery中小数取整

    var uu=Math.floor(5.36) 向下取整 结果为5 var uu=Math.floor(5.88) 结果为5 Math.ceil(5.33) 向上取整,结果为6 Math.round( ...

  3. CSS 背景图像 background属性简写

    background属性简写 background属性可以像margin padding属性一样,有简写方法,它的简写顺序是: background-color background-image ba ...

  4. Win10系统下,本地连接远程桌面(Win2016)图解

    1.Win+R在运行框中输入mstsc,回车 2.在出现的远程登陆窗口中,计算机中输入远程桌面IP 3.点击显示选项按钮,在远程桌面窗口中,点击常规(默认),输入登陆的用户名: XXXXXX 4.点击 ...

  5. 求1!+2!+3!+......+n!的和 -----C++-----

    #include<iostream> using namespace std; int function(int x) { ; ;i<=x;i++) sum=sum*i; retur ...

  6. ORACLE升级11g以上之前版本的wm_concat()函数失效

    先执行: create or replace type string_sum_obj as object ( --聚合函数的实质就是一个对象 sum_string ), static function ...

  7. mybatis中foreach使用

    mybatis中的<foreach collection="list" item="item" index="index" open= ...

  8. java利用反射动态加载方法

    @参考文章 根据特定字符串加载相应的方法,有人用if else,有人用switch.参数少了或情况少了还好,很多方法真要命,不要紧,java反射拯救你 import java.lang.reflect ...

  9. 避免切换横竖屏Fragment的重复加载导致UI混乱

    当我们切换横竖屏时 Activity的生命周期就会重走一遍,自然 其中的Fragment的生命周期也就重新走了一遍,实践证明 当熄屏 再开屏时 Fragment的生命周期也会重走一遍 解决方案: an ...

  10. ios 根据 schemes 打开 app

    公司出需求,要让 h5链接直接打开用户的 app,如果没有安装 app 直接跳转到 appStore 这就需要给 app 配置 schemes 即可 1.在Info.plist中 LSApplicat ...