JavaWeb之ssm框架整合,用户角色权限管理
Posted 谁将新樽辞旧月,今月曾经照古人
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaWeb之ssm框架整合,用户角色权限管理相关的知识,希望对你有一定的参考价值。
SSM框架整合
Spring
SpringMVC
MyBatis
导包:
1, spring
2, MyBatis
3, mybatis-spring
4, fastjson
5, aspectweaver----AspectJ框架
6, log4j-----打印日志信息
7, ojdbc6.jar
8, jstl.jar, standard.jar----标准标签库
9, commons-logging-1.2.jar
src下建立包结构
配置web.xml,spring-mvc.xml,spring-all.xml
建立表结构,使用PowerDesigner
前台页面,后台方法等。
项目结构:
代码(引用,未完全实现):
配置文件:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xmlns="http://java.sun.com/xml/ns/javaee" 4 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 5 id="WebApp_ID" version="3.0"> 6 7 <!-- 告诉web容器log4j的属性文件所在位置 --> 8 <context-param> 9 <param-name>log4jConfigLocation</param-name> 10 <param-value>classpath:conf/log4j.properties</param-value> 11 </context-param> 12 <listener> 13 <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> 14 </listener> 15 16 <!-- spring框架提供的字符编码过滤器 --> 17 <filter> 18 <filter-name>characterEncodingFilter</filter-name> 19 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 20 <init-param> 21 <param-name>encoding</param-name> 22 <param-value>UTF-8</param-value> 23 </init-param> 24 <init-param> 25 <param-name>forceEncoding</param-name> 26 <param-value>true</param-value> 27 </init-param> 28 </filter> 29 <filter-mapping> 30 <filter-name>characterEncodingFilter</filter-name> 31 <url-pattern>/*</url-pattern> 32 </filter-mapping> 33 34 <!-- 加载Spring的配置文件 --> 35 <context-param> 36 <param-name>contextConfigLocation</param-name> 37 <param-value>classpath:conf/spring-config.xml</param-value> 38 </context-param> 39 <listener> 40 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 41 </listener> 42 43 <!-- 加载SpringMVC的配置文件 --> 44 <servlet> 45 <servlet-name>springDispatcherServlet</servlet-name> 46 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 47 <init-param> 48 <param-name>contextConfigLocation</param-name> 49 <param-value>classpath:conf/spring-mvc.xml</param-value> 50 </init-param> 51 <load-on-startup>1</load-on-startup> 52 </servlet> 53 <servlet-mapping> 54 <servlet-name>springDispatcherServlet</servlet-name> 55 <url-pattern>*.do</url-pattern> 56 </servlet-mapping> 57 </web-app>
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xmlns="http://java.sun.com/xml/ns/javaee" 4 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 5 id="WebApp_ID" version="3.0"> 6 7 <!-- 告诉web容器log4j的属性文件所在位置 --> 8 <context-param> 9 <param-name>log4jConfigLocation</param-name> 10 <param-value>classpath:conf/log4j.properties</param-value> 11 </context-param> 12 <listener> 13 <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> 14 </listener> 15 16 <!-- spring框架提供的字符编码过滤器 --> 17 <filter> 18 <filter-name>characterEncodingFilter</filter-name> 19 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 20 <init-param> 21 <param-name>encoding</param-name> 22 <param-value>UTF-8</param-value> 23 </init-param> 24 <init-param> 25 <param-name>forceEncoding</param-name> 26 <param-value>true</param-value> 27 </init-param> 28 </filter> 29 <filter-mapping> 30 <filter-name>characterEncodingFilter</filter-name> 31 <url-pattern>/*</url-pattern> 32 </filter-mapping> 33 34 <!-- 加载Spring的配置文件 --> 35 <context-param> 36 <param-name>contextConfigLocation</param-name> 37 <param-value>classpath:conf/spring-config.xml</param-value> 38 </context-param> 39 <listener> 40 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 41 </listener> 42 43 <!-- 加载SpringMVC的配置文件 --> 44 <servlet> 45 <servlet-name>springDispatcherServlet</servlet-name> 46 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 47 <init-param> 48 <param-name>contextConfigLocation</param-name> 49 <param-value>classpath:conf/spring-mvc.xml</param-value> 50 </init-param> 51 <load-on-startup>1</load-on-startup> 52 </servlet> 53 <servlet-mapping> 54 <servlet-name>springDispatcherServlet</servlet-name> 55 <url-pattern>*.do</url-pattern> 56 </servlet-mapping> 57 </web-app>
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:context="http://www.springframework.org/schema/context" 5 xmlns:mvc="http://www.springframework.org/schema/mvc" 6 xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd 7 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 8 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd"> 9 10 <!-- 配置扫描器 --> 11 <context:component-scan base-package="com.hanqi.controller" /> 12 13 <!-- 配置视图解析器 --> 14 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 15 <!-- <property name="prefix" value="/WEB-INF/"></property> --> 16 <property name="prefix" value="/"></property> 17 <property name="suffix" value=".jsp"></property> 18 </bean> 19 20 <!-- 上传文件的解析器 --> 21 <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> 22 <!-- 上传文件的总大小, 单位是b --> 23 <property name="maxUploadSize" value="10240000"></property> 24 <!-- 单个文件的上传大小限制, 单位是b --> 25 <property name="maxUploadSizePerFile" value="1000000"></property> 26 <!-- 默认字符集 --> 27 <property name="defaultEncoding" value="utf-8"></property> 28 </bean> 29 30 <!-- 开启SpringMVC注解驱动 --> 31 <mvc:annotation-driven> 32 <!-- 改成false, 原因是在spring中默认使用的json格式的转换器是Jackson.jar中的转换器, 但实际开发中更受欢迎的是fastjson.jar --> 33 <mvc:message-converters register-defaults="false"> 34 <bean class="org.springframework.http.converter.StringHttpMessageConverter" /> 35 <bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter" /> 36 <bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter" /> 37 <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/> 38 <bean id="fastJsonHttpMessagerConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> 39 <!-- 设置支持的媒体类型 --> 40 <property name="supportedMediaTypes"> 41 <list> 42 <value>text/html; charset=utf-8</value> 43 <value>application/json; charset=utf-8</value> 44 </list> 45 </property> 46 </bean> 47 </mvc:message-converters> 48 </mvc:annotation-driven> 49 </beans>
src下:
model层实体类:
1 package com.hanqi.model; 2 3 public class SrUserRole { 4 private Integer id; 5 private Integer userid; 6 private Integer roleid; 7 8 public SrUserRole() { 9 super(); 10 } 11 12 public SrUserRole(Integer id, Integer userid, Integer roleid) { 13 super(); 14 this.id = id; 15 this.userid = userid; 16 this.roleid = roleid; 17 } 18 19 public Integer getId() { 20 return id; 21 } 22 23 public void setId(Integer id) { 24 this.id = id; 25 } 26 27 public Integer getUserid() { 28 return userid; 29 } 30 31 public void setUserid(Integer userid) { 32 this.userid = userid; 33 } 34 35 public Integer getRoleid() { 36 return roleid; 37 } 38 39 public void setRoleid(Integer roleid) { 40 this.roleid = roleid; 41 } 42 }
1 package com.hanqi.model; 2 3 public class SrRoleMenu { 4 private Integer id; 5 private Integer roleid; 6 private Integer menuid; 7 8 public SrRoleMenu(Integer id, Integer roleid, Integer menuid) { 9 super(); 10 this.id = id; 11 this.roleid = roleid; 12 this.menuid = menuid; 13 } 14 15 public SrRoleMenu() { 16 super(); 17 } 18 19 public Integer getId() { 20 return id; 21 } 22 23 public void setId(Integer id) { 24 this.id = id; 25 } 26 27 public Integer getRoleid() { 28 return roleid; 29 } 30 31 public void setRoleid(Integer roleid) { 32 this.roleid = roleid; 33 } 34 35 public Integer getMenuid() { 36 return menuid; 37 } 38 39 public void setMenuid(Integer menuid) { 40 this.menuid = menuid; 41 } 42 }
1 package com.hanqi.model; 2 3 public class SrRole { 4 private Integer id; 5 private String rolename; 6 private String status; 7 private boolean checked; 8 9 public SrRole() { 10 super(); 11 } 12 13 public SrRole(Integer id, String rolename, String status) { 14 super(); 15 this.id = id; 16 this.rolename = rolename; 17 this.status = status; 18 } 19 20 public Integer getId() { 21 return id; 22 } 23 24 public void setId(Integer id) { 25 this.id = id; 26 } 27 28 public String getRolename() { 29 return rolename; 30 } 31 32 public void setRolename(String rolename) { 33 this.rolename = rolename; 34 } 35 36 public String getStatus() { 37 return status; 38 } 39 40 public void setStatus(String status) { 41 this.status = status; 42 } 43以上是关于JavaWeb之ssm框架整合,用户角色权限管理的主要内容,如果未能解决你的问题,请参考以下文章
JavaWeb SSM springboot动物检疫信息管理系统(源码+论文可运行《精品毕设》)主要实现:登录用户管理角色权限菜单部门检疫类型检疫信息检疫物质养殖场审核公告等
JavaWeb SSM SpringBoot景区行李寄存管理系统(源码+论文报告可运行《精品毕设》)主要模块:登录用户角色权限菜单部门行李柜用户寄存记录查询通知公告入柜出柜等
JavaWeb SSM 《精品毕设》个人博客系统 前台 + 后台(源码 + 论文)主要实现的登录注册主页博客随笔文章管理消息管理评论管理用户管理角色管理主题管理栏目管理等功能
JavaWeb SSM 《精品毕设》个人博客系统 前台 + 后台(完整源码+论文)主要实现的登录注册主页博客随笔文章管理消息管理评论管理用户管理角色管理主题管理栏目管理等功能