MyBatis-Plus 分页插件的使用方式
引入依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.1</version>
</dependency>
配置分页插件
@Configuration
public class MybatisConfig {
/**
* 分页插件
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
}
编写mapper
package com.fast.model.business.dao.custom;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fast.model.business.entity.form.CollectionQueryForm;
import com.fast.model.business.entity.po.FgCollection;
import com.fast.model.business.entity.po.custom.FgCollectionCust;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
@Component("fgCollectionCustMapper")
public interface FgCollectionCustMapper {
IPage<?> pageCollectionsAndLayers(IPage<FgCollection> page,@Param("queryForm") CollectionQueryForm queryForm);
}
其中CollectionQueryForm
类如下:
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ApiModel(description = "收藏查询对象")
@EqualsAndHashCode(callSuper = true)
public class CollectionQueryForm extends BaseQueryForm<FgCollection> {
@ApiModelProperty(value = "收藏类型", required = true)
private String collectionType;
@ApiModelProperty(value = "收藏名称")
private String collectionName;
@ApiModelProperty(value = "创建者", required = true)
private String createBy;
private Set<String> dataSetIds;
@ApiModelProperty(value = "删除标志",hidden=true)
private String deleteFlag;
@ApiModelProperty(value = "关联id集合")
private Set<String> associatedIdSet = new HashSet();
@ApiModelProperty(value = "关联id")
private String associatedId;
}
编写xml
<select id="pageCollectionsAndLayers" parameterType="com.fast.model.business.entity.form.CollectionQueryForm"
resultType="com.fast.model.business.entity.po.FgCollection">
SELECT
collection.collection_id,
collection.associated_id,
collection.collection_type
FROM
fg_collection AS collection
LEFT JOIN fg_layer AS layer ON layer.ID = collection.associated_id
WHERE
layer.data_set_id in
<foreach collection="queryForm.dataSetIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
AND collection.collection_type = #{queryForm.collectionType}
AND collection.create_by = #{queryForm.createBy}
AND collection.delete_flag = #{queryForm.deleteFlag}
AND layer.delete_flag = #{queryForm.deleteFlag}
<if test="queryForm.collectionName != null and queryForm.collectionName!=''">
AND layer.label LIKE #{queryForm.collectionName}
</if>
ORDER BY collection.create_time DESC
</select>