问答详情
源自:5-1 性能分析实现及参数设置

mybatis-plus 的流式查询怎么实现呢

mybatis-plus 的流式查询怎么实现呢

提问者:taskiller123 2019-11-07 20:31

个回答

  • 老猿
    2020-12-29 11:59:04

    你好,对于你的提问,我之前的回答,所问非所答了,关于流式查询,mp应该是没有特殊的支持。但是mybatis是支持的,mybatis中可以使用Cursor,进行流式查询,具体方法你可以查阅网上相关文章。


  • 老猿
    2019-11-07 22:21:13

            我还真不了解流式查询,你指的是条件构造器的链式调用吗?MP普通的条件构造器和Lambda条件构造器,都支持链式调用,通用service也提供了链式调用方式,我入门篇的课上都讲过。我举个条件构造器的链式调用例子,例如:

    QueryWrapper<User> qw = new QueryWrapper<>(); 
    qw.like("name","laoyuan").eq("age",21).like("address","XX省");
    List<User> listUser = userMapper.selectList(qw);


  • qq_慕田峪2309846
    2021-07-16 16:26:17

    public interface Level1Mapper extends BaseMapper<Level1> {
    
        @Select("select * from a_level1 limit #{limit}")
        Cursor<Level1> scan(@Param("limit") int limit);
    }
    @GetMapping("/level1s_cursor/{limit}")
    @Transactional(readOnly = true)
    public void level1sCursor(@PathVariable("limit") int limit) throws IOException {
        try (Cursor<Level1> cursor = level1Mapper.scan(limit)){
            cursor.forEach(i->log.debug(JSON.toJSONString(i)));
        }
    }

    mybaits  流式查询已经很简洁了