无感五
2019-05-15 23:58
采纳率: 94.7%
浏览 1.6k
已采纳

JAVA如果把FOR循环数据取出来

我现在这样写之后获取到最后一条数据
请问我该如果修改,才可以把全部数据循环出来

public List<UserOrder> findCat(){
        //查询一级下线
     //   int popularizeId = (int) tokenService.getAuthentication().get( "popularizeId" );//获取分销推广id
        int popularizeId = 531571277;//获取分销推广id
        EntityWrapper<User> userEntityWrapper = new EntityWrapper<>(  );
        userEntityWrapper.where( "PARENT_ID={0}",popularizeId );
        List<User> userList = webUsersMapper.selectList( userEntityWrapper );
        List<UserOrder> userOrder = null;
        for(User user : userList){
            Long userId = user.getId();//获得用户id
            System.out.println("用户id"+ userId );
            EntityWrapper<UserOrder> userOrderEntityWrapper = new EntityWrapper<>(  );
            userOrderEntityWrapper.where( "UID={0}" ,userId);
            webUserOrderMapper.selectList( userOrderEntityWrapper );
            userOrder = webUserOrderMapper.selectList( userOrderEntityWrapper );
        }

        return userOrder;
    }
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • 小达哥的垃圾桶 2019-05-16 09:16
    已采纳
    public List<List<UserOrder>> findCat(){
            //查询一级下线
            //   int popularizeId = (int) tokenService.getAuthentication().get( "popularizeId" );//获取分销推广id
            int popularizeId = 531571277;//获取分销推广id
            EntityWrapper<User> userEntityWrapper = new EntityWrapper<>(  );
            userEntityWrapper.where( "PARENT_ID={0}",popularizeId );
            List<User> userList = webUsersMapper.selectList( userEntityWrapper );
            List<List<UserOrder>> userOrderList = new ArrayList<List<UserOrder>>();
            for(User user : userList){
                List<UserOrder> userOrder = new ArrayList<UserOrder>();
                Long userId = user.getId();//获得用户id
                System.out.println("用户id"+ userId );
                EntityWrapper<UserOrder> userOrderEntityWrapper = new EntityWrapper<>(  );
                userOrderEntityWrapper.where( "UID={0}" ,userId);
                webUserOrderMapper.selectList( userOrderEntityWrapper );
                userOrder = webUserOrderMapper.selectList( userOrderEntityWrapper );
                userOrderList.add(userOrder);
            }
            return userOrderList;
        }
    
    评论
    解决 无用
    打赏 举报
查看更多回答(2条)

相关推荐 更多相似问题