Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the mybatis-plus paging type conversion tool class

Shulou Source: shulou.com Published: 2022-06-01 06:16:30 11月15日 Update

This article Xiaobian introduces in detail for you "mybatis-plus page type conversion tool class how to use", the content is detailed, the steps are clear, the details are handled properly, I hope this article "mybatis-plus page type conversion tool class how to use" article can help you solve doubts, the following follow the editor's ideas slowly in-depth, together to learn new knowledge.

Preface

When using mybatis-plus 's paging object, because the generics in the records of the paging object queried by mybatis-puls are entities, sometimes you need to convert the entity to the object shown at the front end, so write a paging data type conversion tool to solve this problem.

Code example public IPage pageList (TransparentGeologicalQueryDTO query) {IPage page=this.lambdaQuery () .like (StringUtil.isNotBlank (query.getName ()), TransparentGeological::getName,query.getName ()) .eq (Objects.nonNull (query.getWorkFaceId ()), TransparentGeological::getWorkFaceId,query.getWorkFaceId ()) .orderByDesc (TransparentGeological::getCreateTime) .page (Condition.getPage (query)) IPage result= PageUtil.copy (page,TransparentGeologicalVO.class); result.getRecords (). ForEach (e-> e.setWorkFaceName (WorkFaceCache.getWorkFaceName (e.getWorkFaceId (); return result;}

Pom files introduce mybatis-pius dependencies

Com.baomidou mybatis-plus-boot-starter 3.4.2

The paging conversion tools are as follows

Import com.baomidou.mybatisplus.core.metadata.IPage;import com.baomidou.mybatisplus.extension.plugins.pagination.Page;import org.springblade.core.tool.utils.BeanUtil; import java.util.List Public class PageUtil {/ * @ Description: convert to IPage object * @ Author: tarzan * @ Date: 9:40 * / public static IPage copy (IPage page, List sourceList, Class targetClazz) {IPage pageResult = new Page (page.getCurrent (), page.getSize (), page.getTotal ()); pageResult.setPages (page.getPages ()); List records = BeanUtil.copy (sourceList, targetClazz) PageResult.setRecords (records); return pageResult;} public static IPage copy (IPage page, Class targetClazz) {return copy (page,page.getRecords (), targetClazz) } after reading this, the article "how to use the mybatis-plus page type conversion tool class" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.

Tags: Tools types objects articles content entities propriety code front end preface ideas data files new knowledge time more sometimes steps knowledge knowledge points Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker MySQL Shulou Tech Info Xiaomi Huawei