SpringBoot打造企业级进销存储系统 第五讲

package com.java1234.repository;import com.java1234.entity.Menu;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;import java.util.List;/*** 菜单=Repository接口*/
public interface MenuRepository extends JpaRepository<Menu,Integer> {/*** 根据父节点以及用户角色id查询子节点* @param parentId* @param roleId* @return*/@Query(value = "SELECT * FROM t_menu WHERE p_id=?1 AND id IN (SELECT menu_id FROM t_role_menu WHERE role_id=?2)",nativeQuery = true)public List<Menu> findByParentIdAndRoleId(int parentId,int roleId);
}
package com.java1234.service;import com.java1234.entity.Menu;import java.util.List;/*** 权限菜单Service接口*/
public interface MenuService {/*** 根据父节点以及用户角色id查询子节点* @param parentId* @param roleId* @return*/public List<Menu> findByParentIdAndRoleId(int parentId, int roleId);
}
package com.java1234.service.impl;import com.java1234.entity.Menu;
import com.java1234.repository.MenuRepository;
import com.java1234.service.MenuService;
import org.springframework.stereotype.Service;import javax.annotation.Resource;
import java.util.List;/*** 权限菜单Service实现类*/
@Service("menuService")
public class MenuServiceImpl implements MenuService {@Resourceprivate MenuRepository menuRepository;@Overridepublic List<Menu> findByParentIdAndRoleId(int parentId, int roleId) {return menuRepository.findByParentIdAndRoleId(parentId,roleId);}
}
package com.java1234.controller;import java.util.HashMap;
import java.util.List;
import java.util.Map;import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.java1234.entity.Menu;
import com.java1234.service.MenuService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;import com.java1234.entity.Role;
import com.java1234.entity.User;
import com.java1234.service.RoleService;
import com.java1234.service.UserService;
import com.java1234.util.StringUtil;/*** 用户Controller* @author Administrator**/
@Controller
@RequestMapping("/user")
public class UserController {@Resourceprivate UserService userService;@Resourceprivate RoleService roleService;@Resourceprivate MenuService menuService;/*** 用户登录判断* @param imageCode* @param user* @param bindingResult* @param session* @return*/@ResponseBody@RequestMapping("/login")public Map<String,Object> login(String imageCode,@Valid User user,BindingResult bindingResult,HttpSession session){Map<String,Object> map=new HashMap<String,Object>();if(StringUtil.isEmpty(imageCode)){map.put("success", false);map.put("errorInfo", "请输入验证码!");return map;}if(!session.getAttribute("checkcode").equals(imageCode)){map.put("success", false);map.put("errorInfo", "验证码输入错误!");return map;}if(bindingResult.hasErrors()){map.put("success", false);map.put("errorInfo", bindingResult.getFieldError().getDefaultMessage());return map;}Subject subject=SecurityUtils.getSubject();UsernamePasswordToken token=new UsernamePasswordToken(user.getUserName(), user.getPassword());try{subject.login(token);String userName=(String) SecurityUtils.getSubject().getPrincipal();User currentUser=userService.findByUserName(userName);session.setAttribute("currentUser", currentUser);List<Role> roleList=roleService.findByUserId(currentUser.getId());map.put("roleList", roleList);map.put("roleSize", roleList.size());map.put("success", true);return map;}catch(Exception e){e.printStackTrace();map.put("success", false);map.put("errorInfo", "用户名或者密码错误!");return map;}}/*** 保存角色信息* @param roleId* @param session* @return* @throws Exception*/@ResponseBody@RequestMapping("/saveRole")public Map<String,Object> saveRole(Integer roleId,HttpSession session)throws Exception{Map<String,Object> map=new HashMap<String,Object>();Role currentRole=roleService.findById(roleId);session.setAttribute("currentRole", currentRole);map.put("success", true);return map;}/*** 加载当前用户信息* @param session* @return* @throws Exception*/@ResponseBody@GetMapping("/loadUserInfo")public String loadUserInfo(HttpSession session)throws Exception{User currentUser=(User) session.getAttribute("currentUser");Role currentRole=(Role) session.getAttribute("currentRole");return "欢迎您:"+currentUser.getTrueName()+"&nbsp;[&nbsp;"+currentRole.getName()+"&nbsp;]";}/*** 加载权限菜单* @param session* @param parentId* @return* @throws Exception*/@ResponseBody@PostMapping("/loadMenuInfo")public String loadMenuInfo(HttpSession session,Integer parentId)throws Exception{Role currentRole=(Role) session.getAttribute("currentRole");return getAllMenuByParentId(parentId,currentRole.getId()).toString();}/*** 获取所有菜单信息* @param parentId* @param roleId* @return*/public JsonArray getAllMenuByParentId(Integer parentId,Integer roleId){JsonArray jsonArray=this.getMenuByParentId(parentId, roleId);for(int i=0;i<jsonArray.size();i++){JsonObject jsonObject=(JsonObject) jsonArray.get(i);if("open".equals(jsonObject.get("state").getAsString())){continue;}else{jsonObject.add("children", getAllMenuByParentId(jsonObject.get("id").getAsInt(), roleId));}}return jsonArray;}/*** 根据父节点和用户角色Id查询菜单* @param parentId* @param roleId* @return*/public JsonArray getMenuByParentId(Integer parentId,Integer roleId){List<Menu> menuList=menuService.findByParentIdAndRoleId(parentId, roleId);JsonArray jsonArray=new JsonArray();for(Menu menu:menuList){JsonObject jsonObject=new JsonObject();jsonObject.addProperty("id", menu.getId()); // 节点IdjsonObject.addProperty("text", menu.getName()); // 节点名称if(menu.getState()==1){jsonObject.addProperty("state", "closed"); // 根节点}else{jsonObject.addProperty("state", "open"); // 叶子节点}jsonObject.addProperty("iconCls", menu.getIcon()); // 节点图标JsonObject attributeObject=new JsonObject(); // 扩展属性attributeObject.addProperty("url", menu.getUrl()); // 菜单请求地址jsonObject.add("attributes", attributeObject);jsonArray.add(jsonObject);}return jsonArray;}
}

在这里插入图片描述

$("#tree").tree({lines:true,url:'/user/loadMenuInfo?parentId=-1',onLoadSuccess:function(){$("#tree").tree("expandAll");}});
    <ul id="tree" class="easyui-tree" style="padding: 10px"></ul>
<!DOCTYPE html>
<html>
<head><meta charset="UTF-8"><title>后台管理-进销存管理系统</title><link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.3.3/themes/default/easyui.css"></link><link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.3.3/themes/icon.css"></link><style type="text/css">.clock {float:right;width: 300px;height: 30px;padding-left: 20px;color: rgb(0, 76, 126);background: url(/static/images/clock.gif) no-repeat;font-size: 14px;}.userInfo{float:left;padding-left: 20px;padding-top: 30px;}</style><script type="text/javascript" src="/static/jquery-easyui-1.3.3/jquery.min.js"></script><script type="text/javascript" src="/static/jquery-easyui-1.3.3/jquery.easyui.min.js"></script><script type="text/javascript" src="/static/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script><script type="text/javascript">function showTime(){var date = new Date();this.year = date.getFullYear();this.month = date.getMonth() + 1;this.date = date.getDate();this.day = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")[date.getDay()];this.hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();this.minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();this.second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();$("#clock").text("现在是:" + this.year + "年" + this.month + "月" + this.date + "日 " + this.hour + ":" + this.minute + ":" + this.second + " " + this.day);}$(document).ready(function() {window.setInterval("showTime()",1000);$("#userInfo").load("/user/loadUserInfo"); // 加载用户信息$("#tree").tree({lines:true,url:'/user/loadMenuInfo?parentId=-1',onLoadSuccess:function(){$("#tree").tree("expandAll");}});});</script>
</head>
<body class="easyui-layout">
<div region="north" style="height: 72px;"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="381px" style="background:url(/static/images/top_left.jpg)"></td><td style="background:url(/static/images/top_center.jpg)"><div id="userInfo" class="userInfo"></div></td><td valign="bottom" width="544px" style="background:url(/static/images/top_right.jpg)"><div id="clock" class="clock"></div></td></tr></table>
</div><div region="center">
</div><div region="west" style="width: 200px" title="导航菜单" split="true" iconCls="icon-navigation"><ul id="tree" class="easyui-tree" style="padding: 10px"></ul></div><div region="south" style="height: 30px;padding: 5px" align="center">Copyright © 2012-2017 南通小锋网络科技有限公司  版权所有
</div></body>
</html>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/749518.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

第二百零五回

文章目录 概念介绍响应方法滑动事件点击事件 经验总结 我们在上一章回中介绍了如何给ListView添加分隔线,本章回中将介绍ListView响应事件相关的知识.闲话休提&#xff0c;让我们一起Talk Flutter吧。 概念介绍 我们在这里说的ListView响应事件主要分两种类型&#xff0c;一种…

【深度学习模型移植】用torch普通算子组合替代torch.einsum方法

首先不得不佩服大模型的强大之处&#xff0c;在算法移植过程中遇到einsum算子在ONNX中不支持&#xff0c;因此需要使用普通算子替代。参考TensorRT - 使用torch普通算子组合替代torch.einsum爱因斯坦求和约定算子的一般性方法。可以写出简单的替换方法&#xff0c;但是该方法会…

【Flask开发实战】项目介绍-防火墙规则查询系统

一、前言 硬件防火墙为常备主用网络安全设备&#xff0c;主要通过网络访问控制方式实现安全防护。 不同厂家防火墙的网络访问控制功能均采用同样的模式操作&#xff1a;防火墙配置若干条防火墙规则&#xff0c;当IP包到来&#xff0c;防火墙根据包的五元组属性&#xff08;协…

Python学习笔记之math库的使用

一、平方&#xff0c;m的n次方 math.pow(x, y)是返回x的y次幂 语法 import matha math.pow(3, 2)print(3的2次方, a)# 输出结果为3的2次幂&#xff0c;为9二、开平方 math.sqrt(x)返回x的算术平方根 语法 import mathb 100print(math.sqrt(b)) # 输出结果为10 三、弧度制与…

突破编程_前端_JS编程实例(工具栏组件)

1 开发目标 工具栏组件旨在模拟常见的桌面软件工具栏&#xff0c;所以比较适用于 electron 的开发&#xff0c;该组件包含工具栏按钮、工具栏分割条和工具栏容器三个主要角色&#xff0c;并提供一系列接口和功能&#xff0c;以满足用户在不同场景下的需求&#xff1a; 点击工具…

【MatLab】之:Simulink安装

一、内容简介 本文介绍如何在 MatLab 中安装 Simulink 仿真工具包。 二、所需原材料 MatLab R2020b&#xff08;教学使用&#xff09; 三、安装步骤 1. 点击菜单中的“附加功能”&#xff0c;进入附加功能管理器&#xff1a; 2. 在左侧的“按类别筛选”下选择Using Simulin…

Linux网络编程: IP协议详解

一、TCP/IP五层模型 物理层&#xff08;Physical Layer&#xff09;&#xff1a;物理层是最底层&#xff0c;负责传输比特流&#xff08;bitstream&#xff09;以及物理介质的传输方式。它定义了如何在物理媒介上传输原始的比特流&#xff0c;例如通过电缆、光纤或无线传输等。…

购票小程序有哪些功能

​通过小程序购买电子票&#xff0c;然后在使用时&#xff0c;出示电子票二维码&#xff0c;由商家进行验证/核销。通过小程序购票和核销&#xff0c;使得整个流程非常顺利&#xff0c;免去了线下购票的繁琐&#xff0c;而且还容易遗失。下面我们就来具体看一下小程序如何进行购…

3月16日,每日信息差

&#x1f396; 素材来源官方媒体/网络新闻 &#x1f384; 广汽传祺官宣加入华为鸿蒙生态 &#x1f30d; 国家数据局&#xff1a;加快构建全国一体化算力网 推动建设中国式现代化数字基座 &#x1f30b; 中国首个超深气田累产天然气突破800亿立方米 &#x1f381; 东方甄选客服回…

Postman进行Websocket接口测试

Postman进行Websocket接口测试 前言下载地址使用1、new一个一个WebSocket Request2、填写内容和需要请求头携带的参数3、表示成功 网页请求101表示握手成功 前言 有些较低版本postman不支持websocket接口测试&#xff0c;如果根据此文未找到创建websocket接口测试的目录&#…

c语言:于龙加

于龙加 任务描述 于龙同学设计了一个特别的加法规则&#xff0c;加法被重新定义了&#xff0c;我们称为于龙加。 两个非负整数的于龙加的意义是将两个整数按前后顺序连接合并形成一个新整数。 于龙想编程解决于龙加问题&#xff0c;可是对下面的程序他没有思路&#xff01; …

面向对象(C# )

面向对象&#xff08;C# &#xff09; 文章目录 面向对象&#xff08;C# &#xff09;ref 和 out传值调用和引用调用ref 和 out 的使用ref 和 out 的区别 结构体垃圾回收GC封装成员属性索引器静态成员静态类静态构造函数拓展方法运算符重载内部类和分布类 继承里氏替换继承中的…

Qt 鼠标滚轮示例

1.声明 void wheelEvent(QWheelEvent *event) override;2.实现&#xff08;方便复制、测试起见用静态变量&#xff09; #include <mutex> void MainWindow::wheelEvent(QWheelEvent *event) {static QLabel *label new QLabel("Zoom Level: 100%", this);st…

elementUi中表格超出一行省略,鼠标放入显示完整提示

一、想要的效果 二、代码&#xff0c;加入show-overflow-tooltip即可 <el-table-column min-width"220" prop"content" show-overflow-tooltip> </el-table-column>

在Windows电脑上跑linux用双系统、虚拟机还是WSL?

文章目录 1. Main2. 总结Reference 1. Main 在windows上升级Docker desktop, 升级完之后提示支持WSL。WSL是指windows subsystem for linux, 那么它和虚拟机上的linux有什么区别和优劣势呢&#xff1f; 在没有虚拟化技术出现之前&#xff0c;如果用户想在同一台电脑上使用lin…

PCB设计中的MARKER

今天在给板子布局的时候发现了一个这样的东西&#xff0c;名叫MARKER&#xff0c;查了一下这个东西分享一下&#xff1a; 目录 MARKER是什么样的&#xff1f; MARKER的用途&#xff1a; MARKER是必须的吗&#xff1f; MARKER是什么样的&#xff1f; 他在PCB中是这样的&…

记一下mysql安装过程中遇到的报错解决

执行mysql8.0.34安装过程中的&#xff1a;bin/mysqld --initialize --usermysql 步骤时报错。 报错1&#xff1a;bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory 解决&#xff1a; centos&…

web 课程

文章目录 格式图片超链接书签链接表格例子横跨束跨 格式 <br /> <br/> #换行图片 <img> 标签是用于在网页中嵌入图像的 HTML 标签&#xff0c;它有一些属性可以用来控制图像的加载、显示和交互。以下是对 <img> 标签常用属性的详细介绍&#xff1a;…

MySQL基础架构

文章目录 MySQL基础架构一、连接器 - 建立连接&#xff0c;权限认证二、查缓存 - 提高效率三、分析器 - 做什么四、优化器 - 怎么做五、执行器 - 执行语句六、存储引擎1、存储引擎的概述2、存储引擎的对比3、存储引擎的命令4、存储引擎的选择 MySQL基础架构 大体来说&#xff…

旅游管理系统 |基于springboot框架+ Mysql+Java+Tomcat的旅游管理系统设计与实现(可运行源码+数据库+设计文档)

推荐阅读100套最新项目 最新ssmjava项目文档视频演示可运行源码分享 最新jspjava项目文档视频演示可运行源码分享 最新Spring Boot项目文档视频演示可运行源码分享 目录 前台功能效果图 管理员功能登录前台功能效果图 系统功能设计 数据库E-R图设计 lunwen参考 摘要 研究…