2018-5-12 13:51:52

1.@RequestParam注解

例如:(@RequestParam(value = "parentId" , defaultValue = "0")int parentId),如果前台没传parentId,则默认值是0。

2.com.google.guava:guava:20.0 的jar包。集合的创建。

3.mapper的返回结果是list的 ,mybatis已经封装好了,而且为空值也不会返回null。

4.通过equals比较的对象,如果相等,那么他们的hashcode也是相同的,反过来则不一定。

5.set(xxx)集合放置普通对象要重写equals和hashcode方法。

6.递归算法

public ServerResponse<List<Integer>> selectCategoryAndChildrenById(Integer categoryId){
    Set<Category> categorySet = Sets.newHashSet();
    findChildCategory(categorySet,categoryId);

    List<Integer> categoryIdList = Lists.newArrayList();
    if(categoryId != null ){
        for(Category categoryItem : categorySet){
            categoryIdList.add(categoryItem.getId());
        }
    }
    return  ServerResponse.createBySuccess(categoryIdList);
}
//递归算法算出子节点
private Set<Category> findChildCategory(Set<Category> categorySet,Integer categoryId){
    Category category = categoryMapper.selectByPrimaryKey(categoryId);
    if(category != null){
        categorySet.add(category);
    }
    //查找子节点,递归算法一定要有一个退出条件
    List<Category> categoryList = categoryMapper.selectCategoryChildrenByParentId(categoryId);
    for (Category categoryItem : categoryList) {
        findChildCategory(categorySet,categoryItem.getId());
    }
    return categorySet;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值