MybatisPlus的BaseMapper和Wrapper使用 您所在的位置:网站首页 querywrapper使用方法 MybatisPlus的BaseMapper和Wrapper使用

MybatisPlus的BaseMapper和Wrapper使用

2022-05-28 02:22| 来源: 网络整理| 查看: 265

一、简介  在MybatisPlus中,BaseMapper中定义了一些常用的CRUD方法,当我们自定义的Mapper接口继承BaseMapper后即可拥有了这些方法。二、BaseMapper中的CRUD方法 通用 CRUD 封装BaseMapper接口,为 Mybatis-Plus 启动时自动解析实体表关系映射转换为 Mybatis 内部对象注入容器 泛型 T 为任意实体对象 参数 Serializable 为任意类型主键 Mybatis-Plus 不推荐使用复合主键约定每一张表都有自己的唯一 id 主键 对象 Wrapper 为 条件构造器 /* * Copyright (c) 2011-2020, hubin ([email protected]). *

* Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at *

* http://www.apache.org/licenses/LICENSE-2.0 *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.baomidou.mybatisplus.core.mapper; import java.io.Serializable; import java.util.Collection; import java.util.List; import java.util.Map; import org.apache.ibatis.annotations.Param; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Constants; /** *

* Mapper 继承该接口后,无需编写 mapper.xml 文件,即可获得CRUD功能 *

*

* 这个 Mapper 支持 id 泛型 *

* * @author hubin * @since 2016-01-23 */ public interface BaseMapper { /** *

* 插入一条记录 *

* * @param entity 实体对象 */ int insert(T entity); /** *

* 根据 ID 删除 *

* * @param id 主键ID */ int deleteById(Serializable id); /** *

* 根据 columnMap 条件,删除记录 *

* * @param columnMap 表字段 map 对象 */ int deleteByMap(@Param(Constants.COLUMN_MAP) Map columnMap); /** *

* 根据 entity 条件,删除记录 *

* * @param queryWrapper 实体对象封装操作类(可以为 null) */ int delete(@Param(Constants.WRAPPER) Wrapper queryWrapper); /** *

* 删除(根据ID 批量删除) *

* * @param idList 主键ID列表(不能为 null 以及 empty) */ int deleteBatchIds(@Param(Constants.COLLECTION) Collection


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有