merge
This commit is contained in:
@@ -29,7 +29,6 @@ public class CommonConstant {
|
||||
*/
|
||||
public static final String EMAIL_KEY = "email_config";
|
||||
/**
|
||||
*
|
||||
* 当前登录用户
|
||||
*/
|
||||
public static final String CURRENT_USER = "current_user";
|
||||
@@ -37,4 +36,8 @@ public class CommonConstant {
|
||||
* 当前登录用户id
|
||||
*/
|
||||
public static final String CURRENT_USER_ID = "current_id";
|
||||
/**
|
||||
* 权限树
|
||||
*/
|
||||
public static final String AUTHORITY_THREE = "authority_three";
|
||||
}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
package com.xwbing.configuration;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.web.filter.CharacterEncodingFilter;
|
||||
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
|
||||
/**
|
||||
* 说明: 程序上下文配置
|
||||
@@ -16,7 +21,34 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
//@ImportResource("classpath:applicationContext.xml")//用来加载其他xml配置文件
|
||||
public class ApplicationContextConfig {
|
||||
/**
|
||||
* 线程池
|
||||
* 文件上传解析器
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public CommonsMultipartResolver getCommonsMultipartResolver() {
|
||||
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
|
||||
multipartResolver.setMaxUploadSize(104857600);
|
||||
multipartResolver.setDefaultEncoding("UTF-8");
|
||||
return multipartResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* encoding编码问题
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(CharacterEncodingFilter.class)
|
||||
public Filter characterEncodingFilter() {
|
||||
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
|
||||
characterEncodingFilter.setEncoding("UTF-8");
|
||||
characterEncodingFilter.setForceEncoding(true);
|
||||
return characterEncodingFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务线程池
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
@@ -8,19 +8,16 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.web.filter.CharacterEncodingFilter;
|
||||
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 说明: 程序配置
|
||||
* 说明: servlet配置
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2017/5/10 16:36
|
||||
* 作者: xiangwb
|
||||
@@ -29,7 +26,7 @@ import java.util.List;
|
||||
@EnableWebMvc
|
||||
//@ComponentScan(basePackages = {"com.xwbing.controller"}, includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value = RestController.class)})
|
||||
public class DispatcherServletConfig extends WebMvcConfigurerAdapter {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DispatcherServletConfig.class);
|
||||
private final Logger logger = LoggerFactory.getLogger(DispatcherServletConfig.class);
|
||||
|
||||
/***
|
||||
* 添加拦截器
|
||||
@@ -57,8 +54,10 @@ public class DispatcherServletConfig extends WebMvcConfigurerAdapter {
|
||||
*/
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
//swagger
|
||||
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
//
|
||||
super.addResourceHandlers(registry);
|
||||
}
|
||||
|
||||
@@ -89,30 +88,4 @@ public class DispatcherServletConfig extends WebMvcConfigurerAdapter {
|
||||
httpMessageConverter.setSupportedMediaTypes(mediaTypes);
|
||||
return httpMessageConverter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传解析器
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public CommonsMultipartResolver getCommonsMultipartResolver() {
|
||||
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
|
||||
multipartResolver.setMaxUploadSize(104857600);
|
||||
multipartResolver.setDefaultEncoding("UTF-8");
|
||||
return multipartResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* encoding编码问题
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Filter characterEncodingFilter() {
|
||||
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
|
||||
characterEncodingFilter.setEncoding("UTF-8");
|
||||
characterEncodingFilter.setForceEncoding(true);
|
||||
return characterEncodingFilter;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.xwbing.controller.sys;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xwbing.annotation.LogInfo;
|
||||
import com.xwbing.constant.CommonConstant;
|
||||
import com.xwbing.constant.CommonEnum;
|
||||
import com.xwbing.entity.SysAuthority;
|
||||
import com.xwbing.entity.vo.SysAuthVo;
|
||||
import com.xwbing.redis.RedisService;
|
||||
import com.xwbing.service.sys.SysAuthorityService;
|
||||
import com.xwbing.util.JSONObjResult;
|
||||
import com.xwbing.util.RestMessage;
|
||||
@@ -30,12 +32,17 @@ import java.util.List;
|
||||
public class SysAuthorityControl {
|
||||
@Resource
|
||||
private SysAuthorityService sysAuthorityService;
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
@LogInfo("添加权限")
|
||||
@PostMapping("save")
|
||||
@ApiOperation(value = "添加权限")
|
||||
public JSONObject save(@RequestBody SysAuthority sysAuthority) {
|
||||
RestMessage save = sysAuthorityService.save(sysAuthority);
|
||||
//删除缓存
|
||||
if (save.isSuccess())
|
||||
redisService.del(CommonConstant.AUTHORITY_THREE);
|
||||
return JSONObjResult.toJSONObj(save);
|
||||
}
|
||||
|
||||
@@ -46,6 +53,9 @@ public class SysAuthorityControl {
|
||||
if (StringUtils.isEmpty(id))
|
||||
return JSONObjResult.toJSONObj("主键不能为空");
|
||||
RestMessage result = sysAuthorityService.removeById(id);
|
||||
//删除缓存
|
||||
if (result.isSuccess())
|
||||
redisService.del(CommonConstant.AUTHORITY_THREE);
|
||||
return JSONObjResult.toJSONObj(result);
|
||||
}
|
||||
|
||||
@@ -71,6 +81,9 @@ public class SysAuthorityControl {
|
||||
}
|
||||
}
|
||||
RestMessage result = sysAuthorityService.update(sysAuthority);
|
||||
//删除缓存
|
||||
if (result.isSuccess())
|
||||
redisService.del(CommonConstant.AUTHORITY_THREE);
|
||||
return JSONObjResult.toJSONObj(result);
|
||||
}
|
||||
|
||||
@@ -99,7 +112,17 @@ public class SysAuthorityControl {
|
||||
@ApiOperation(value = "递归查询所有权限")
|
||||
@ApiImplicitParam(name = "enable", value = "是否启用,格式Y|N", paramType = "query", dataType = "string")
|
||||
public JSONObject listTree(String enable) {
|
||||
List<SysAuthVo> authoritys = sysAuthorityService.listChildren(CommonConstant.ROOT, enable);
|
||||
List<SysAuthVo> authoritys = null;
|
||||
//先去缓存里拿
|
||||
boolean exists = redisService.exists(CommonConstant.AUTHORITY_THREE);
|
||||
if (exists) {
|
||||
String result = redisService.get(CommonConstant.AUTHORITY_THREE);
|
||||
authoritys = JSONArray.parseArray(result, SysAuthVo.class);
|
||||
} else {
|
||||
authoritys = sysAuthorityService.listChildren(CommonConstant.ROOT, enable);
|
||||
// 设置缓存
|
||||
redisService.set(CommonConstant.AUTHORITY_THREE, JSONArray.toJSONString(authoritys));
|
||||
}
|
||||
return JSONObjResult.toJSONObj(authoritys, true, "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 说明: GlobalExceptionHandler
|
||||
* 说明: 全局异常处理
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2017/5/10 16:36
|
||||
* 作者: xiangwb
|
||||
|
||||
@@ -38,6 +38,7 @@ public class LoginInterceptor extends HandlerInterceptorAdapter {
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
|
||||
String servletPath = request.getServletPath();
|
||||
if (!set.contains(servletPath) && !servletPath.contains("login")) {
|
||||
// HttpSession session = request.getSession();
|
||||
@@ -52,7 +53,7 @@ public class LoginInterceptor extends HandlerInterceptorAdapter {
|
||||
logger.info("用户未登录");
|
||||
OutputStream outputStream = response.getOutputStream();
|
||||
RestMessage restMessage = new RestMessage();
|
||||
restMessage.setMessage("请登录");
|
||||
restMessage.setMessage("请先登录");
|
||||
outputStream.write(JSON.toJSONString(restMessage).getBytes("utf-8"));
|
||||
outputStream.close();
|
||||
return false;
|
||||
|
||||
@@ -16,7 +16,7 @@ spring:
|
||||
#jpa
|
||||
jpa:
|
||||
database: mysql
|
||||
show-sql: true
|
||||
show-sql: false
|
||||
hibernate:
|
||||
ddl-auto: update
|
||||
properties:
|
||||
@@ -40,6 +40,12 @@ spring:
|
||||
starttls:
|
||||
enable: true
|
||||
required: true
|
||||
#b编码
|
||||
http:
|
||||
encoding:
|
||||
charset: UTF-8
|
||||
enabled: true
|
||||
force: true
|
||||
#redis
|
||||
redis:
|
||||
host: 192.168.11.202
|
||||
|
||||
Reference in New Issue
Block a user