若依分页问题

若依分页问题

分页当对查出的数据做处理后,分页失效

原来的代码

    @GetMapping("/list")
    public TableDataInfo list(Journalism journalism)
    {
        startPage();
        List<JournalismHomeDto> list = journalismService.selectJournalismList(journalism);
        return getDataTable(list);
    }

改造方式:
分页:startPage();
只对该语句以后的第一个查询(Select)语句得到的数据进行分页。

  1. controller
        @GetMapping("/list")
        public TableDataInfo list(Journalism journalism)
        {
            List<JournalismHomeDto> list = journalismService.selectJournalismList(journalism);
            return getDataTable(list);
        }
    

2.service

分页开始,查到结果先转成pageinfo,然后更换其中的dto,再赋值

 @Override
    public List<JournalismHomeDto> selectJournalismList(Journalism journalism) {
        PageUtils.startPage();
        List<Journalism> journalisms = journalismMapper.selectJournalismList(journalism);
        return selectJournalismHomeList(journalisms);
    }

    public List<JournalismHomeDto> selectJournalismHomeList(List<Journalism> journalisms){
        PageInfo<Journalism> pageInfo = new PageInfo<>(journalisms);
        PageInfo<JournalismHomeDto> journalismHomeDtoPageInfo = PageInfoUtil.pageInfo2PageInfoDTO(pageInfo, JournalismHomeDto.class);
        for (JournalismHomeDto journalismHomeDto:journalismHomeDtoPageInfo.getList()) {
            Program program = programService.getPositiveByJournalismId(journalismHomeDto.getJournalismid());
            if(program!=null){
                journalismHomeDto.setThumbnail(CommonConfig.getSdkDevUrl()+program.getThumbnail());
            }
        }
        return journalismHomeDtoPageInfo.getList();
    }
  1. pageinfoUtil工具类

    import com.github.pagehelper.Page;
    import com.github.pagehelper.PageInfo;
    import org.springframework.beans.BeanUtils;
    
    /**
     * @description:github Pagehelper工具
     * @Author:JasonZhang
     */
    public class PageInfoUtil {
        public static  <P, D> PageInfo<D> pageInfo2PageInfoDTO(PageInfo<P> pageInfoPO, Class<D> dClass) {
            Page<D> page = new Page<>(pageInfoPO.getPageNum(), pageInfoPO.getPageSize());
            page.setTotal(pageInfoPO.getTotal());
            for (P p : pageInfoPO.getList()) {
                D d = null;
                try {
                    d = dClass.newInstance();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                BeanUtils.copyProperties(p, d);
                page.add(d);
            }
            return new PageInfo<>(page);
        }
    }
    
    
  2. pageUtils(若依自带)

    import com.cdv.common.core.page.PageDomain;
    import com.cdv.common.core.page.TableSupport;
    import com.cdv.common.utils.sql.SqlUtil;
    import com.github.pagehelper.PageHelper;
    
    public class PageUtils extends PageHelper {
        public PageUtils() {
        }
    
        public static void startPage() {
            PageDomain pageDomain = TableSupport.buildPageRequest();
            Integer pageNum = pageDomain.getPageNum();
            Integer pageSize = pageDomain.getPageSize();
            String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
            Boolean reasonable = pageDomain.getReasonable();
            PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable);
        }
    
        public static void clearPage() {
            PageHelper.clearPage();
        }
    }
    
  3. mapper.xml

        <select id="selectJournalismList" parameterType="Journalism" resultMap="JournalismResult">
            <include refid="selectJournalismVo"/>
            <where>
                <if test="journalismid != null  and journalismid != ''"> and INSTR( #{journalismid} , journalismId) >= 1</if>
                <if test="title != null  and title != ''"> and title like concat('%', #{title}, '%')</if>
                <if test="content != null  and content != ''"> and content = #{content}</if>
                <if test="typeid != null  and typeid != ''"> and typeid like concat('%', #{typeid}, '%')</if>
                <if test="device != null  and device != ''"> and device = #{device}</if>
                <if test="editor != null  and editor != ''"> and editor = #{editor}</if>
                <if test="creator != null  and creator != ''"> and creator = #{creator}</if>
                <if test="tags != null  and tags != ''"> and tags = #{tags}</if>
                <if test="status != null "> and status = #{status}</if>
                <if test="published != null "> and published = #{published}</if>
                <if test="processnode != null  and processnode != ''"> and processnode = #{processnode}</if>
                <if test="level != null "> and level = #{level}</if>
                <if test="createtime != null "> and createtime = #{createtime}</if>
                <if test="location != null  and location != ''"> and location = #{location}</if>
                <if test="readstatus != null "> and readStatus = #{readstatus}</if>
                <if test="source != null  and source != ''"> and source = #{source}</if>
                <if test="tenantid != null  and tenantid != ''"> and tenantid = #{tenantid}</if>
                <if test="introduction != null  and introduction != ''"> and introduction = #{introduction}</if>
                <if test="auditstatus != null  and auditstatus != ''"> and auditStatus = #{auditstatus}</if>
                <if test="restrictions != null  and restrictions != ''"> and restrictions = #{restrictions}</if>
                <if test="changestate != null "> and changeState = #{changestate}</if>
                <if test="organization != null  and organization != ''"> and organization = #{organization}</if>
                <if test="displaytime != null "> and displayTime = #{displaytime}</if>
                <if test="channelid != null  and channelid != ''"> and channelid = #{channelid}</if>
                <if test="organizationid != null  and organizationid != ''"> and organizationid = #{organizationid}</if>
                <if test="ischecked != null "> and ischecked = #{ischecked}</if>
                <if test="picturesize != null "> and picturesize = #{picturesize}</if>
                <if test="programsize != null "> and programsize = #{programsize}</if>
                <if test="audiosize != null "> and audiosize = #{audiosize}</if>
                <if test="deleteflag != null "> and deleteflag = #{deleteflag}</if>
                <if test="cmsstatus != null "> and cmsStatus = #{cmsstatus}</if>
                <if test="security != null "> and security = #{security}</if>
                <if test="sourceid != null  and sourceid != ''"> and sourceid = #{sourceid}</if>
                <if test="cliptype != null "> and cliptype = #{cliptype}</if>
                <if test="languages != null "> and languages = #{languages}</if>
                <if test="type != null "> and type = #{type}</if>
                <if test="publish != null "> and INSTR( #{publish} , publish) >= 1</if>
                <if test="transtitle != null "> and transtitle = #{transtitle}</if>
                <if test="downTenant != null and downTenant != ''" > and down_tenant = #{downTenant} </if>
                <if test="queryTenant != null and queryTenant != ''" > and query_tenant = #{queryTenant} </if>
            </where>
            order by publish asc,displayTime desc
        </select>
    
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值