小工具知识网

当前位置: 首页 > 行业知识 > Mybatis plus 分页查询total为0 及日期类格式化配置

行业知识

Mybatis plus 分页查询total为0 及日期类格式化配置

2026-11-14 06:00:17 来源:互联网转载

问题���述:

()

使用mp分页的时候,debug发现page的total是0条。

原因:

()

1.未配置分页拦截器

    @Bean    public PaginationInterceptor paginationInterceptor(){        return new PaginationInterceptor();    }

2.写错方法了...(好吧我就是这种)

应该是selectPage而不是selectList

        ‍♀️Page page = new Page(form.getPage(),form.getLimit());//启用分页        LambdaQueryWrapper wrapper = new LambdaQueryWrapper();        wrapper.like(StringUtils.isNotBlank(form.getCommunityName()),Community::getCommunityName,form.getCommunityName());        wrapper.eq(form.getCommunityId()!=null,Community::getCommunityId,form.getCommunityId());        ‍♂️Page communityPage = communityMapper.selectPage(page, wrapper);        List records = communityPage.getRecords();

手动分割线------

记录springbboot日期类格式化的配置。

也就是我们需要返回的时候按照前端指定的格式返回。

1.通过JsonFormat注解,在日期字段上添加。

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone ="GMT+8" )    private Date createTime;

2.yaml配置(建议,如果有很多字段需要添加的话)。

spring:  jackson:    time-zone: GMT+8    date-format: yyyy-MM-dd HH:mm:ss

上一篇:商场服务器怎么维护好?

下一篇:劳动用工备案不通过怎么修改呢