logger.info("获取user_id为{}的用户信息", uid); User user = userService.get(uid); logger.info("获取用户详情-所在地地址信息"); Address address = addressService.get(user.getUser_address().getAddress_areaId()); Stack<String> addressStack = new Stack<>(); //最后一级地址 addressStack.push(address.getAddress_name() + " "); //如果不是第一级地址 while (!address.getAddress_areaId().equals(address.getAddress_regionId().getAddress_areaId())) { address = addressService.get(address.getAddress_regionId().getAddress_areaId()); addressStack.push(address.getAddress_name() + " "); } StringBuilder builder = new StringBuilder(); while (!addressStack.empty()) { builder.append(addressStack.pop()); } logger.info("所在地地址字符串:{}", builder); Address add=new Address(); add.setAddress_name(builder.toString()); user.setUser_address(add); logger.info("获取用户详情-家乡地址信息"); address = addressService.get(user.getUser_homeplace().getAddress_areaId()); //最后一级地址 addressStack.push(address.getAddress_name() + " "); //如果不是第一级地址 while (!address.getAddress_areaId().equals(address.getAddress_regionId().getAddress_areaId())) { address = addressService.get(address.getAddress_regionId().getAddress_areaId()); addressStack.push(address.getAddress_name() + " "); } builder = new StringBuilder(); while (!addressStack.empty()) { builder.append(addressStack.pop()); } logger.info("家乡地址字符串:{}", builder); user.setUser_homeplace(add);
时间: 2024-04-03 22:31:05 浏览: 41
tencentyun#qcloud-documents#通过 userid 获取用户详情1
这段代码是关于获取用户信息中的地址信息和将其转化为字符串的过程。首先,通过用户ID获取用户信息,然后获取用户所在地的地址信息和家乡的地址信息。利用栈的结构,将地址信息从最后一级地址开始依次入栈,直到第一级地址。通过弹出栈中的元素并拼接成字符串,得到完整的地址字符串。最后,将地址字符串设置为用户的所在地地址和家乡地址,并返回用户信息。
阅读全文