zoukankan      html  css  js  c++  java
  • RBAC权限管理系统

    基于角色的权限访问控制(Role-Based Access Control)作为传统访问控制(自主访问,强制访问)的有前景的代替受到广泛的关注。

    扩展的RBAC模型:基于部门进行管理。

     使用idea床架springmvc项目:

    File -> New Project -> Maven -> create from archetype -> :maven-archetype-webapp 填写包名等信息

    项目生成后,在src/main文件夹下新建java文件夹,然后右键 Mark Directory as Resource Root

    添加tomcat-server后,在VM options中添加,控制台不会输出乱码

    -Dfile.encoding=UTF-8

    等项目构建完成后,找到maven spring-beans依赖

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
        <springframework.version>5.1.5.RELEASE</springframework.version>
      </properties>
    
      <dependencies>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-beans</artifactId>
          <version>${springframework.version}</version>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context</artifactId>
          <version>${springframework.version}</version>
        </dependency>
        <!--Spring MVC + Spring Web-->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-web</artifactId>
          <version>${springframework.version}</version>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-webmvc</artifactId>
          <version>${springframework.version}</version>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-jdbc</artifactId>
          <version>${springframework.version}</version>
        </dependency>
        <!--mybatis-->
        <dependency>
          <groupId>org.mybatis</groupId>
          <artifactId>mybatis</artifactId>
          <version>3.5.2</version>
        </dependency>
        <dependency>
          <groupId>org.mybatis</groupId>
          <artifactId>mybatis-spring</artifactId>
          <version>2.0.2</version>
        </dependency>
        <!--druid-->
        <dependency>
          <groupId>com.alibaba</groupId>
          <artifactId>druid</artifactId>
          <version>1.1.12</version>
        </dependency>
        <!--mysql-->
        <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
          <version>8.1.11</version>
        </dependency>
        <!--lombok-->
        <dependency>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok</artifactId>
          <version>1.18.8</version>
        </dependency>
        <!--Jackson-->
        <!--fastJson有bug-->
        <dependency>
          <groupId>com.fasterxml.jackson.datatype</groupId>
          <artifactId>jackson-datatype-guava</artifactId>
          <version>2.8.8</version>
        </dependency>
        
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.11</version>
          <scope>test</scope>
        </dependency>
      </dependencies>

     配置web.xml文件

    <!DOCTYPE web-app PUBLIC
     "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
     "http://java.sun.com/dtd/web-app_2_3.dtd" >
    
    <web-app>
      <display-name>Archetype Created Web Application</display-name>
      <!--listener-->
      <!--监听springbean的加载-->
      <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
      
      <!--Spring beans 配置文件所在目录-->
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
      </context-param>
      <!--springmvc配置-->
      <servlet>
        <servlet-name>spring</servlet-name><!--对应spring-servlet.xml配置文件-->
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      </servlet>
      <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern><!--配置/login 不会匹配/ss.jsp-->
      </servlet-mapping>
      <!--Encoding-->
      <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
          <param-name>encoding</param-name>
          <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
          <param-name>forceEncoding</param-name>
          <param-value>true</param-value>
        </init-param>
      </filter>
      <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/</url-pattern>
      </filter-mapping>
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
      
    </web-app>

    spring-servlet.xml文件

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/tool"
           xmlns:mvc="http://www.springframework.org/schema/tool"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool.xsd">
    
        <!--上下文注解-->
        <context:annotation-config/>
        <!--启动注解驱动的spring mvc 功能-->
        <mvc:annotation-driven/>
        <!--启动包扫描-->
        <context:component-scan base-package="com.mmall.controller" />
        <context:component-scan base-package="com.mmall.service" />
        
        <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
        <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
        <bean id="jsonView" class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" />
        <bean class="org.springframework.web.servlet.view.InternalResourceView">
            <property name="prefix" value="/views/"/>
            <property name="suffix" value=".jsp" />
        </bean>
    </beans>

     

     mybatis配置

    Idea部署tomcat->Deployment->*:war exploded 部署加调试

  • 相关阅读:
    js判断CheckBox是否选中
    C# 判断一个请求是异步请求
    正判断文件类型
    mysql启动命令窗口闪退问题
    db2手动恢复备份数据库
    redis使用
    分析Redis架构设计
    DB2数据库的在线备份步骤
    MySql主从复制
    SpringMVC工作原理
  • 原文地址:https://www.cnblogs.com/taiguyiba/p/10749137.html
Copyright © 2011-2022 走看看