I. Introduction
In MybatisPlus in, BaseMapper defines some common CRUD methods, when our custom Mapper interface inheritance BaseMapper to have these methods.
Two, BaseMapper method of CRUD
- General CRUD package BaseMapper interface to
Mybatis-Plus
automatically resolve entity table mapping relationship start to convertMybatis
internal object into the vessel - Generics
T
any solid object - Parameters
Serializable
for the primary key of any typeMybatis-Plus
is not recommended to use composite primary key conventions each table has its own uniqueid
primary key - Object
Wrapper
of the condition constructor
/* * Copyright (c) 2011-2020, hubin ([email protected]). * <p> * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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. */ packagecom.baomidou.mybatisplus.core.mapper; Import the java.io.Serializable; Import java.util.Collection; Import java.util.List; Import a 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; / ** * <P> * Mapper interface inheritance after, without writing mapper.xml file, you can get CRUD functionality * </ the p-> * <the p-> * Mapper supports this generic id * </ the p-> * * @author Hubin *@Since 2016-01-23 * / public interface BaseMapper <T> { / ** * <P> * insert a record * </ P> * * @param Entity entity object * / int INSERT (T Entity); / * * * <P> * The delete ID * </ P> * * @param ID primary key ID * / int deleteById (the Serializable ID); / ** * <P> * The columnMap condition, delete records * </ P> * * @param columnMap table field map objects * / Int deleteByMap (@Param (Constants.COLUMN_MAP) the Map <String, Object> columnMap); / ** * <P> * The conditions entity, delete records * </ P> * * @param queryWrapper packaging operations entity object class (can be null) * / int delete (@Param (Constants.WRAPPER) the Wrapper <T> queryWrapper); / ** * <P> * delete (ID The mass delete) * </ P> * * @param IDLIST primary key ID list (can not be null and empty) * / int deleteBatchIds (@Param (Constants.COLLECTION) Collection <? the extends Serializable> IDLIST); / ** * <P> * The modified ID * </ P> * * @param Entity entity object * / int updateById (@Param (Constants.ENTITY) T Entity); / ** * <P> * The whereEntity condition update records * </ P> * * @param entity entity object (set condition value is not null) * @param updateWrapper packaging operations entity object class (can be null, which is used to generate the entity where clause) * / int Update (@ param (Constants.ENTITY) T Entity, @Param (Constants.WRAPPER) the Wrapper <T> updateWrapper); / ** * <P> * The ID inquiry * </ p> * *@param ID primary key ID * / T selectById (the Serializable ID); / ** * <P> * query (query based bulk ID) * </ P> * * @param IDLIST primary key ID list (and can not be null empty) * / List <T> selectBatchIds (@Param (Constants.COLLECTION) Collection <? the extends Serializable> IDLIST); / ** * <the p-> * query (according to columnMap conditions) * </ the p-> * * @param columnMap field map Object * / List <T> selectByMap (@Param (Constants.COLUMN_MAP) the Map <String, Object>/**columnMap); * <P> * The conditions entity, select a row * </ P> * * @param queryWrapper entity object * / T between selectOne (@Param (Constants.WRAPPER) the Wrapper <T> queryWrapper); / ** * <P> * The Wrapper conditions, the total number of records query * </ P> * * @param queryWrapper entity object * / Integer SelectCount (@Param (Constants.WRAPPER) Wrapper <T> queryWrapper); / ** * <P> * The entity conditions, query all the records * </ p> * * @Param queryWrapper packaging operations entity object class (which can be null) * / List <T> selectList is (@Param (Constants.WRAPPER) Wrapper <T> queryWrapper); / ** * <P> * The Wrapper conditions, query all records * </ P> * * @param queryWrapper entity object wrapper operation class (can be null) * / List <the Map <String, Object >> selectMaps (@Param (Constants.WRAPPER) Wrapper <T> queryWrapper); / ** * <P> * The Wrapper conditions, query all records * Note: returns the value of only the first field * </ P> * * @param queryWrapper packaging operations entity object class (can be null) * / List<Object> selectObjs (@Param (Constants.WRAPPER) the Wrapper <T> queryWrapper); / ** * <P> * The entity conditions, all of the query record (and page) * </ P> * * @param Page tab query (may RowBounds.DEFAULT) * @param queryWrapper packaging operations entity object class (can be null) * / the IPage <T> SelectPage (the IPage <T> Page, @Param (Constants.WRAPPER) the Wrapper <T> queryWrapper) ; / ** * <P> * The Wrapper conditions, all of the query record (and page) * </ P> * * @Param Page tab query * @param queryWrapper packaging operations entity object class * / IPage <the Map <String, Object >> selectMapsPage (IPage <T> page, @Param (Constants.WRAPPER) Wrapper<T> queryWrapper); }
Three, MybatisPlus learning
MybatisPlus: https://mp.baomidou.com/guide/crud-interface.html#mapper-crud-%E6%8E%A5%E5%8F%A3