Commit a1ed68f6 authored by 梁光意's avatar 梁光意

把session修改为request

parent 83ad1535
......@@ -14,8 +14,6 @@ import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import java.nio.channels.SelectableChannel;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Map;
import java.util.function.Supplier;
......@@ -48,7 +46,7 @@ public class SysMetaObjectHandler implements MetaObjectHandler {
if(StringUtils.isBlank(token)){
throw new SysException("token不能为空");
}
Object currentUser = request.getSession().getAttribute(token);
Object currentUser = request.getAttribute(token);
CurrentUser user =null;
if(ObjectUtils.isNotEmpty(currentUser)){
user= SlmConstants.gson.fromJson(currentUser.toString(),CurrentUser.class);
......
......@@ -85,7 +85,7 @@ public class BaseRestController {
String getUrl =dcClientHost+"/{appId}/users/user-info";
R<CurrentUser> result = RestTemplateUtils.get(getUrl, new TypeToken<R<CurrentUser>>() {
}.getType(), uriVariables);
request.getSession().setAttribute(token, SlmConstants.gson.toJson(result.detach()));
request.setAttribute(token,SlmConstants.gson.toJson(result.detach()));
}
......@@ -100,6 +100,6 @@ public class BaseRestController {
protected CurrentUser getCurrentUser (HttpServletRequest request){
String token=request.getHeader(SlmConstants.TOKEN_PREFIX);
return SlmConstants.gson.fromJson(request.getSession().getAttribute(token).toString(),CurrentUser.class);
return SlmConstants.gson.fromJson(request.getAttribute(token).toString(),CurrentUser.class);
}
}
......@@ -3,6 +3,7 @@ package com.syc.slm.slmbi.handler;
import com.syc.slm.common.core.util.R;
import com.syc.slm.slmbi.exception.SysException;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.MyBatisSystemException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
......@@ -32,4 +33,16 @@ public class SysExceptionHandler {
return R.bad(e.getMsg(),e.getDebugMsg());
}
/**
* mybaits抛出的异常,以及SysMetaObjectHandler自定义抛出的异常
* @param e
* @return
*/
@ExceptionHandler(MyBatisSystemException.class)
@ResponseBody
public R<Object> handleMyBatisSystemException(MyBatisSystemException e) {
log.info(e.getMessage());
return R.bad(e.getCause().getCause().getMessage(),e.getMessage());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment