页面:
<script type="text/javascript" src="plugins/angularjs/angular.min.js"></script>
<script type="text/javascript" src="js/service/userService.js"></script>
<script type="text/javascript" src="js/controller/userController.js"></script>
<div class="item bo" ng-repeat="entity in list">
<!-- 去重 -->
<h3><a href="" ng-hide="list[$index].catOneName == list[$index+1].catOneName">{{entity.catOneName}}</a></h3>
<div class="item-list clearfix">
<div class="subitem">
<dl class="fore">
<!-- 去重 -->
<dt><a href="" ng-hide="list[$index].catTwoName == list[$index+1].catTwoName">{{entity.catTwoName}}</a></dt>
<dd><em><a href="">{{entity.catThreeName}}</a></em></dd>
</dl>
</div>
</div>
</div>
实体类:
public class TbItemCat implements Serializable{
private Long id;
private Long parentId;
private String name;
private Long typeId;
sql做自连接查询:
mapper.xml
<select id="selectAll" resultType="java.util.HashMap">
SELECT
cat1.`id` catOneId,cat1.`name` catOneName,cat1.`parent_id` parentIdOne,cat2.id catTwoId,cat2.`name` catTwoName,cat2.`parent_id` parentIdTwo,cat3.id catThreeId,cat3.`name` catThreeName,cat3.`parent_id` parentIdThree
FROM tb_item_cat cat1,tb_item_cat cat2,tb_item_cat cat3
WHERE cat1.`id`=cat2.`parent_id` AND cat2.id=cat3.`parent_id`
</select>
mapper接口:
List<Map<String,TbItemCat>> selectAll();
impl实现类:
@Override
public List<Map<String,TbItemCat>> selectAll() {
List<Map<String,TbItemCat>> selectAll = itemCatMapper.selectAll();
return selectAll;
}
controller控制层:
@RequestMapping("/findAll")
public List<Map<String,TbItemCat>> findAll(){
List<Map<String,TbItemCat>> selectAll = itemCatService.selectAll();
return selectAll;
}
更多内容请见原文,原文转载自:https://blog.csdn.net/weixin_44519496/article/details/120575453
标签:selectAll,parent,List,cat1,cat2,第五章,首页,angularjs,id From: https://www.cnblogs.com/wangchuanxinshi/p/17079265.html