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; }