mybatis-plus的使用入门学习笔记 (持续更新)

in 日常随笔 with 0 comment 访问: 296 次

查询构造器 QueryWrapper

    @Override
    @Cached(name="manuscript:list:organizationId:",key = "#organizationId+'-'+#pageNum+'-'+#pageSize",
            expire = 300,cacheNullValue=true)
    @CacheRefresh(refresh = 60, stopRefreshAfterLastAccess = 300)
    public Page<Manuscript> getList(long organizationId, int pageNum, int pageSize) {
        QueryWrapper<Manuscript> wrapper = new QueryWrapper<>();
        // Manuscript.class中所有字段,除了'content'
        wrapper.select(Manuscript.class, tableFieldInfo -> !tableFieldInfo.getColumn().equals("content")).
                isNull("deleted_time").
                eq("organization_id",organizationId).
                orderByDesc("top_at").
                orderByDesc("created_time");


        Page<Manuscript> manuscriptPage =  page(new Page<>(pageNum, pageSize), wrapper);

        /* 迭代处理数据
        List<Manuscript> records = manuscriptPage.getRecords();
        Iterator iterator = records.iterator();
        while(iterator.hasNext()) {
            Manuscript manuscript = (Manuscript) iterator.next();
            manuscript.setTitle("迭代修改引用数据");
        }
        */

        return manuscriptPage;
    }

模型方式

https://www.jianshu.com/p/ceb1df475021

赞赏支持
Responses