mybatis一对多关系用oracle实现分页

有 回复表,二级回复表(像贴吧里的楼中楼回复)。

在主贴页面里,把回复+二级回复一起分页显示。
大概是这种形式:

回复1

-二级回复1

-二级回复2

回复2

回复3

回复类里面有二级回复集合,oracle存储过程里实现分页查询时,先回复 left join 二级回复,再用rownum分页。

但是界面上显示的时候,因为我先把一级回复显示出来后,再遍历显示该一级回复对象里的二级回复集合,所以第二页开始会再显示一级回复的内容,就会超出原本设置的每页行数值。

补充:
行数是指回复+二级回复的数量。所以如果按我这么写sql的话,一级跟他的第一个二级回复会变成一条数据,而实际上要求是把他们分成两行。并且第二页的话,如果回复3有二级回复,会把回复3也给显示出来,就会变成6行:
回复3
--二级回复3
回复4
回复5
回复6
回复7

想要的效果是去掉回复3的:
--二级回复3
回复4
回复5
回复6
回复7

想问这种要怎么解决? 还是说表设计的不对,应该只用一张回复表?


喵喔喔
浏览 1336回答 2
2回答

四季花海

之前做过一个类似的无限级的菜单树,我大概说一下我的思路,具体能不能实现你可以试试,主要是通过Map+递归实现层层嵌套,然后我觉的可以对一级的回复坐分页,结构部分代码你可以参考下:public class ResourceTree {&nbsp; &nbsp; public static Map<String, Object> mapArray = new LinkedHashMap<String, Object>();&nbsp; &nbsp; public List<Resource> menuCommon;&nbsp; &nbsp; public List<Object> list = new ArrayList<Object>();&nbsp; &nbsp; public List<Object> menuList(List<Resource> resource) {&nbsp; &nbsp; &nbsp; &nbsp; this.menuCommon = resource;&nbsp; &nbsp; &nbsp; &nbsp; for (Resource x : resource) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Map<String, Object> mapArr = new LinkedHashMap<String, Object>();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (x.getParentId() == 0) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mapArr.put("id", x.getId());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mapArr.put("text", x.getResourceName());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mapArr.put("resourceUrl", x.getUrl());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mapArr.put("resourceParent", x.getParentId());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mapArr.put("resourceType", x.getType());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mapArr.put("resourceTag", x.getResourceCode());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // mapArr.put("resourceIcon", x.getResourceIcon());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // mapArr.put("resourceParentPath", x.getResourceParentPath());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mapArr.put("children", menuChild(x.getId()));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; list.add(mapArr);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; return list;&nbsp; &nbsp; }&nbsp; &nbsp; public List<?> menuChild(int id) {&nbsp; &nbsp; &nbsp; &nbsp; List<Object> lists = new ArrayList<Object>();&nbsp; &nbsp; &nbsp; &nbsp; for (Resource a : menuCommon) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Map<String, Object> childArray = new LinkedHashMap<String, Object>();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (a.getParentId() == id) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; childArray.put("id", a.getId());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; childArray.put("text", a.getResourceName());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; childArray.put("resourceUrl", a.getUrl());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; childArray.put("resourceParent", a.getParentId());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; childArray.put("resourceType", a.getType());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; childArray.put("resourceTag", a.getResourceCode());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // childArray.put("resourceIcon", a.getResourceIcon());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // childArray.put("resourceParentPath", &nbsp; &nbsp;a.getResourceParentPath());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; childArray.put("children", menuChild(a.getId()));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lists.add(childArray);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; return lists;&nbsp; &nbsp; }}

人到中年有点甜

先按条件查出每一页的ID数组 用你分页的方式再用ID数组 查询出你需要的详细数据
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Oracle