All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.quhaodian.user.freemaker.MenusDirective Maven / Gradle / Ivy

There is a newer version: 1.8.7
Show newest version
package com.quhaodian.user.freemaker;

import com.quhaodian.common.utils.DirectiveUtils;
import com.quhaodian.user.data.entity.Menu;
import com.quhaodian.user.data.service.MenuService;
import freemarker.core.Environment;
import freemarker.template.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 查找某个节点下一层的菜单
 */
public class MenusDirective implements TemplateDirectiveModel {

    @Autowired
    MenuService menuService;

    @Override
    public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
            throws TemplateException, IOException {

        // 其实完全可以不用它,params是个Map,自己通过key取值就可以了,做一下空值判断
        Integer id = DirectiveUtils.getInt("id", params);
        Integer size = DirectiveUtils.getInt("size", params);

        List page = menuService.findChildMenu(id);

        List menus = new ArrayList();
        for (Menu menu : page) {

//			boolean ok = SecurityUtils.getSubject().isPermitted(menu.getName());
//			if (ok) {
//				menus.add(menu);
//			}
        }

        Map paramWrap = new HashMap(params);
        paramWrap.put("list", ObjectWrapper.DEFAULT_WRAPPER.wrap(page));
        Map origMap = DirectiveUtils.addParamsToVariable(env, paramWrap);
        if (body != null) {
            body.render(env.getOut());
        }
        DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap);

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy