首页>代码>ssm开发组织机构后台管理系统>/human/src/main/java/com/ycxm/controller/SysMenuController.java
package com.ycxm.controller;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.ycxm.dao.SysMenuMapper;
import com.ycxm.dao.SysRoleMenuMapper;
import com.ycxm.pojo.SysMenu;
import com.ycxm.pojo.SysUser;
import com.ycxm.pojo.TableInfo;
import com.ycxm.pojo.Tree;
import com.ycxm.service.SysMenuService;
import com.ycxm.util.TreeBuildUilt;

@Controller
@RequestMapping("sysmenu")
public class SysMenuController extends BaseController {

	@Autowired
	private SysMenuService sysMenuService;

	@Autowired
	private SysRoleMenuMapper roleMenuMapper;

	@Autowired
	private SysMenuMapper menuMapper;

	@GetMapping("page")
	public String page() {

		return "sysmenu";
	}

	@GetMapping("pageAdd")
	public ModelAndView pageAdd(Integer id) {
		ModelAndView mv = new ModelAndView("sysmenuAdd");
		List<SysMenu> menu = sysMenuService.getOne(id);
		mv.addObject("menu", menu.get(0));
		return mv;
	}

	@RequestMapping("menu")
	@ResponseBody
	public List<Tree> getAllMenuTreeByUser() {
		SysUser user = getCurrentUser();
		List<SysMenu> menus = sysMenuService.getMenuWithUser(user);
		List<Tree> list = new ArrayList<Tree>();
		List<Tree> treeList = new ArrayList<Tree>();
		for (SysMenu menu : menus) {
			Tree tree = new Tree();
			tree.setId(menu.getId().toString());
			tree.setParentId(menu.getParentId() == null ? "" : menu.getParentId().toString());
			tree.setText(menu.getText());
			tree.setUrl(menu.getUrl());
			tree.setIconCls(menu.getIconCls());
			list.add(tree);
		}
		treeList = TreeBuildUilt.bulidTree(list);
		return treeList;
	}

	@RequestMapping("menus")
	@ResponseBody
	public List<Tree> getAllMenu() {
		List<SysMenu> menus = menuMapper.getAllMenus();
		List<Tree> list = new ArrayList<Tree>();
		for (SysMenu menu : menus) {
			Tree tree = new Tree();
			tree.setId(menu.getId().toString());
			tree.setParentId(menu.getParentId() == null ? "" : menu.getParentId().toString());
			tree.setText(menu.getText());
			tree.setUrl(menu.getUrl());
			tree.setIconCls(menu.getIconCls());
			list.add(tree);
		}
		List<Tree> treeList = TreeBuildUilt.bulidTree(list);
		return treeList;
	}

	@RequestMapping("tree")
	@ResponseBody
	public List<Tree> getTree() {
		List<SysMenu> menus = sysMenuService.getOne(null);
		List<Tree> list = new ArrayList<Tree>();
		for (SysMenu menu : menus) {
			Tree tree = new Tree();
			tree.setId(menu.getId().toString());
			tree.setParentId(menu.getParentId() == null ? "" : menu.getParentId().toString());
			tree.setText(menu.getText());
			tree.setUrl(menu.getUrl());
			tree.setIconCls(menu.getIconCls());
			list.add(tree);
		}
		List<Tree> treeList = TreeBuildUilt.bulidTree(list);
		return treeList;
	}

	@RequestMapping("showAllMenus")
	@ResponseBody
	public TableInfo showAllMenus(SysMenu sysMenu) {
		List<SysMenu> menu = sysMenuService.getAllMenu(sysMenu);
		TableInfo info = new TableInfo(menu.size(), menu);
		return info;
	}

	@RequestMapping("delete")
	@ResponseBody
	public Boolean delete(Integer id) {

		return sysMenuService.delete(id);
	}

	@RequestMapping("update")
	@ResponseBody
	public Boolean update(SysMenu menu) {

		return sysMenuService.update(menu);
	}

	@RequestMapping("getMenuIDByRoleID")
	@ResponseBody
	public List<Integer> getMenuIDByRoleID(Integer roleID) {
		List<Integer> list = roleMenuMapper.getMenuIDByRoleID(roleID);
		return list;
	}

}
最近下载更多
zxc131313  LV12 2022年10月22日
45618955  LV8 2022年6月16日
我是helloworld  LV23 2022年5月25日
wuying8208  LV15 2022年5月12日
893213895  LV18 2021年12月19日
噜噜啦啦露露  LV8 2021年12月14日
wanglinddad  LV54 2021年12月10日
志犟CR7  LV3 2021年11月10日
苏屿999  LV9 2021年10月18日
最代码-宋家辉  LV61 2021年8月22日
最近浏览更多
wddq123 4月3日
暂无贡献等级
minjing123  LV8 1月4日
WBelong  LV7 2023年12月26日
shuangfu  LV24 2023年12月2日
uni-code_0123  LV1 2023年11月27日
政政123456  LV3 2023年10月22日
泓鼎168  LV19 2023年10月16日
wwewww  LV4 2023年10月15日
zhangjianghe 2023年9月7日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友