Unlimited classification, cascade.

Mainly applied recursively, this application for news category.

Code began default level is 0,

By calling for once, handle class recursive find out, for the second time through, the local categroy in the foreground of the display, plus "discount" sign.

public List<Category> getCategorysList(Integer level){
        
        List<Category> ls= categoryMapper.getCategorys(level);
        List<Category> temp = new ArrayList<Category>();
        
        for (Category category : ls) {
            temp.add(category);
            List<Category> categorysList = getCategorysList(category.getId());
            
            for (Category category2 : categorysList) {
                category2.setName("└─"+category2.getName());
            }
            temp.addAll(categorysList);
        }
        return temp;

 

Guess you like

Origin www.cnblogs.com/sdgtxuyong/p/12574427.html