欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
1.SpringBoot整合Shiro思路
 
2. 环境搭建
 
2.1 创建项目
 
2.2 引入依赖
 
pom.xml
 
<dependencies>
 
    <dependency>
 
        <groupId>org.springframework.boot</groupId>
 
        <artifactId>spring-boot-starter-web</artifactId>
 
    </dependency>
 
    <dependency>
 
        <groupId>org.springframework.boot</groupId>
 
        <artifactId>spring-boot-devtools</artifactId>
 
        <scope>runtime</scope>
 
        <optional>true</optional>
 
    </dependency>
 
    <dependency>
 
        <groupId>org.projectlombok</groupId>
 
        <artifactId>lombok</artifactId>
 
        <optional>true</optional>
 
    </dependency>
 
    <dependency>
 
        <groupId>org.springframework.boot</groupId>
 
        <artifactId>spring-boot-starter-test</artifactId>
 
        <scope>test</scope>
 
    </dependency>
 
    <!--引入Jsp依赖-->
 
    <dependency>
 
        <groupId>org.apache.tomcat.embed</groupId>
 
        <artifactId>tomcat-embed-jasper</artifactId>
 
    </dependency>
 
    <!--jstl-->
 
    <dependency>
 
        <groupId>jstl</groupId>
 
        <artifactId>jstl</artifactId>
 
        <version>1.2</version>
 
    </dependency>
 
</dependencies>
 
<build>
 
    <plugins>
 
        <plugin>
 
            <groupId>org.springframework.boot</groupId>
 
            <artifactId>spring-boot-maven-plugin</artifactId>
 
            <configuration>
 
                <excludes>
 
                    <exclude>
 
                        <groupId>org.projectlombok</groupId>
 
                        <artifactId>lombok</artifactId>
 
                    </exclude>
 
                </excludes>
 
            </configuration>
 
        </plugin>
 
    </plugins>
 
</build>
 
2.3 创建前端页面
 
在webapp文件夹中创建index.jsp和login.jsp
 
index.jsp
 
<%@page contentType="text/html;UTF-8" pageEncoding="UTF-8" isErrorPage="false" %>
 
<!doctype html>
 
<html lang="en">
 
<head>
 
    <meta charset="UTF-8">
 
    <meta name="viewport"
 
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
 
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
 
    <title>Document</title>
 
</head>
 
<body>
 
<%--受限资源--%>
 
<h1>系统主页</h1>
 
<ul>
 
    <li><a href="#">用户管理</a></li>
 
    <li><a href="#">商品管理</a></li>
 
    <li><a href="#">订单管理</a></li>
 
    <li><a href="#">物流管理</a></li>
 
</ul>
 
</body>
 
</html>
 
login.jsp
 
<%@page contentType="text/html;UTF-8" pageEncoding="UTF-8" isErrorPage="false" %>
 
<!doctype html>
 
<html lang="en">
 
<head>
 
    <meta charset="UTF-8">
 
    <meta name="viewport"
 
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
 
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
 
    <title>Document</title>
 
</head>
 
<body>
 
<h1>登录界面</h1>
 
<form action="${pageContext.request.contextPath}/user/login" method="post">
 
    用户名:<input type="text" name="username" > <br/>
 
    密码  : <input type="text" name="password"> <br>
 
    <input type="submit" value="登录">
 
</form>
 
</html>
 
2.4 配置视图信息
 
application.properties
 
server.port=8080
 
server.servlet.context-path=/shiro
 
spring.application.name=shiro
 
spring.mvc.view.prefix=/
 
spring.mvc.view.suffix=.jsp
 
2.5 解决IDEA冲突问题
 
JSP 与IDEA 与SpringBoot存在一定的不兼容,修改此配置即可解决
 
2.6 测试搭建的环境
 
3. 整合Shiro
 
3.1 引入依赖
 
pom.xml
 
<!--引入shrio-->
 
<dependency>
 
    <groupId>org.apache.shiro</groupId>
 
    <artifactId>shiro-spring-boot-starter</artifactId>
 
    <version>1.5.3</version>
 
</dependency>

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h65202.shtml