Bootstrap

Myabtis-puls

Myabtis-puls分页返回自定义字段

一、定义一个PageUtil工具类

代码如下(示例):

public class PageUtil implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 总记录数
     */
    private int total;
    /**
     * 每页记录数
     */
    private int size;
    /**
     * 总页数
     */
    private int pages;
    /**
     * 当前页数
     */
    private int current;

    private long processingStatus;

    private long processedStatus;

    private long allStatus;

    public long getProcessingStatus() {
        return processingStatus;
    }

    public void setProcessingStatus(long processingStatus) {
        this.processingStatus = processingStatus;
    }

    public long getProcessedStatus() {
        return processedStatus;
    }

    public void setProcessedStatus(long processedStatus) {
        this.processedStatus = processedStatus;
    }

    public long getAllStatus() {
        return allStatus;
    }

    public void setAllStatus(long allStatus) {
        this.allStatus = allStatus;
    }

    /**
     * 列表数据
     */
    private List<?> records;




    /**
     * 分页
     * @param records        列表数据
     * @param total  总记录数
     * @param size    每页记录数
     * @param current    当前页数
     */
    public PageUtil(List<?> records, int total, int size, int current) {
        this.records = records;
        this.total = total;
        this.size = size;
        this.current = current;
        this.pages = (int)Math.ceil((double)total/size);
    }

    /**
     * 分页
     */
    public PageUtil(IPage<?> page) {
        this.records = page.getRecords();
        this.total = (int)page.getTotal();
        this.size = (int)page.getSize();
        this.current = (int)page.getCurrent();
        this.pages = (int)page.getPages();
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public int getPages() {
        return pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }

    public int getCurrent() {
        return current;
    }

    public void setCurrent(int current) {
        this.current = current;
    }

    public List<?> getRecords() {
        return records;
    }

    public void setRecords(List<?> records) {
        this.records = records;
    }
}

二、定义controller

代码如下(示例):

public class ManagementController {
    @Autowired
    private ManagementService ManagementService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestBody ManagementQuery Query){
        return  ManagementService.selectAMList(Query);
    }


}

三、定义service接口

public interface ManagementService extends IService<Management> {

    R selectAMList(ManagementQuery tQuery);
}

三、定义ServiceImpl实现类

@Service("ManagementService")
public class ManagementServiceImpl extends ServiceImpl<ManagementDao, Management> implements ManagementService {

    @Autowired
    ManagementDao Mapper;
    @Override
    public R selectAMList(ManagementQuery Query) {
        Page<TblScmTaskAirlineManagement> page = new Page<>();
        try {
            Integer pageNum = Integer.valueOf(airlineManagementQuery.getPageNum());
            Integer pageSize = Integer.valueOf(airlineManagementQuery.getPageSize());
            page.setCurrent(pageNum);
            page.setSize(pageSize);
            IPage<Management> managementIPage = Mapper.selectAMList(page, Query);
            PageUtil pages = new PageUtil(managementIPage);
            return R.ok(pages);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return R.failed("失败");
    }

}

四、定义mapper接口

@Mapper
public interface ManagementDao extends BaseMapper<Management> {
    IPage<Management> selectAMList(Page<Management> page, @Param("query") ManagementQuery query);
}

五、定义mapper.xml

<mapper namespace="com.msb.mall.product.dao.ManagementDao">
    <select id="selectAMList" parameterType="com.msb.mall.product.entity.ManagementQuery" resultType="com.msb.mall.product.entity.Management">
        select a.id,a.taskName
        from tbl_scm_task_airline_management a
        <where>
            <if test="query.taskName != null and query.taskName != ''">
                and a.task_name = #{query.taskName}
            </if>
            <if test="query.executeStatus!= null and query.executeStatus!= '' ">
                <choose>
                    <when test="query.executeStatus == 0">
                        and (a.EXECUTE_STATUS = 1 or a.EXECUTE_STATUS = 2)
                    </when>
                    <when test="query.executeStatus == 1">
                        and a.EXECUTE_STATUS = 1
                    </when>
                    <when test="query.executeStatus == 2">
                        and a.EXECUTE_STATUS = 2
                    </when>
                </choose>
            </if>
        </where>
    </select>
</mapper>

六、返回结果

在这里插入图片描述

悦读

道可道,非常道;名可名,非常名。 无名,天地之始,有名,万物之母。 故常无欲,以观其妙,常有欲,以观其徼。 此两者,同出而异名,同谓之玄,玄之又玄,众妙之门。

;