Căn cứ vào SSM+MVC ba tầng giá cấu thực hiện người dùng quyền hạn quản lý hệ thống
Lời mở đầu
Bổn chu vì đại gia mang đến một cái đơn giản người dùng quyền hạn quản lý hệ thống, nên hệ thống chủ yếu chia làm 2 cái mô khối, người dùng quản lý cùng nhân vật quản lý, nhân vật nhưng nhiều tuyển quyền hạn, người dùng nhưng nhiều tuyển diễn viên, logic hơi chút phức tạp, hảo, phía dưới đi vào chủ đề
Người dùng quản lý hệ thống tóm tắt
Hệ thống duy trì phòng nhảy tường, người dùng không đăng nhập không thể tiến vào chủ trang
- Nhân vật mô khối,Yêu cầu thực hiện nhân vật bổ sung và cắt bỏ sửa tra, thả nhân vật nhưng nhiều tuyển quyền hạn, thực hiện phục tuyển khung quyền hạn hồi hiện
- Người dùng mô khối,Yêu cầu thực hiện người dùng bổ sung và cắt bỏ sửa tra, thực hiện phân trang,Phân trang yêu cầu thực hiện trước 5 sau 4,Thả người dùng nhưng nhiều tuyển diễn viên, thực hiện phục tuyển khung nhân vật hồi hiện
Hiệu quả đồ
Số liệu biểu chuẩn bị
t_user người dùng biểu
CREATETABLE`t_user`(
`id`int(11)NOTNULLAUTO_INCREMENT,
`username`varchar(32)COLLATEutf8mb4_unicode_ciDEFAULTNULLCOMMENT' username xưng ',
`userpwd`varchar(32)COLLATEutf8mb4_unicode_ciDEFAULTNULLCOMMENT' người dùng mật mã ',
`realname`varchar(32)COLLATEutf8mb4_unicode_ciDEFAULTNULLCOMMENT' người dùng tên họ thật ',
PRIMARYKEY(`id`)
)
t_role nhân vật biểu
CREATETABLE`t_role`(
`id`int(11)NOTNULLAUTO_INCREMENT,
`rolename`varchar(32)COLLATEutf8mb4_unicode_ciDEFAULTNULLCOMMENT' nhân vật tên ',
PRIMARYKEY(`id`)
)
t_user_role người dùng nhân vật liên hệ biểu
CREATETABLE`t_user_role`(
`id`int(11)NOTNULLAUTO_INCREMENT,
`user_id`int(11)DEFAULTNULLCOMMENT' người dùng id',
`role_id`int(11)DEFAULTNULLCOMMENT' nhân vật id',
PRIMARYKEY(`id`)
)
t_permission quyền hạn biểu
CREATETABLE`t_permission`(
`id`int(11)NOTNULLAUTO_INCREMENT,
`perm_code`varchar(128)COLLATEutf8mb4_unicode_ciDEFAULTNULLCOMMENT' quyền hạn mã ',
`perm_name`varchar(128)COLLATEutf8mb4_unicode_ciDEFAULTNULLCOMMENT' quyền hạn tên ',
PRIMARYKEY(`id`)
)
t_role_perm nhân vật quyền hạn liên hệ biểu
CREATETABLE`t_role_perm`(
`id`int(11)NOTNULLAUTO_INCREMENT,
`role_id`int(11)DEFAULTNULLCOMMENT' nhân vật id',
`perm_code`varchar(128)COLLATEutf8mb4_unicode_ciDEFAULTNULLCOMMENT' quyền hạn mã ',
PRIMARYKEY(`id`)
)
Hạng mục kết cấu
Java nguyên mã kết cấu
Phối trí văn kiện
Đằng trước kết cấu
pom ỷ lại văn kiện
<?xml version= "1.0" encoding= "UTF-8"?>
<projectxmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http:// w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>SSM-UserPermissionManagerSystem</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository /artifact/org.springframework/spring-aop -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>5.2.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository /artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.4</version>
</dependency>
<!-- https://mvnrepository /artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.4.RELEASE</version>
</dependency>
<!-- mybatis ỷ lại tọa độ -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.4</version>
</dependency>
<!-- java liên tiếp mysql điều khiển tọa độ -->
<!-- https://mvnrepository /artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
<!-- https://mvnrepository /artifact/com.mchange/c3p0 -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
<!-- https://mvnrepository /artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.2.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository /artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.4</version>
</dependency>
<!-- https://mvnrepository /artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.9.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<!-- https://mvnrepository /artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
Dựng hạng mục
Lấy Maven phương thức sáng tạo Web hạng mục
Trung tâm nguyên mã
RouteController, lộ từ nhảy chuyển loại, chủ yếu dùng cho nhảy chuyển tới chỉ định jsp giao diện cũng mang theo số liệu tiến hành nhuộm đẫm
packagecom.wanshi.controller;
importcom.wanshi.bean.TPermission;
importcom.wanshi.bean.TRole;
importcom.wanshi.bean.TUser;
importcom.wanshi.service.PermissionService;
importcom.wanshi.service.RoleService;
importcom.wanshi.service.UserService;
importorg.springframework.beans.factory.annotation.Autowired;
importorg.springframework.stereotype.Controller;
importorg.springframework.ui.Model;
importorg.springframework.web.bind.annotation.RequestMapping;
importjavax.servlet.http.HttpServletRequest;
importjava.util.ArrayList;
importjava.util.List;
@Controller
@RequestMapping("/route")
publicclassRouteController{
@Autowired
privatePermissionServicepermissionService;
@Autowired
privateRoleServiceroleService;
@Autowired
privateUserServiceuserService;
@RequestMapping("/index")
publicStringindex(){
return"index";
}
@RequestMapping("/addRole")
publicStringaddRole(Modelmodel){
List<TPermission>list=permissionService.list();
model.addAttribute("permList",list);
return"role/add";
}
@RequestMapping("/addUser")
publicStringaddUser(Modelmodel){
List<TRole>list=roleService.list();
model.addAttribute("roleList",list);
return"user/add";
}
@RequestMapping("/updateRole")
publicStringupdateRole(HttpServletRequestrequest,Modelmodel){
Stringid=request.getParameter("id");
TRolerole=roleService.getByRole(id);
List<TPermission>list=permissionService.list();
List<TPermission>byRolePermList=roleService.getByRolePermList(role.getId());
List<String>permCodes=newArrayList<String>();
for(TPermissiontPermission:byRolePermList){
permCodes.add(tPermission.getPerm_code());
}
model.addAttribute("permCodes",permCodes);
model.addAttribute("permList",list);
model.addAttribute("role",role);
return"role/edit";
}
@RequestMapping("/updateUser")
publicStringupdateUser(HttpServletRequestrequest,Modelmodel){
Stringid=request.getParameter("id");
TUseruser=userService.getByUser(id);
List<TRole>userRoleList=userService.getByRoleList(user.getId());
List<TRole>roleList=roleService.list();
List<Integer>roleIds=newArrayList<Integer>();
for(TRoletRole:userRoleList){
roleIds.add(tRole.getId());
}
model.addAttribute("roleIds",roleIds);
model.addAttribute("roleList",roleList);
model.addAttribute("user",user);
return"user/edit";
}
}
RoleController, nhân vật khống chế khí loại, dùng cho biên soạn nhân vật CRUD
packagecom.wanshi.controller;
importcom.wanshi.bean.TRole;
importcom.wanshi.service.PermissionService;
importcom.wanshi.service.RoleService;
importorg.springframework.beans.factory.annotation.Autowired;
importorg.springframework.stereotype.Controller;
importorg.springframework.ui.Model;
importorg.springframework.web.bind.annotation.RequestMapping;
importjavax.servlet.http.HttpServletRequest;
importjava.util.List;
@Controller
@RequestMapping("/role")
publicclassRoleController{
@Autowired
privateRoleServiceroleService;
@RequestMapping("/list")
publicStringlist(Modelmodel){
List<TRole>list=roleService.list();
model.addAttribute("roleList",list);
return"role/list";
}
@RequestMapping("addHandle")
publicStringaddHandle(TRolerole,HttpServletRequestrequest){
String[]permCodes=request.getParameterValues("permCodes");
roleService.insert(role,permCodes);
return"redirect:/role/list";
}
@RequestMapping("/updateHandle")
publicStringupdateHandle(TRolerole,HttpServletRequestrequest){
String[]permCodes=request.getParameterValues("permCodes");
roleService.update(role,permCodes);
return"redirect:/role/list";
}
@RequestMapping("/delete")
publicStringdelete(TRolerole){
roleService.delete(role);
return"redirect:/role/list";
}
}
UserController, người dùng khống chế khí loại, dùng cho biên soạn người dùng CRUD, phân trang, cùng với đăng nhập
packagecom.wanshi.controller;
importcom.wanshi.bean.Page;
importcom.wanshi.bean.TPermission;
importcom.wanshi.bean.TRole;
importcom.wanshi.bean.TUser;
importcom.wanshi.service.PermissionService;
importcom.wanshi.service.RoleService;
importcom.wanshi.service.UserService;
importorg.springframework.beans.factory.annotation.Autowired;
importorg.springframework.stereotype.Controller;
importorg.springframework.ui.Model;
importorg.springframework.web.bind.annotation.RequestMapping;
importjavax.servlet.http.HttpServletRequest;
importjava.util.ArrayList;
importjava.util.List;
importjava.util.Set;
@Controller
@RequestMapping("/user")
publicclassUserController{
@Autowired
privateUserServiceuserService;
@Autowired
privatePermissionServicepermissionService;
privatestaticfinalIntegerPageSize=2;
@RequestMapping("/login")
publicStringlogin(TUseruser,HttpServletRequestrequest){
TUseruser1=userService.exam(user);
if(user1!=null){
request.getSession().setAttribute("user",user1);
return"redirect:/route/index";
}
return"login";
}
@RequestMapping("/logout")
publicStringlogout(HttpServletRequestrequest){
request.getSession().invalidate();
return"login";
}
@RequestMapping("/page")
publicStringpage(HttpServletRequestrequest,Modelmodel){
StringpageNumb=request.getParameter("pageNumb");
IntegercurrPage=1;
if(pageNumb!=null&&!pageNumb.equals("")){
currPage=Integer.valueOf(pageNumb);
}
Page<TUser>page=userService.page(currPage,PageSize);
model.addAttribute("pager",page);
return"user/list";
}
@RequestMapping("/addHandle")
publicStringaddHandle(TUseruser,HttpServletRequestrequest){
String[]roleIds=request.getParameterValues("roleIds");
userService.insert(user,roleIds);
return"redirect:/user/page";
}
@RequestMapping("/updateHandle")
publicStringupdateHandle(TUseruser,HttpServletRequestrequest){
String[]roleIds=request.getParameterValues("roleIds");
userService.update(user,roleIds);
return"redirect:/user/page";
}
@RequestMapping("/delete")
publicStringdelete(HttpServletRequestrequest){
Stringid=request.getParameter("id");
userService.delete(id);
return"redirect:/user/page";
}
@RequestMapping("/detail")
publicStringdetail(HttpServletRequestrequest,Modelmodel){
Stringid=request.getParameter("id");
TUseruser=userService.getByUser(id);
List<TRole>roleList=userService.getByRoleList(user.getId());
List<Integer>roleIds=newArrayList<Integer>();
for(TRoletRole:roleList){
roleIds.add(tRole.getId());
}
Set<TPermission>permList=permissionService.getDetail(roleIds);
model.addAttribute("user",user);
model.addAttribute("roleList",roleList);
model.addAttribute("permList",permList);
return"user/detail";
}
}
LoginInterceptor chặn lại khí, dùng cho chặn lại chưa đăng nhập người dùng, nếu chưa đăng nhập, tắc không thể phỏng vấn chủ trang, đạt tới an toàn hiệu quả
packagecom.wanshi.interceptor;
importorg.springframework.web.servlet.HandlerInterceptor;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
publicclassLoginInterceptorimplementsHandlerInterceptor{
publicbooleanpreHandle(HttpServletRequestrequest,HttpServletResponseresponse,Objecthandler)throwsException{
//1. Đối đăng nhập, đăng ký, phong cách trực tiếp cho đi
// thu hoạch thỉnh cầu uri địa chỉ
Stringuri=request.getRequestURI();
if(uri.contains("login")){
returntrue;
}
//2. Tiến hành session nghiệm chứng
Objectuser=request.getSession().getAttribute("user");
if(user==null){
request.getRequestDispatcher("/WEB-INF/pages/login.jsp")
.forward(request,response);
returnfalse;
}
returntrue;
}
}
Lời kết thúc
Hạng mục liền đến này kết thúc, nếu đối bổn hạng mục cảm thấy hứng thú lão thiết, nhưng tại hạ phương thu hoạch hoàn chỉnh hạng mục
Hoàn chỉnh hạng mục liên tiếpNgười dùng quyền hạn quản lý hệ thống
Lấy ra mã: hbpj
Có bất luận vấn đề gì đều nhưng ở bình luận khu nhắn lại hoặc tin nhắn ta
Chỉ cầu ngài có thể lưu lại ngài quý giá dấu chân, chờ gì đâu, đều nhìn đến này lạp, còn chưa tới cái một kiện tam liền sao == ( cất chứa + chú ý + bình luận ) ==
Cảm tạ ngài duy trì, chúng ta hạ thiên thấy ~