springboot整合shiro+thymeleaf
a.步骤:
1.创建prom文件,导入依赖
2.在resources文件下创建mappers包和templates包,并且创建配置文件application.yml,application.properties
3.创建启动类App
4.创建shiro整合springboot的配置类,以及shiro的realm文件
5.创建基础的MVC架构,pojo,mapper,service,controller
b.项目目录
c.效果截图
1.启动springboot运行时
2.http://localhost:8080/ 注意:跳转进入index.html页面,可是index.html需要认证后才可以访问,所有跳转至登录页面去认证
数据库Users表中的数据,单表进行授权验权
我们登录的时候用错误的username登录或者错误的密码登录的效果
a.用户名错误
b.密码错误
用正确的账户和密码进行登录,进入index,html首页
我们在shiro中进行了用户的授权,绑定了add权限和find查找权限,但是我们在控制器的方法上却只给add和update方法上绑定了相应的add和update权限,所以有个效果会报500
有add权限去访问add方法
2.没有update权限去方法update方法
3.无权限访问方法就会报错500,说当前权限找不到,如果想要页面好看可以去创建异常捕获器去修饰页面
d.项目部署的环境
a. 1.创建prom文件,导入依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.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>com.liujie</groupId>
<artifactId>thymeleaf-shiro-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.0</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<!-- 跳过测试类 -->
<skipTests>true</skipTests>
</configuration>
<!-- 网上收集还有这个标签也可以跳过test
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
-->
</plugin>
</plugins>
</build>
<dependencies>
<!--aop切入包-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<version>2.4.3</version>
</dependency>
<!--整合的shiro依赖-->
<!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-spring -->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.7.1</version>
</dependency>
<!--自动编译时生成getter,setter方法-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!--进行数据库连接-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.21</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--thymeleaf模板-->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
<groupId>