基於SSM框架的JavaWeb通用許可權管理系統

longmanma發表於2021-09-09

檢視更多系統:

01 概述

這是一個通用許可權管理系統專案,基於SSM(Spring + Spring-MVC +Mybatis)框架開發,其SQL語句持久在Hibernate 中,對原生SQL的支援較好。製作該系統的初衷是用來幫助JavaWeb開發者或初學者學習、借鑑的需要。讀者可以在這個 系統基礎上引入其它技術或完全依賴本系統技術進行功能擴充,來開發實際應用需求的專案,免去了應用系統中對於“ 許可權設計”這一部分的麻煩。

02 技術

> Jsp 、SSM(Spring + Spring-MVC + Mybatis)、Shiro 、Mvc、Jdbc、MySQL、DWZ富客戶端框架 + Jquery + Ajax

03 環境

> JDK:JDK1.6+ 、WEB:Tomcat6.0+ 、DB:MySQL5+ 、IDE: MyEclipse8.5+/Eclipse4.4+

04 工程結構

圖片描述

05 執行截圖

登入介面

圖片描述

員工管理介面

圖片描述

部門管理介面

圖片描述

角色管理介面

圖片描述

06 主要程式碼

員工部門管理

package com.kzfire.portal.action.user;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.kzfire.portal.base.BaseAction;
import com.kzfire.portal.entiy.SysDept;
import com.kzfire.portal.service.DeptService;
import com.kzfire.portal.service.UserService;
import com.kzfire.portal.utils.JSONUtils;
import com.kzfire.portal.utils.VoFactory;
import com.kzfire.portal.vo.ConditionVo;

@RequestMapping("/user/dept")
@Controller
public class DeptAction extends BaseAction{
	@Autowired
	DeptService deptService;
	@Autowired
	UserService userService;
	
	/**
	 * 設定員工部門
	 * @param model
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/setUserDept")
	public String setUserDept(Model model,HttpServletRequest request,HttpServletResponse response) {
		
		String userId=request.getParameter("userId");
		model.addAttribute("userId", userId);
		//設定部門樹
		List list=deptService.getAllDept();
		model.addAttribute("data", JSONUtils.parseList(list));
		return VIEW+"user/dept/setUserDept";
	}
	
	@RequestMapping("/saveUserdept")
	public ModelAndView saveUserdept(Model model, HttpServletRequest request,
			HttpServletResponse response) {
		try {
			Integer userId=Integer.parseInt(request.getParameter("userId"));
			Integer deptId=Integer.parseInt(request.getParameter("deptId"));
			deptService.saveUserdept(userId,deptId);
		} catch (Exception e) {
			e.printStackTrace();
			return ajaxDoneError("操作失敗:"+e.getMessage());
		}
		return ajaxDoneSuccess("操作成功");
	}
	
	@RequestMapping("/main")
	public String list(Model model,HttpServletRequest request,HttpServletResponse response) {
		//設定部門樹
		List list=deptService.getAllDept();
		System.out.println("json格式----->"    + JSONUtils.parseList(list).toString() );
		model.addAttribute("data", JSONUtils.parseList(list));
		return VIEW+"user/dept/dept";
	}
	
	@RequestMapping("/userList")
	public String userList(Model model,HttpServletRequest request,HttpServletResponse response) {
		ConditionVo cvo=VoFactory.getConditionVo(request);
		String deptId=request.getParameter("deptId");
		if("1".equals(deptId))
		{
			cvo.setText4("1");
		}else
		{
			cvo.setText3(request.getParameter("deptId"));
		}
		request.setAttribute("deptId", deptId);
		cvo.setTotalCount(userService.getUserCount(cvo));
		model.addAttribute("vo", cvo);
		model.addAttribute("list", userService.getList(cvo));
		return VIEW+"user/dept/userList";
	}
	
	@RequestMapping("/add")
	public String add(Model model,HttpServletRequest request,HttpServletResponse response) {
		SysDept dept=new SysDept();
		dept.setPid(Integer.parseInt(request.getParameter("selDept")));
		model.addAttribute("dept", dept);
		return VIEW+"user/dept/deptEdit";
	}
	@RequestMapping("/edit")
	public String edit(Model model,HttpServletRequest request,HttpServletResponse response) {
		SysDept dept=deptService.getDeptById(Integer.parseInt(request.getParameter("selDept")));
		model.addAttribute("dept", dept);
		return VIEW+"user/dept/deptEdit";
	}
	
	@RequestMapping("/del")
	public ModelAndView del(Model model, HttpServletRequest request)
	{
		try {
			String deptId=request.getParameter("selDept");
			deptService.delDeptById(Integer.parseInt(deptId));
		} catch (Exception e) {
			e.printStackTrace();
			return ajaxDoneError("操作失敗:"+e.getMessage());
		}
		return ajaxDoneSuccess("操作成功");
	}
	
	@RequestMapping("/save")
	public ModelAndView save(SysDept dept,Model model, HttpServletRequest request,
			HttpServletResponse response) {
		try {
			if(dept!=null)
			{
				deptService.saveDept(dept);
			}
		} catch (Exception e) {
			e.printStackTrace();
			return ajaxDoneError("操作失敗:"+e.getMessage());
		}
		return ajaxDoneSuccess("操作成功");
	}
}

角色管理

package com.kzfire.portal.action.user;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.kzfire.portal.base.BaseAction;
import com.kzfire.portal.entiy.SysRole;
import com.kzfire.portal.service.RoleService;
import com.kzfire.portal.utils.VoFactory;
import com.kzfire.portal.vo.ConditionVo;
import com.kzfire.portal.vo.PerGroupVo;

@RequestMapping("/user/role")
@Controller
public class RoleAction extends BaseAction{
	@Autowired
	RoleService roleService;
	
	@RequestMapping("/list")
	public String list(Model model,HttpServletRequest request,HttpServletResponse response) {
		ConditionVo cvo=VoFactory.getConditionVo(request);
		cvo.setTotalCount(roleService.getTableCount("sys_role"));
		model.addAttribute("vo", cvo);
		model.addAttribute("list", roleService.getList(cvo));
		return VIEW+"permission/role/list";
	}
	
	/**
	 * 許可權編輯頁面
	 * @param model
	 * @param request
	 * @return
	 */
	@RequestMapping("/editPermission")
	public String editPermission(Model model, HttpServletRequest request)
	{
		String roleId=request.getParameter("roleId");
		//獲取角色許可權
		List group=roleService.getPerGroupVoByUserId(Integer.parseInt(roleId));
		model.addAttribute("group", group);
		model.addAttribute("roleId", roleId);
		return VIEW+"permission/role/editPermission";
	}
	
