1 Star 4 Fork 0

qlslylq / JavaDesign

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.en.md

  作者:qlslylq (浅蓝深蓝叶落秋,https://www.bmob.cn/shop/detail/396)

  联系:13297089301 QQ:2939143482

  QQ讨论群:326550832(AndroidDesign)

  名下开源框架:

  1.AndroidDesign(eclipse,in 2014)

  2.AndroidDesign(AndroidStudio,in 2016)

  3.AdmxSDK及AdmxSDK_v2(AndroidStudio,in 2017)

  4.UnityDesign(VisualStudio,C#,in 2017)

  5.FlutterDesign(AndroidStudio,in 2019)

  6.JavaDesign(Intellij IDEA,in 2020)

  名下开源项目:

  1.AndroidDesignQtfy (https://www.bmob.cn/shop/detail/396)

  2.UnityDesignEasyAR (AR纹理识别demo)

  3.UnityDesignThreeInOne (三合一游戏demo)

  友情推广:

  华为云:华为云

华为云

JavaDesign

介绍

JavaSSM后台管理系统基础框架。以JSP前后端不分离方式搭建,jQueryEasyUI作为前端展示,SSM提供后台服务。

框架基本功能:菜单管理,角色管理,权限管理,用户管理,日志管理。

详细介绍

系统登录:登录后,根据所属角色权限动态展示三级菜单树。

菜单管理:三级菜单的增删查改;远端分页,搜索。

角色管理:角色增删查改;远端分页,搜索。

权限管理:不同角色的菜单权限(三层权限)分配。

用户管理:用户的增删查改;头像的上传,进度监听及展示;修改密码;远端多字段排序,筛选,分页,搜索。

日志管理:提供埋点日志记录服务;远端多字段排序,分页,搜索。

基本封装

后端Log类,StackTraceUtils类提供控制台日志点击自动跳转对应文件的行数功能,调用栈功能

后端BeanUtils,ELUtils,RedirectUtils,SessionUtils,SqlSessionFactoryUtils类提供对IOC,SpringEL,重定向,session操作,sql连接的基本封装

前端AjaxInterceptor,DialogUtil,ElementUtil,ExtendUtil,ImageUtil,LoadingUtil提供对全局ajax拦截(自动控制loading条显隐,并可单独修改文本),dialog常规操作,元素常规操作,对象扩展,图片加载(两种加载模式CenterCrop与FitCenter,和三种加载形状矩形,圆角,圆形的封装),loading常规操作的功能。

参考演变

Log与StackTraceUtils的自动跳转文件与调用栈功能,参考了本人名下AndroidDesign中的Log与StackTraceUtils,演变而来,Java与Android两端通用;

ImageUtil的两种加载模式,三种形状加载方式,参考了本人名下AndroidDesign中的ImageUtils或GlideUtils;

menu[list.jsp],role[list.jsp],user[list.jsp],参考了本人名下AndroidDesign中的窗口线及FreeApp中的窗口线写法;

SessionUtils,ELUtils,BeanUtils中的泛型去强转化写法,参考了本人名下AndroidDesign的BaseActivity中的findView泛型去强转化写法; 略。

系统环境

开发工具:Intellij IDEA 2020.1

Java版本:JDK 1.8

编译:Gradle 5.4.1

服务器:Tomcat 7.0.96

数据库:MySQL 8.0.16

系统采用技术:Spring + SpringMVC + Mybatis + Redis + html5 + css3 + javascript + jQuery + jQueryEasyUI + ajax + jsp + 面向过程 + 前后端不分离

导入JavaDesign项目配置:

1.ProStructure-->project配置编译输出目录:...\JavaDesign\out

2.Settings-->gradle配置编译方式:IDEA

3.添加Tomcat[local]运行:

Server配置浏览器启动页:http://localhost:8080/javadesign/system/login

Deployment添加.war(exploded),ApplicationContext:/javadesign

根目录中的javax.el-3.0.0.jar移动到tomcat的lib目录下

4.新建数据库ssm并导入项目根目录ssm.sql文件中的结构及数据

5.文件resources/spring-mybatis/spring-mybatis.xml中配置数据库连接,并启动MySql数据库

运行截图:

菜单管理

菜单管理-编辑菜单

角色管理

权限分配

日志管理

用户管理

用户管理-编辑用户

#### 代码示例:

#### 菜单列表前端:

/**
 * @Description 菜单列表
 * @Author https://gitee.com/qlslylq/UnityDesign
 * @link https://gitee.com/qlslylq/FlutterDesign
 * @link https://gitee.com/qlslylq/AndroidDesign
 **/

$(document).ready(function () {
    initElement();
    initData();
    initListener();
});

function initElement() {
    initToolBarEle();
    initGridEle();
}

function initData() {

}

function initListener() {

}

function onClick(ele) {
    if (ele.id == "icon-add") {
        openAddDialog();
    } else if (ele.id == "icon-add-btn") {
        openAddBtnDialog();
    } else if (ele.id == "icon-edit") {
        openEditDialog();
    } else if (ele.id == "icon-remove") {
        openDeleteDialog();
    } else if (ele.id == "icon-reload") {
        queryForAll();
    } else if (ele.id == "icon-search") {
        queryForSearchText();
    } else if ($(ele).attr("iconCls") == "icon-add") {
        openIconSelectDialog(ele);
    } else if (ele.id == "img") {
        selectElement(ele, "img-selected");
    }
}

/**
 * 初始化工具栏按钮<br/>
 */
function initToolBarEle() {
    var roleThirdMenus = JSON.parse(sessionStorage.getItem('roleThirdMenus'));
    for (var i = 0; i < roleThirdMenus.length; i++) {
        var btnHtml = '<a href="#" class="easyui-linkbutton"  data-index="' + i + '" onclick="' + roleThirdMenus[i].link + '()" plain = "true" > ' + roleThirdMenus[i].name + ' </a>';
        $(".wu-toolbar-button").append(btnHtml);
        $(".wu-toolbar-button [data-index=" + i + "]").linkbutton({
            iconCls: roleThirdMenus[i].icon
        });
    }
}

/**
 * 填充菜单数据<br/>
 */
function initGridEle() {
    $('#grid').treegrid({
        loadMsg: false,//网络层自定义控制loading显隐
        url: '../menu/getList',
        queryParams: {},
        idField: 'id',
        treeField: 'name',//从哪个Field开始展开树-->首个Field
        // loadFilter: filterDataForPager,
        loadFilter: function (data) {
            return data.data;
        },
        rownumbers: false,
        singleSelect: true,
        pageNumber: 1,
        pageSize: 100,
        pageList: [10, 20, 50, 80, 100],
        pagePosition: 'bottom',
        pagination: true,
        multiSort: true,
        fitColumns: true,
        fit: true,
        columns: [
            [{
                checkbox: true
            }, {
                field: 'id',
                title: 'ID',
                width: 130,
                sortable: true,
                hidden: "true"
            }, {
                field: 'name',
                title: '名称',
                width: 130,
                sortable: false
            }, {
                field: 'parent',
                title: '父级菜单',
                width: 130,
                sortable: false,
                formatter: function (value, row, index) {
                    if (row.parent) {
                        return row.parent.name;
                    } else {
                        return null;
                    }
                }
            }, {
                field: 'icon',
                title: '图标',
                width: 130,
                sortable: false,
                formatter(value, row, index) {
                    var ele = '<a class="' + value + '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>';
                    return ele + value;
                }
            }, {
                field: 'link',
                title: '链接',
                width: 130,
                sortable: false
            },]
        ], onLoadSuccess: function () {//数据加载成功
            $(this).treegrid('clearSelections');//选中即使刷新也会有选中缓存
        }
    });
}

/**
 *  打开添加窗口<br/>
 */
function openAddDialog() {
    showCustomDialog($("#dialog-add"), "添加菜单", false, function () {
        if (add()) {
            $("#dialog-add").dialog('close');
        }
    });
}

/**
 *  打开添加按钮窗口<br/>
 */
function openAddBtnDialog() {
    var item = $('#grid').treegrid('getSelected');
    if (item == null) {
        $.messager.warning("请先选择要绑定到的二级菜单~");
        return;
    }
    if (item._parentId == 0 || item.parent._parentId != 0) {
        $.messager.warning("请选择二级菜单~");
        return;
    }

    showCustomDialog($("#dialog-add-btn"), "添加按钮", false, function () {
        if (addBtn()) {
            $("#dialog-add-btn").dialog('close');
        }
    }, function () {
        $("#form-add-btn .easyui-combobox").combobox('setValue', item.id);
        $("#form-add-btn .easyui-combobox").combobox('setText', item.name);
    });
}

/**
 *  打开修改一二三级菜单窗口<br/>
 */
function openEditDialog() {
    var item = $('#grid').treegrid('getSelected');
    if (item == null) {
        $.messager.warning("请选择要修改的菜单项~");
        return;
    }
    if (item._parentId == 0 || item.parent._parentId == 0) {//一二级菜单
        showCustomDialog($("#dialog-edit"), "编辑菜单", false, function () {
            if (edit()) {
                $("#dialog-edit").dialog('close');
            }
        }, function () {
            $("#form-edit input[type='hidden']").val(item.id);
            $("#form-edit .easyui-combobox").combobox('setValue', item._parentId);
            $("#form-edit .easyui-combobox").combobox('setText', item.parent ? item.parent.name : "顶级菜单");
            $("#form-edit input[name='name']").val(item.name);
            $("#form-edit input[name='icon']").val(item.icon);
            $("#form-edit input[name='link']").val(item.link);
        });
    } else {//三级菜单
        showCustomDialog($("#dialog-edit-btn"), "编辑按钮", false, function () {
            if (editBtn()) {
                $("#dialog-edit-btn").dialog('close');
            }
        }, function () {
            $("#form-edit-btn input[type='hidden']").val(item.id);
            $("#form-edit-btn .easyui-combobox").combobox('setValue', item._parentId);
            $("#form-edit-btn .easyui-combobox").combobox('setText', item.parent.name);
            $("#form-edit-btn input[name='name']").val(item.name);
            $("#form-edit-btn input[name='icon']").val(item.icon);
            $("#form-edit-btn input[name='link']").val(item.link);
        });
    }
}

/**
 *  打开图标选择窗口<br/>
 */
function openIconSelectDialog(ele) {
    if ($("#table").children().length == 0) {
        $.post({
            url: "../menu/getIconList",
            async: false,
            success: function (data) {
                var list_icon = data.data;
                var tbody = $("#table");
                var content = '';
                tbody.empty();

                $.each(list_icon, function (i, item) {
                    var fileName = item.toString();
                    var iconName = fileName.substring(0, fileName.indexOf("."));
                    var iconClassName = "icon-" + iconName.replace(/_/g, "-");
                    var icon = '<a id="img" style="position: absolute;top: 0px;bottom: 0px;left: 0px;right: 0px;" onclick="onClick(this)" href="javascript:void(0);"  class="' + iconClassName + '"></a>';

                    var tr_start = '<tr>';
                    var td = '<td style="position: relative">' + icon + '</td>';
                    var tr_end = '</tr>';

                    var cols = 10;

                    if (i % cols == 0) {
                        content += tr_start;
                    }
                    content += td;
                    if ((i + 1) % cols == 0 || i == list_icon.length - 1) {
                        content += tr_end;
                    }

                });
                tbody.append(content);
            }
        });
    }

    showCustomDialog($("#dialog-icon-select"), "选择图标", true, function () {
        var imgClass = $(".img-selected").prop('class').split(" ")[0];
        $("input[name='icon']", getParentUntil(ele, "form")).val(imgClass);
    }, function () {
        $(".img-selected").removeClass("img-selected");
    });
}

/**
 *  打开删除窗口<br/>
 */
function openDeleteDialog() {
    var item = $('#grid').treegrid('getSelected');
    if (item == null) {
        $.messager.warning("请选择要删除的菜单项~");
        return;
    }

    showDialog("删除菜单", "确定删除?", function () {
        remove(item);
    });
}

/**
 *  添加记录<br/>
 */
function add() {
    //校验表单
    var validate = validateForm($("#form-add"));
    if (!validate) {
        $.messager.warning("请正确填写相关信息~");
        return false;
    }

    //校验combobox
    var validateParentId = validateCombobox($("#form-add .easyui-combobox"), "父级菜单无效~");
    if (!validateParentId) {
        return false;
    }

    //校验icon
    var iconClass = $("#form-add input[name='icon']").val();
    var validateIcon = iconClass.length > 0 ? $("." + iconClass).length > 0 : false;
    if (!validateIcon) {
        $.messager.warning("图标无效~");
        return false;
    }

    var data = $("#form-add").serialize(); //www-form格式:k1=v1&k2=v2
    $.post({
        url: '../menu/add',
        data: data,
        success: function (data) {
            $.messager.info('添加成功~');
            queryForAll();
        }
    });
    return true;
}

/**
 *  添加三级菜单<br/>
 */
function addBtn() {
    //校验表单
    var validate = validateForm($("#form-add-btn"));
    if (!validate) {
        $.messager.warning("请正确填写相关信息~");
        return false;
    }

    //校验icon
    var iconClass = $("#form-add-btn input[name='icon']").val();
    var validateIcon = iconClass.length > 0 ? $("." + iconClass).length > 0 : false;
    if (!validateIcon) {
        $.messager.warning("图标无效~");
        return false;
    }

    var data = $("#form-add-btn").serialize(); //www-form格式:k1=v1&k2=v2
    $.post({
        url: '../menu/addBtn',
        data: data,
        success: function (data) {
            $.messager.info('添加成功~');
            queryForAll();
        }
    });
    return true;
}

/**
 *  修改记录<br/>
 */
function edit() {
    //校验表单
    var validate = validateForm($("#form-edit"));
    if (!validate) {
        $.messager.warning("请正确填写相关信息~");
        return false;
    }

    //校验combobox (设定规则:编辑下,不可变更父子关系,后端不校验关系变更,前端防控)
    var id = $("#form-edit input[type='hidden']").val();
    var parentId = $("#form-edit .easyui-combobox").combobox('getValue');
    if (id == parentId) {
        $.messager.warning("父级菜单不能指定为自身~");
        return false;
    }
    var validateParentId = validateCombobox($("#form-edit .easyui-combobox"), "父级菜单无效~");
    if (!validateParentId) {
        return false;
    }

    //校验icon
    var iconClass = $("#form-edit input[name='icon']").val();
    var validateIcon = iconClass.length > 0 ? $("." + iconClass).length > 0 : false;
    if (!validateIcon) {
        $.messager.warning("图标无效~");
        return false;
    }

    var data = $("#form-edit").serialize(); //www-form格式:k1=v1&k2=v2
    $.post({
        url: '../menu/edit',
        data: data,
        success: function (data) {
            $.messager.info('修改成功~');
            queryForAll();
        }
    });
    return true;
}

/**
 *  修改三级菜单<br/>
 */
function editBtn() {
    //校验表单
    var validate = validateForm($("#form-edit-btn"));
    if (!validate) {
        $.messager.warning("请正确填写相关信息~");
        return false;
    }

    //校验icon
    var iconClass = $("#form-edit-btn input[name='icon']").val();
    var validateIcon = iconClass.length > 0 ? $("." + iconClass).length > 0 : false;
    if (!validateIcon) {
        $.messager.warning("图标无效~");
        return false;
    }

    var data = $("#form-edit-btn").serialize(); //www-form格式:k1=v1&k2=v2
    $.post({
        url: '../menu/editBtn',
        data: data,
        success: function (data) {
            $.messager.info('修改成功~');
            queryForAll();
        }
    });
    return true;
}

/**
 *  删除记录<br/>
 */
function remove(item) {
    $.post({
        url: '../menu/delete',
        data: {
            id: item.id
        },
        success: function (data) {
            $.messager.info('删除成功~');
            queryForAll();
        }
    });
}

/**
 * 查询<br/>
 */
function queryForAll() {
    $("#grid").treegrid('load', {
        keyword: ""
    });

    $("#dialog-add .easyui-combobox").combobox('reload');
    //设定规则:编辑下,不可变更父子关系
    // $("#dialog-edit .easyui-combobox").combobox('reload');
}

/**
 * 搜索(不支持二级搜索,因为_parentId有效,但无parent返回,如何显示一二级与如何返回一二级结构会比较尴尬,且需兼容非搜索)<br/>
 */
function queryForSearchText() {
    $("#grid").treegrid('load', {
        keyword: $("#input-search").val()
    });
}

/**
 * 按键监听<br/>
 */
function onkeyUp(event) {
    if (event.key == "Enter") {
        queryForSearchText();
    }
}

#### 菜单列表后端:

package com.qlslylq.javadesign.controller;

import com.qlslylq.javadesign.enums.ErrorEnum;
import com.qlslylq.javadesign.mapper.service.MenuService;
import com.qlslylq.javadesign.model.Menu;
import com.qlslylq.javadesign.model.request.MenuEditReq;
import com.qlslylq.javadesign.pojo.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description 菜单控制器
 * @Author https://gitee.com/qlslylq/UnityDesign
 * @link https://gitee.com/qlslylq/FlutterDesign
 * @link https://gitee.com/qlslylq/AndroidDesign
 **/
@Controller
@RequestMapping(value = "/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    /**
     * 菜单列表页<br/>
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ModelAndView list(ModelAndView mv) {
        mv.setViewName("menu/list");
        return mv;
    }

    /**
     * 一级菜单列表页<br/>
     */
    @RequestMapping(value = "/getTopList", method = RequestMethod.POST)
    @ResponseBody
    public List<Menu> getTopList() {
        List<Menu> list = menuService.getTopList();
        Menu item = new Menu();
        item.setId(0L);
        item.set_parentId(0L);
        item.setName("顶级菜单");
        list.add(0, item);
        return list;
    }

    /**
     * 获取菜单详情<br/>
     */
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> get(long id) {
        Menu item = menuService.get(id);
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("code", ErrorEnum.ERR_0.getId());
        map.put("msg", "");
        map.put("data", item);
        return map;
    }

    /**
     * 获取图标资源集<br/>
     */
    @RequestMapping(value = "/getIconList", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> getIconList(HttpServletRequest servletRequest) {
        Map<String, Object> map = new LinkedHashMap<>();

        String root_path = servletRequest.getServletContext().getRealPath("/");
        File file = new File(root_path + "resources/easyui/css/icons");
        if (!file.exists()) {
            map.put("code", ErrorEnum.ERR_403.getId());
            map.put("msg", "文件夹不存在~");
            return map;
        }
        File[] files = file.listFiles();
        List<String> data = new ArrayList<>();
        for (File item : files) {
            if (item.getName().contains(".png")) {
                data.add(item.getName());
            }
        }

        map.put("code", ErrorEnum.ERR_0.getId());
        map.put("msg", "");
        map.put("data", data);
        return map;
    }

    /**
     * 添加一二级菜单<br/>
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> add(MenuEditReq menu) {
        Map<String, Object> map = new LinkedHashMap<>();

        if (menu.getParentId() == null || (menu.getParentId() != null && menu.getParentId() < 0)) {
            menu.setParentId(0L);
        }

        //确认parentId有效性
        if (menu.getParentId() != null && menu.getParentId() != 0) {
            List<Menu> list_top = menuService.getTopList();
            boolean validateParentId = false;
            for (Menu item : list_top) {
                if (item.getId().equals(menu.getParentId())) {
                    validateParentId = true;
                    break;
                }
            }
            if (!validateParentId) {
                map.put("code", ErrorEnum.ERR_404.getId());
                map.put("msg", "父级菜单不存在~");
                return map;
            }
        }

        if (StringUtils.isEmpty(menu.getName()) || StringUtils.isEmpty(menu.getIcon()) || StringUtils.isEmpty(menu.getLink())) {
            map.put("code", ErrorEnum.ERR_405.getId());
            map.put("msg", ErrorEnum.ERR_405.getName());
            return map;
        }

        int code = menuService.add(menu);
        map.put("code", code > 0 ? ErrorEnum.ERR_0.getId() : ErrorEnum.ERR_501.getId());
        map.put("msg", code > 0 ? "" : ErrorEnum.ERR_501.getName());
        return map;
    }

    /**
     * 添加按钮(三级菜单)<br/>
     */
    @RequestMapping(value = "/addBtn", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> addBtn(MenuEditReq menu) {
        Map<String, Object> map = new LinkedHashMap<>();

        if (menu.getParentId() == null || (menu.getParentId() != null && menu.getParentId() <= 0)) {
            map.put("code", ErrorEnum.ERR_404.getId());
            map.put("msg", "父级菜单不存在~");
            return map;
        }

        //确认parentId有效性
        if (menu.getParentId() != null && menu.getParentId() != 0) {
            List<Menu> list_top = menuService.getTopList();
            boolean validateParentId = false;
            for (Menu item : list_top) {
                List<Menu> list_children = menuService.getChildrenList(item.getId());
                for (Menu item_child : list_children) {
                    if (item_child.getId().equals(menu.getParentId())) {
                        validateParentId = true;
                        break;
                    }
                }
                if (validateParentId) {
                    break;
                }
            }
            if (!validateParentId) {
                map.put("code", ErrorEnum.ERR_404.getId());
                map.put("msg", "父级菜单不存在~");
                return map;
            }
        }

        if (StringUtils.isEmpty(menu.getName()) || StringUtils.isEmpty(menu.getIcon()) || StringUtils.isEmpty(menu.getLink())) {
            map.put("code", ErrorEnum.ERR_405.getId());
            map.put("msg", ErrorEnum.ERR_405.getName());
            return map;
        }

        int code = menuService.add(menu);
        map.put("code", code > 0 ? ErrorEnum.ERR_0.getId() : ErrorEnum.ERR_501.getId());
        map.put("msg", code > 0 ? "" : ErrorEnum.ERR_501.getName());
        return map;
    }

    /**
     * 修改一二级菜单<br/>
     * 一级菜单可变更为二级菜单,二级菜单不能变更为一级菜单<br/>
     * 设定规则:编辑下,不可变更父子关系,后端不校验关系变更,前端防控<br/>
     */
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> edit(MenuEditReq menu) {
        Map<String, Object> map = new LinkedHashMap<>();

        if (menu.getParentId() == null || (menu.getParentId() != null && menu.getParentId() < 0)) {
            menu.setParentId(0L);
        }

        if (menu.getId().equals(menu.getParentId())) {
            map.put("code", ErrorEnum.ERR_404.getId());
            map.put("msg", "父级菜单不能指定为自身~");
            return map;
        }

        //确认parentId有效性
        if (menu.getParentId() != null && menu.getParentId() != 0) {
            List<Menu> list_top = menuService.getTopList();
            boolean validateParentId = false;
            for (Menu item : list_top) {
                if (item.getId().equals(menu.getParentId())) {
                    validateParentId = true;
                    break;
                }
            }
            if (!validateParentId) {
                map.put("code", ErrorEnum.ERR_404.getId());
                map.put("msg", "父级菜单不存在~");
                return map;
            }
        }

        if (StringUtils.isEmpty(menu.getName()) || StringUtils.isEmpty(menu.getIcon()) || StringUtils.isEmpty(menu.getLink())) {
            map.put("code", ErrorEnum.ERR_405.getId());
            map.put("msg", ErrorEnum.ERR_405.getName());
            return map;
        }

        int code = menuService.edit(menu);
        map.put("code", code > 0 ? ErrorEnum.ERR_0.getId() : ErrorEnum.ERR_501.getId());
        map.put("msg", code > 0 ? "" : ErrorEnum.ERR_501.getName());
        return map;
    }

    /**
     * 修改三级菜单<br/>
     * 一级菜单可变更为二级菜单,二级菜单不能变更为一级菜单<br/>
     */
    @RequestMapping(value = "/editBtn", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> editBtn(MenuEditReq menu) {
        Map<String, Object> map = new LinkedHashMap<>();

        if (menu.getParentId() == null || (menu.getParentId() != null && menu.getParentId() < 0)) {
            menu.setParentId(0L);
        }

        if (menu.getId().equals(menu.getParentId())) {
            map.put("code", ErrorEnum.ERR_404.getId());
            map.put("msg", "父级菜单不能指定为自身~");
            return map;
        }

        //确认parentId有效性
        if (menu.getParentId() != null && menu.getParentId() != 0) {
            List<Menu> list_top = menuService.getTopList();
            boolean validateParentId = false;
            for (Menu item : list_top) {
                List<Menu> list_children = menuService.getChildrenList(item.getId());
                for (Menu item_child : list_children) {
                    if (item_child.getId().equals(menu.getParentId())) {
                        validateParentId = true;
                        break;
                    }
                }
                if (validateParentId) {
                    break;
                }
            }
            if (!validateParentId) {
                map.put("code", ErrorEnum.ERR_404.getId());
                map.put("msg", "父级菜单不存在~");
                return map;
            }
        }

        if (StringUtils.isEmpty(menu.getName()) || StringUtils.isEmpty(menu.getIcon()) || StringUtils.isEmpty(menu.getLink())) {
            map.put("code", ErrorEnum.ERR_405.getId());
            map.put("msg", ErrorEnum.ERR_405.getName());
            return map;
        }

        int code = menuService.edit(menu);
        map.put("code", code > 0 ? ErrorEnum.ERR_0.getId() : ErrorEnum.ERR_501.getId());
        map.put("msg", code > 0 ? "" : ErrorEnum.ERR_501.getName());
        return map;
    }

    /**
     * 删除菜单<br/>
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> delete(long id) {
        Map<String, Object> map = new LinkedHashMap<>();

        if (menuService.getChildrenList(id).size() > 0) {
            map.put("code", ErrorEnum.ERR_404.getId());
            map.put("msg", "请先删除该菜单下的所有子菜单~");
            return map;
        }
        int code = 0;
        try {
            code = menuService.delete(id);
        } catch (Exception e) {
            map.put("code", ErrorEnum.ERR_404.getId());
            map.put("msg", "请先删除关联该菜单的所有权限~");
            return map;
        }
        map.put("code", code > 0 ? ErrorEnum.ERR_0.getId() : ErrorEnum.ERR_502.getId());
        map.put("msg", code > 0 ? "" : ErrorEnum.ERR_502.getName());
        return map;
    }

    /**
     * 查询及搜索菜单<br/>
     */
    @RequestMapping(value = "/getList", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> getList(Pager pager, @RequestParam(value = "keyword", required = false, defaultValue = "") String keyword) {
        Map<String, Object> map = new LinkedHashMap<>();
        Map<String, Object> data = new LinkedHashMap<>();

        List<Menu> list = menuService.getList(pager, keyword);
        map.put("code", ErrorEnum.ERR_0.getId());
        map.put("msg", "");
        data.put("total", menuService.getTotalCount(keyword));
        data.put("rows", list);
        map.put("data", data);
        return map;
    }

}



#### 远端多字段排序

    /**
     * 查询及搜索用户<br/>
     */
    @RequestMapping(value = "/getList", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> getList(Pager pager, @RequestParam(value = "keyword", required = false, defaultValue = "") String keyword,
                                       @RequestParam(value = "roleId", required = false, defaultValue = "-1") long roleId,
                                       @RequestParam(value = "sex", required = false, defaultValue = "-1") int sex, SortOrder sortOrder) {
        Map<String, Object> map = new LinkedHashMap<>();
        Map<String, Object> data = new LinkedHashMap<>();

        sortOrder.setSortSql();

        List<User> list = userService.getList(pager, keyword, roleId, sex, sortOrder);
        map.put("code", ErrorEnum.ERR_0.getId());
        map.put("msg", "");
        data.put("total", userService.getTotalCount(keyword, roleId, sex));
        data.put("rows", list);
        map.put("data", data);
        return map;
    }

Comments ( 0 )

Sign in for post a comment

About

JavaSSM后台管理系统基础框架。以JSP前后端不分离方式搭建,jQueryEasyUI作为前端展示,SSM提供后台服务。 框架基本功能:菜单管理,角色管理,权限管理,用户管理,日志管理。 spread retract
Java
LGPL-3.0
Cancel

Releases

No release

Contributors

All

Activities

load more
can not load any more
Java
1
https://gitee.com/qlslylq/JavaDesign.git
git@gitee.com:qlslylq/JavaDesign.git
qlslylq
JavaDesign
JavaDesign
master

Search