testOnReturn: false
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
useGlobalDataSourceStat: true
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
mybatis:
config-location: classpath:mybatis/mybatis-config.xml
mapper-locations: classpath:mybatis/mapper/*.xml
接下来是对照数据库表结构,创建三个pojo:
SysUser.java
import lombok.Data;
/**
-
@Author : JCccc
-
@CreateTime : 2020/4/24
-
@Description :
**/
@Data
public class SysUser {
private Integer userId;
private String userName;
private String password;
private String userRemarks;
}
SysRole.class
import lombok.Data;
/**
-
@Author : JCccc
-
@CreateTime : 2020/4/24
-
@Description :
**/
@Data
public class SysRole {
private String roleId;
private String roleName;
private String roleRemarks;
}
SysPermissions.java
import lombok.Data;
/**
-
@Author : JCccc
-
@CreateTime : 2020/4/24
-
@Description :
**/
@Data
public class SysPermissions {
private Integer perId;
private String permissionsName;
private String perRemarks;
}
实体类创建完毕,先不用管那些操作表的增删改查。
核心使用环节, 创建ShiroConfig.java :
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.Map;
/**
-
@Author : JCccc
-
@CreateTime : 2020/4/24
-
@Description :
**/
@Configuration
public class ShiroConfig {
@Bean
@ConditionalOnMissingBean
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
DefaultAdvisorAutoProxyCreator defaultAAP = new DefaultAdvisorAutoProxyCreator();
defaultAAP.setProxyTargetClass(true);
return defaultAAP;
}
//将自己的验证方式加入容器
@Bean
public UserRealm myShiroRealm() {
UserRealm userRealm = new UserRealm();
return userRealm;
}
//权限管理,配置主要是Realm的管理认证
@Bean
public DefaultWebSecurityManager securityManager() {
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
securityManager.setRealm(myShiroRealm());
return securityManager;
}
//对url的过滤筛选
@Bean
public ShiroFilterFactoryBean shiroFilterFactoryBean(DefaultWebSecurityManager securityManager) {
Sh