The following are 10 query methods in the general interface BaseMapper
/**
* Query by ID
*
* @param id primary key ID
*/
T selectById(Serializable id);
/**
* Query (batch query based on ID)
*
* @param idList primary key ID list (cannot be null and empty)
*/
List<T> selectBatchIds(Collection<? extends Serializable> idList);
/**
* Query (according to columnMap condition)
*
* @param columnMap table field map object
*/
List<T> selectByMap( Map<String, Object> columnMap);
/**
* According to the entity condition, query a record
*
* @param queryWrapper Entity object encapsulation operation class (can be null)
*/
T selectOne(Wrapper<T> queryWrapper);
/**
* According to Wrapper conditions, query the total number of records
*
* @param queryWrapper Entity object encapsulation operation class (can be null)
*/
Integer selectCount(Wrapper<T> queryWrapper);
/**
* According to entity conditions, query all records
*
* @param queryWrapper Entity object wrapper operation class (can be null)
*/
List<T> selectList( Wrapper<T> queryWrapper);
/**
* According to Wrapper conditions, query all records
*
* @param queryWrapper Entity object encapsulation operation class (can be null)
*/
List<Map<String, Object>> selectMaps(Wrapper<T> queryWrapper);
/**
* According to Wrapper conditions, query all records
* <p>Note: Only return the value of the first field</p>
*
* @param queryWrapper Entity object encapsulation operation class (can be null)
*/
List<Object> selectObjs(Wrapper<T> queryWrapper);
/**
* According to the entity condition, query all records (and turn pages)
*
* @param page paging query condition (can be RowBounds.DEFAULT)
* @param queryWrapper entity object encapsulation operation class (can be null)
*/
<E extends IPage<T>> E selectPage(E page, Wrapper<T> queryWrapper);
/**
* According to Wrapper conditions, query all records (and turn pages)
*
* @param page pagination query conditions
* @param queryWrapper Entity object encapsulation operation class
*/
<E extends IPage<Map<String, Object>>> E selectMapsPage (E page, Wrapper<T> queryWrapper);
First
selectById
Usage: query the specified id object information
the second
selectBatchIds
Usage: Query the specified id object information in batches
The third
selectByMap
Usage: Query entity information that satisfies the conditions, and the conditions are encapsulated into the map collection
the fourth
selectCount
Usage: Query the total number of entity information records that satisfy the condition, and enter a condition constructor object
the fifth
selectList
Usage: Query entity information records that meet the conditions, and return List<T>
sixth
selectMaps
Usage: Query entity information records that meet the conditions, and return List<Map<String, Object>>
In this method, note that the keys of the map in the returned List cannot be said to be all entity class attributes, nor can they be said to be all data table field names
Here you have to pay attention to the actual development time
When is it appropriate to use selectList and selectMap????
If the result of the query can be encapsulated into an object, then use selectList. If the query is not suitable for encapsulating the object or you don’t want to write the encapsulated object, use selectMap. For example, to query the number of people in each department select dept_id,count(*) count from t_employee group by dept_id is suitable for selectMap
Of course selectList is also possible
for example
seventh
selectPage
Usage: Paging query entity information records that meet the conditions
To do paging with plus, you need to configure it first
Rationalized configuration is mainly to check the data passed in when paging. For example, if you pass a -1 page, it is obviously illogical or there are 5 pages in total. You query page 10. After rationalized configuration, it is not logical to return the last page of data uniformly
@Configuration
public class MybatisPlusConfig{
//分页
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
paginationInnerInterceptor.setOverflow(true); //合理化
interceptor.addInnerInterceptor(paginationInnerInterceptor);
return interceptor;
}
}
select * from employee where...limit (currentPage-1)*pageSize,pageSize
eighth
selectMapsPage
Usage: Same as selectPage, the difference is that the generic type of the paging data set returned by selectMapsPage is Map, and selectPage is an entity object.
Ninth
selectOne
Usage: Query entity objects that meet the conditions. If multiple pieces of data are returned, an exception will be thrown.
Type 10
selectObjs
Usage: Query entity objects that meet the conditions, and return the set of specified columns. If no specified column is specified, the first column will be returned by default
Returns the first column without specifying a column