	@RequestMapping("/savePer")
	public ModelAndView savePer(Model model, HttpServletRequest request,
			HttpServletResponse response) {
		try {
			String[] perIds=request.getParameterValues("perId");
			roleService.savePermission(perIds,Integer.parseInt(request.getParameter("roleId")));
		} catch (Exception e) {
			e.printStackTrace();
			return ajaxDoneError("操作失敗");
		}
		
		return ajaxDoneSuccess("操作成功");
	}
	
	@RequestMapping("/add")
	public String add(Model model, HttpServletRequest request)
	{
		model.addAttribute("role", new SysRole());
		return VIEW+"permission/role/roleEdit";
	}
	
	
	
	@RequestMapping("/edit")
	public String edit(Model model, HttpServletRequest request)
	{
		String roleId=request.getParameter("roleId");
		SysRole role=roleService.getRoleById(Integer.parseInt(roleId));
		model.addAttribute("role", role);
		return VIEW+"permission/role/roleEdit";
	}
	
	
	
	@RequestMapping("/del")
	public ModelAndView del(Model model, HttpServletRequest request)
	{
		try {
			String roleId=request.getParameter("roleId");
			roleService.delRoleById(Integer.parseInt(roleId));
		} catch (Exception e) {
			e.printStackTrace();
			return ajaxDoneError("操作失敗");
		}
		return ajaxDoneSuccess("操作成功");
	}
	
	@RequestMapping("/save")
	public ModelAndView save(SysRole role,Model model, HttpServletRequest request,
			HttpServletResponse response) {
		if(role!=null)
		{
			roleService.saveShop(role);
		}
		return ajaxDoneSuccess("操作成功");
	}
	

}

07 其它

1、MySQL資料庫賬戶

MySQL資料庫預設埠:“3306”、資料庫名:“kzfire”、賬戶名:“root”、密碼:空。

2、SQL檔案

SQL檔案放在“MySQL資料庫SQL檔案” 目錄,需透過“Navicat for MySQL”工具執行此SQL檔案。

3、系統啟動檔案

系統啟動檔案是“webroot”目錄下的“login.jsp”

4、系統登入使用者名稱及密碼

“login.jsp”啟動(執行)後,正常情況下進入登入介面,使用者名稱輸入“admin”,密碼輸入“123456”。如果登入不進去,很有可能是資料庫引數配置問題導致,請檢查資料庫引數配置檔案,資料庫引數配置檔案放

演示地址:

說明:此原始碼來源於網路,若有侵權,請聯絡刪除!!

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/2730/viewspace-2826503/,如需轉載,請註明出處,否則將追究法律責任。

相關文章