Spring+shiro+mybatis+lombok项目部署
Spring+shiro+mybatis+lombok项目部署
项目介绍
本项目是maven项目
数据库mysql
前端html+jquery+md5+wangEditor+cancas 框架:bootstrap
后端spring+mybatis+shiro+lombok
笔记配套项目:
配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| spring: datasource: url: jdbc:mysql://localhost:3306/finance?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC&zeroDateTimeBehavior=convertToNull username: root password: 123456 driver-class-name: com.mysql.cj.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource druid: initial-size: 5 min-idle: 5 max-active: 20 max-wait: 60000 time-between-eviction-runs-millis: 60000 min-evictable-idle-time-millis: 300000 validation-query: SELECT 1 FROM DUAL test-while-idle: true test-on-borrow: false test-on-return: false pool-prepared-statements: true max-pool-prepared-statement-per-connection-size: 20 filters: stat,wall use-global-data-source-stat: true connect-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 web: resources: static-locations: classpath:/static/ mybatis: mapper-locations: classpath:mapper/\*.xml type-aliases-package: com.crazy.finance.bean configuration: map-underscore-to-camel-case: true
server: port: 8099
|
返回类JsonUtils
在tuils里的JsonUtils类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| package com.example.finance.utils; import lombok.Data; import java.util.HashMap; import java.util.Map; /\*\* \* 通用的返回类(封装json数据) \* \*/ @Data public class JsonUtils {
private int code;
private String msg;
private Map<String, Object> extend = new HashMap(); /\*\* \* 处理成功 \* \* @return \*/ public static JsonUtils success() { JsonUtils result = new JsonUtils(); result.setCode(100); result.setMsg("处理成功!"); return result; } /\*\* \* 处理失败 \* \* @return \*/ public static JsonUtils fail() { JsonUtils result = new JsonUtils(); result.setCode(200); result.setMsg("处理失败!"); return result; } public static JsonUtils failPs() { JsonUtils result = new JsonUtils(); result.setCode(300); result.setMsg("处理失败!"); return result; } public static JsonUtils failEx() { JsonUtils result = new JsonUtils(); result.setCode(400); result.setMsg("处理失败!"); return result; } public static JsonUtils failNu() { JsonUtils result = new JsonUtils(); result.setCode(500); result.setMsg("处理失败!"); return result; } /\*\* \* 添加要返回的json数据 \* \* @param key \* @param value \* @return \*/ public JsonUtils add(String key, Object value) { this.getExtend().put(key, value); return this; } }
|
Config
一些配置类
分别是ShiroConfig类
用来自动实现权限分配
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| package com.example.finance.config.shiro; import at.pollux.thymeleaf.shiro.dialect.ShiroDialect; import lombok.extern.slf4j.Slf4j; import org.apache.shiro.spring.web.ShiroFilterFactoryBean; import org.apache.shiro.web.mgt.DefaultWebSecurityManager; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import java.util.LinkedHashMap; import java.util.Map; @Slf4j @Configuration public class ShiroConfig { @Bean public ShiroFilterFactoryBean getShiroFilterFactoryBean(@Qualifier("securityManager") DefaultWebSecurityManager securityManager){ ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean(); bean.setSecurityManager(securityManager);
Map<String, String> filterMap = new LinkedHashMap();
/\* anon: 无需认证就可访问 authc:必须认证才能访问 user:必须拥有记住我功能才能访问 perms: 拥有对某个资源的权限才能访问 role:拥有某个角色权限才能访问 \*/
filterMap.put("/error/\*\*", "anon"); filterMap.put("/", "anon"); filterMap.put("/index.html", "anon"); filterMap.put("/toregister.html", "anon"); filterMap.put("/login/\*\*", "anon"); filterMap.put("/asserts/\*\*", "anon"); filterMap.put("/bootstrap/\*\*", "anon"); filterMap.put("/images/\*\*", "anon"); filterMap.put("/lyear/\*\*", "anon"); filterMap.put("/js/\*\*", "anon");
filterMap.put("/\*\*", "authc");
bean.setFilterChainDefinitionMap(filterMap);
bean.setLoginUrl("/");
return bean; } @Bean("securityManager") public DefaultWebSecurityManager getDefaultWebSecurityManager(@Qualifier("userRealm") UserRealm userRealm) { DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(); securityManager.setRealm(userRealm); return securityManager; } @Bean("userRealm") public UserRealm getUserRealm() { return new UserRealm(); }
@Bean public ShiroDialect getShiroDialect() { return new ShiroDialect(); } }
|