基于javaweb+mysql的springboot前后端分离疫情防疫平台设计和实现(java+springmvc+vue+node.js+mybatis+mysql+springboot)
运行环境
Java≥8、MySQL≥5.7、Node.js≥10
开发工具
后端:eclipse/idea/myeclipse/sts等均可配置运行
前端:WebStorm/VSCode/HBuilderX等均可
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot前后端分离疫情防疫平台设计和实现(java+springmvc+vue+node.js+mybatis+mysql+springboot)
主要技术:Java、springmvc、VUE、node.js、mybatis、mysql、tomcat、jquery、layui、bootstarp、JavaScript、html、css、jsp、log4j等一些常见的基本技术。 主要模块功能有:
管理员用户登录:用户登录。
用户信息: 用户信息数据的列表查看、修改和删除、用户绑定角色来显示对应的菜单显示。
角色管理:角色信息数据的列表查看、修改和删除、每个角色可以设置不同菜单显示、超级管理员拥有最高权限。
菜单管理: 菜单信息数据的列表查看、修改和删除、可以通过用户角色来设置
菜单权限:根据用户绑定角色、角色绑定菜单显示、以及基础菜单的添加、修改和删除操作。
实时疫情状态:通过echarts图标来模拟实现数据驱动标识、实时显示疫情分布图和感染人员信息等。
历史行程管理:每日登记管理:外出报备管理:复工申请管理:审核信息管理:
通知公告管理:管理员发布一些通知公告信息以及管理查看等
这个系统主要功能截图如下:
登录之后进入系统首页:目前系统主要功能如下
用户管理模块:用户添加、修改、删除、查询等基本操作
角色管理模块、通过用户绑定角色、角色控制菜单显示、灵活控制菜单。
@RestController
@RequestMapping("/sys/goOut")
public class GoOutController extends AbstractController {
@Autowired
private GoOutService GoOutService;
@GetMapping("/list")
public R list(@RequestParam Map<String, Object> params){
PageUtils page = GoOutService.queryPage(params);
return R.ok().put("page", page);
}
@GetMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
GoOut goOut = GoOutService.getById(id);
return R.ok().put("goOut", goOut);
}
@PostMapping("/save")
public R save(@RequestBody GoOut goOut){
goOut.setStu("未审核");
GoOutService.saveOrUpdate(goOut);
return R.ok();
}
@PostMapping("/update")
public R update(@RequestBody GoOut goOut){
GoOutService.updateById(goOut);
return R.ok();
}
@PostMapping("/delete")
public R update(@RequestBody Long[] ids){
for (int i = 0; i < ids.length; i++) {
Long id=ids[i];
GoOutService.removeById(id);
}
return R.ok();
}
if (parameters == null || parameters.length == 0) {
return null;
}
for (int i = 0; i < parameters.length; i++) {
parameters[i] = xssEncode(parameters[i]);
}
return parameters;
}
@Override
public Map<String,String[]> getParameterMap() {
Map<String,String[]> map = new LinkedHashMap<>();
Map<String,String[]> parameters = super.getParameterMap();
for (String key : parameters.keySet()) {
String[] values = parameters.get(key);
for (int i = 0; i < values.length; i++) {
values[i] = xssEncode(values[i]);
}
map.put(key, values);
}
return map;
}
@Override
public String getHeader(String name) {
String value = super.getHeader(xssEncode(name));
if (StringUtils.isNotBlank(value)) {
value = xssEncode(value);
}
return value;
}
private String xssEncode(String input) {
return htmlFilter.filter(input);
}
/**
* 获取最原始的request
*/
public HttpServletRequest getOrgRequest() {
return orgRequest;
}
/**
//获取用户凭证
String token = request.getHeader(jwtUtils.getHeader());
if(StringUtils.isBlank(token)){
token = request.getParameter(jwtUtils.getHeader());
}
//凭证为空
if(StringUtils.isBlank(token)){
throw new RRException(jwtUtils.getHeader() + "不能为空", HttpStatus.UNAUTHORIZED.value());
}
Claims claims = jwtUtils.getClaimByToken(token);
if(claims == null || jwtUtils.isTokenExpired(claims.getExpiration())){
throw new RRException(jwtUtils.getHeader() + "失效,请重新登录", HttpStatus.UNAUTHORIZED.value());
}
//设置userId到request里,后续根据userId,获取用户信息
request.setAttribute(USER_KEY, Long.parseLong(claims.getSubject()));
return true;
}
}
/**
* .
*
* Thm
*
* !
*/
package io.renren.modules.sys.controller;
}
@Override
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
if(((HttpServletRequest) request).getMethod().equals(RequestMethod.OPTIONS.name())){
return true;
}
return false;
}
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
//获取请求token,如果token不存在,直接返回401
String token = getRequestToken((HttpServletRequest) request);
if(StringUtils.isBlank(token)){
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setHeader("Access-Control-Allow-Credentials", "true");
httpResponse.setHeader("Access-Control-Allow-Origin", HttpContextUtils.getOrigin());
String json = new Gson().toJson(R.error(HttpStatus.SC_UNAUTHORIZED, "invalid token"));
httpResponse.getWriter().print(json);
return false;
}
return executeLogin(request, response);
}
@Override
protected boolean onLoginFailure(AuthenticationToken token, AuthenticationException e, ServletRequest request, ServletResponse response) {
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setContentType("application/json;charset=utf-8");
httpResponse.setHeader("Access-Control-Allow-Credentials", "true");
httpResponse.setHeader("Access-Control-Allow-Origin", HttpContextUtils.getOrigin());
try {
//处理登录失败的异常
Throwable throwable = e.getCause() == null ? e : e.getCause();
R r = R.error(HttpStatus.SC_UNAUTHORIZED, throwable.getMessage());
* 登录
*/
@PostMapping("/sys/login")
public Map<String, Object> login(@RequestBody SysLoginForm form)throws IOException {
boolean captcha = sysCaptchaService.validate(form.getUuid(), form.getCaptcha());
// if(!captcha){
// return R.error("验证码不正确");
// }
//用户信息
SysUserEntity user = sysUserService.queryByUserName(form.getUsername());
//账号不存在、密码错误
if(user == null || !user.getPassword().equals(new Sha256Hash(form.getPassword(), user.getSalt()).toHex())) {
return R.error("账号或密码不正确");
}
//账号锁定
if(user.getStatus() == 0){
return R.error("账号已被锁定,请联系管理员");
}
//生成token,并保存到数据库
R r = sysUserTokenService.createToken(user.getUserId());
return r;
}
/**
* 退出
*/
@PostMapping("/sys/logout")
public R logout() {
sysUserTokenService.logout(getUserId());
return R.ok();
}
}
/**
* .
*
* Thm
*
* !
*/
package io.renren.common.aspect;
/**
* 角色管理
*
*/
@RestController
@RequestMapping("/sys/role")
public class SysRoleController extends AbstractController {
@Autowired
private SysRoleService sysRoleService;
@Autowired
private SysRoleMenuService sysRoleMenuService;
/**
* 角色列表
*/
@GetMapping("/list")
@RequiresPermissions("sys:role:list")
public R list(@RequestParam Map<String, Object> params){
//如果不是超级管理员,则只查询自己创建的角色列表
if(getUserId() != Constant.SUPER_ADMIN){
params.put("createUserId", getUserId());
}
PageUtils page = sysRoleService.queryPage(params);
return R.ok().put("page", page);
}
/**
* 角色列表
*/
@GetMapping("/select")
@RequiresPermissions("sys:role:select")
public R select(){
Map<String, Object> map = new HashMap<>();
//如果不是超级管理员,则只查询自己所拥有的角色列表
if(getUserId() != Constant.SUPER_ADMIN){
map.put("create_user_id", getUserId());
@Autowired
private ToworkApplyService ToworkApplyService;
@GetMapping("/list")
public R list(@RequestParam Map<String, Object> params){
PageUtils page = ToworkApplyService.queryPage(params);
return R.ok().put("page", page);
}
@GetMapping("/ToworkApply/{id}")
public R ToworkApply(@PathVariable("id") Long id){
ToworkApply toworkApply = ToworkApplyService.getById(id);
return R.ok().put("toworkApply", toworkApply);
}
@PostMapping("/save")
public R save(@RequestBody ToworkApply toworkApply){
toworkApply.setStu("未审核");
ToworkApplyService.saveOrUpdate(toworkApply);
return R.ok();
}
@PostMapping("/update")
public R update(@RequestBody ToworkApply toworkApply){
ToworkApplyService.updateById(toworkApply);
return R.ok();
}
@PostMapping("/delete")
public R update(@RequestBody Long[] ids){
for (int i = 0; i < ids.length; i++) {
Long id=ids[i];
ToworkApplyService.removeById(id);
}
return R.ok();
}
}
/**
* .
*
* Thm
*
* !
*/
package io.renren.modules.app.controller;
@Around("logPointCut()")
public Object around(ProceedingJoinPoint point) throws Throwable {
long beginTime = System.currentTimeMillis();
//执行方法
Object result = point.proceed();
//执行时长(毫秒)
long time = System.currentTimeMillis() - beginTime;
//保存日志
saveSysLog(point, time);
return result;
}
private void saveSysLog(ProceedingJoinPoint joinPoint, long time) {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
SysLogEntity sysLog = new SysLogEntity();
SysLog syslog = method.getAnnotation(SysLog.class);
if(syslog != null){
//注解上的描述
sysLog.setOperation(syslog.value());
}
//请求的方法名
String className = joinPoint.getTarget().getClass().getName();
String methodName = signature.getName();
sysLog.setMethod(className + "." + methodName + "()");
//请求的参数
Object[] args = joinPoint.getArgs();
try{
String params = new Gson().toJson(args);
sysLog.setParams(params);
}catch (Exception e){
}
//获取request
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
//设置IP地址
sysLog.setIp(IPUtils.getIpAddr(request));
//用户名
String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername();
sysLog.setUsername(username);
/**
* 验证参数是否正确
*/
private void verifyForm(SysMenuEntity menu){
if(StringUtils.isBlank(menu.getName())){
throw new RRException("菜单名称不能为空");
}
if(menu.getParentId() == null){
throw new RRException("上级菜单不能为空");
}
//菜单
if(menu.getType() == Constant.MenuType.MENU.getValue()){
if(StringUtils.isBlank(menu.getUrl())){
throw new RRException("菜单URL不能为空");
}
}
//上级菜单类型
int parentType = Constant.MenuType.CATALOG.getValue();
if(menu.getParentId() != 0){
SysMenuEntity parentMenu = sysMenuService.getById(menu.getParentId());
parentType = parentMenu.getType();
}
//目录、菜单
if(menu.getType() == Constant.MenuType.CATALOG.getValue() ||
menu.getType() == Constant.MenuType.MENU.getValue()){
if(parentType != Constant.MenuType.CATALOG.getValue()){
throw new RRException("上级菜单只能为目录类型");
}
return ;
}
//按钮
if(menu.getType() == Constant.MenuType.BUTTON.getValue()){
if(parentType != Constant.MenuType.MENU.getValue()){
throw new RRException("上级菜单只能为菜单类型");
}
return ;
}
* 系统配置信息
*
*/
@RestController
@RequestMapping("/sys/config")
public class SysConfigController extends AbstractController {
@Autowired
private SysConfigService sysConfigService;
/**
* 所有配置列表
*/
@GetMapping("/list")
@RequiresPermissions("sys:config:list")
public R list(@RequestParam Map<String, Object> params){
PageUtils page = sysConfigService.queryPage(params);
return R.ok().put("page", page);
}
/**
* 配置信息
*/
@GetMapping("/info/{id}")
@RequiresPermissions("sys:config:info")
public R info(@PathVariable("id") Long id){
SysConfigEntity config = sysConfigService.getById(id);
return R.ok().put("config", config);
}
/**
* 保存配置
*/
@SysLog("保存配置")
@PostMapping("/save")
@RequiresPermissions("sys:config:save")
public R save(@RequestBody SysConfigEntity config){
ValidatorUtils.validateEntity(config);
sysConfigService.saveConfig(config);
return R.ok();
}
/**
* 修改配置
*/
@SysLog("修改配置")
/**
* 异常处理器
*
*/
@RestControllerAdvice
public class RRExceptionHandler {
private Logger logger = LoggerFactory.getLogger(getClass());
/**
* 处理自定义异常
*/
@ExceptionHandler(RRException.class)
public R handleRRException(RRException e){
R r = new R();
r.put("code", e.getCode());
r.put("msg", e.getMessage());
return r;
}
@ExceptionHandler(NoHandlerFoundException.class)
public R handlerNoFoundException(Exception e) {
logger.error(e.getMessage(), e);
return R.error(404, "路径不存在,请检查路径是否正确");
}
@ExceptionHandler(DuplicateKeyException.class)
public R handleDuplicateKeyException(DuplicateKeyException e){
logger.error(e.getMessage(), e);
return R.error("数据库中已存在该记录");
}
@ExceptionHandler(AuthorizationException.class)
public R handleAuthorizationException(AuthorizationException e){
logger.error(e.getMessage(), e);
return R.error("没有权限,请联系管理员授权");
}
@ExceptionHandler(Exception.class)
public R handleException(Exception e){
logger.error(e.getMessage(), e);
return R.error();
}
}
/**
*/
package io.renren.modules.app.interceptor;
/**
* 权限(Token)验证
*
*/
@Component
public class AuthorizationInterceptor extends HandlerInterceptorAdapter {
@Autowired
private JwtUtils jwtUtils;
public static final String USER_KEY = "userId";
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
Login annotation;
if(handler instanceof HandlerMethod) {
annotation = ((HandlerMethod) handler).getMethodAnnotation(Login.class);
}else{
return true;
}
if(annotation == null){
return true;
}
//获取用户凭证
String token = request.getHeader(jwtUtils.getHeader());
if(StringUtils.isBlank(token)){
token = request.getParameter(jwtUtils.getHeader());
}
}
/**
* .
*
* Thm
*
* !
*/
package io.renren.modules.app.controller;
/**
* APP登录授权
*
*/
@RestController
@RequestMapping("/app")
@Api("APP登录接口")
public class AppLoginController {
@Autowired
private UserService userService;
@Autowired
private JwtUtils jwtUtils;
/**
* 登录
*/
@PostMapping("login")
@ApiOperation("登录")
public R login(@RequestBody LoginForm form){
//表单校验
ValidatorUtils.validateEntity(form);
//用户登录
long userId = userService.login(form);
ToworkApplyService.removeById(id);
}
return R.ok();
}
}
/**
* .
*
* Thm
*
* !
*/
package io.renren.modules.app.controller;
/**
* 注册
*
*/
@RestController
@RequestMapping("/app")
@Api("APP注册接口")
public class AppRegisterController {
@Autowired
private UserService userService;
@PostMapping("register")
@ApiOperation("注册")
public R register(@RequestBody RegisterForm form){
//表单校验
ValidatorUtils.validateEntity(form);
UserEntity user = new UserEntity();
user.setMobile(form.getMobile());
user.setUsername(form.getMobile());
if(claims == null || jwtUtils.isTokenExpired(claims.getExpiration())){
throw new RRException(jwtUtils.getHeader() + "失效,请重新登录", HttpStatus.UNAUTHORIZED.value());
}
//设置userId到request里,后续根据userId,获取用户信息
request.setAttribute(USER_KEY, Long.parseLong(claims.getSubject()));
return true;
}
}
/**
* .
*
* Thm
*
* !
*/
package io.renren.modules.sys.controller;
/**
* 系统配置信息
*
*/
@RestController
@RequestMapping("/sys/config")
public class SysConfigController extends AbstractController {
@Autowired
private SysConfigService sysConfigService;
/**
* 所有配置列表
*/
@GetMapping("/list")
@RequiresPermissions("sys:config:list")
public R list(@RequestParam Map<String, Object> params){
PageUtils page = sysConfigService.queryPage(params);
return R.ok().put("page", page);
}
/**
* 获取最原始的request
*/
public HttpServletRequest getOrgRequest() {
return orgRequest;
}
/**
* 获取最原始的request
*/
public static HttpServletRequest getOrgRequest(HttpServletRequest request) {
if (request instanceof XssHttpServletRequestWrapper) {
return ((XssHttpServletRequestWrapper) request).getOrgRequest();
}
return request;
}
}
/**
* .
*
* Thm
*
* !
*/
package io.renren.modules.sys.controller;
* 用户信息
*/
@GetMapping("/info/{userId}")
@RequiresPermissions("sys:user:info")
public R info(@PathVariable("userId") Long userId){
SysUserEntity user = sysUserService.getById(userId);
//获取用户所属的角色列表
List<Long> roleIdList = sysUserRoleService.queryRoleIdList(userId);
user.setRoleIdList(roleIdList);
return R.ok().put("user", user);
}
/**
* 保存用户
*/
@SysLog("保存用户")
@PostMapping("/save")
@RequiresPermissions("sys:user:save")
public R save(@RequestBody SysUserEntity user){
ValidatorUtils.validateEntity(user, AddGroup.class);
user.setCreateUserId(getUserId());
sysUserService.saveUser(user);
return R.ok();
}
/**
* 修改用户
*/
@SysLog("修改用户")
@PostMapping("/update")
@RequiresPermissions("sys:user:update")
public R update(@RequestBody SysUserEntity user){
ValidatorUtils.validateEntity(user, UpdateGroup.class);
user.setCreateUserId(getUserId());
sysUserService.update(user);
return R.ok();
}
@GetMapping("/info/{id}")
@RequiresPermissions("sys:config:info")
public R info(@PathVariable("id") Long id){
SysConfigEntity config = sysConfigService.getById(id);
return R.ok().put("config", config);
}
/**
* 保存配置
*/
@SysLog("保存配置")
@PostMapping("/save")
@RequiresPermissions("sys:config:save")
public R save(@RequestBody SysConfigEntity config){
ValidatorUtils.validateEntity(config);
sysConfigService.saveConfig(config);
return R.ok();
}
/**
* 修改配置
*/
@SysLog("修改配置")
@PostMapping("/update")
@RequiresPermissions("sys:config:update")
public R update(@RequestBody SysConfigEntity config){
ValidatorUtils.validateEntity(config);
sysConfigService.update(config);
return R.ok();
}
/**
* 删除配置
*/
@SysLog("删除配置")
@PostMapping("/delete")
@RequiresPermissions("sys:config:delete")
public R delete(@RequestBody Long[] ids){
sysConfigService.deleteBatch(ids);
/**
* 异常处理器
*
*/
@RestControllerAdvice
public class RRExceptionHandler {
private Logger logger = LoggerFactory.getLogger(getClass());
/**
* 处理自定义异常
*/
@ExceptionHandler(RRException.class)
public R handleRRException(RRException e){
R r = new R();
r.put("code", e.getCode());
r.put("msg", e.getMessage());
return r;
}
@ExceptionHandler(NoHandlerFoundException.class)
public R handlerNoFoundException(Exception e) {
logger.error(e.getMessage(), e);
return R.error(404, "路径不存在,请检查路径是否正确");
}
@ExceptionHandler(DuplicateKeyException.class)
public R handleDuplicateKeyException(DuplicateKeyException e){
logger.error(e.getMessage(), e);
return R.error("数据库中已存在该记录");
}
@ExceptionHandler(AuthorizationException.class)
public R handleAuthorizationException(AuthorizationException e){
logger.error(e.getMessage(), e);
return R.error("没有权限,请联系管理员授权");
}
@ExceptionHandler(Exception.class)
public R handleException(Exception e){
logger.error(e.getMessage(), e);
return R.error();
}
}
/**
* .
*
map.put("create_user_id", getUserId());
}
List<SysRoleEntity> list = (List<SysRoleEntity>) sysRoleService.listByMap(map);
return R.ok().put("list", list);
}
/**
* 角色信息
*/
@GetMapping("/info/{roleId}")
@RequiresPermissions("sys:role:info")
public R info(@PathVariable("roleId") Long roleId){
SysRoleEntity role = sysRoleService.getById(roleId);
//查询角色对应的菜单
List<Long> menuIdList = sysRoleMenuService.queryMenuIdList(roleId);
role.setMenuIdList(menuIdList);
return R.ok().put("role", role);
}
/**
* 保存角色
*/
@SysLog("保存角色")
@PostMapping("/save")
@RequiresPermissions("sys:role:save")
public R save(@RequestBody SysRoleEntity role){
ValidatorUtils.validateEntity(role);
role.setCreateUserId(getUserId());
sysRoleService.saveRole(role);
return R.ok();
}
/**
* 修改角色
*/
@SysLog("修改角色")
@PostMapping("/update")
@RequiresPermissions("sys:role:update")
public R update(@RequestBody SysRoleEntity role){
ValidatorUtils.validateEntity(role);
role.setCreateUserId(getUserId());
sysRoleService.update(role);
return R.ok();
}
/**
ossEntity.setCreateDate(new Date());
sysOssService.save(ossEntity);
return R.ok().put("url", url);
}
/**
* 删除
*/
@PostMapping("/delete")
@RequiresPermissions("sys:oss:all")
public R delete(@RequestBody Long[] ids){
sysOssService.removeByIds(Arrays.asList(ids));
return R.ok();
}
}
/**
* .
*
* Thm
*
* !
*/
package io.renren.modules.sys.oauth2;
/**
* oauth2过滤器
*
}
return R.ok();
}
}
/**
* .
*
* Thm
*
* !
*/
package io.renren.modules.app.controller;
/**
* 注册
*
*/
@RestController
@RequestMapping("/app")
@Api("APP注册接口")
return super.getInputStream();
}
//为空,直接返回
String json = IOUtils.toString(super.getInputStream(), "utf-8");
if (StringUtils.isBlank(json)) {
return super.getInputStream();
}
//xss过滤
json = xssEncode(json);
final ByteArrayInputStream bis = new ByteArrayInputStream(json.getBytes("utf-8"));
return new ServletInputStream() {
@Override
public boolean isFinished() {
return true;
}
@Override
public boolean isReady() {
return true;
}
@Override
public void setReadListener(ReadListener readListener) {
}
@Override
public int read() throws IOException {
return bis.read();
}
};
}
@Override
public String getParameter(String name) {
String value = super.getParameter(xssEncode(name));
if (StringUtils.isNotBlank(value)) {
value = xssEncode(value);
}
return value;
}
* 注册
*
*/
@RestController
@RequestMapping("/app")
@Api("APP注册接口")
public class AppRegisterController {
@Autowired
private UserService userService;
@PostMapping("register")
@ApiOperation("注册")
public R register(@RequestBody RegisterForm form){
//表单校验
ValidatorUtils.validateEntity(form);
UserEntity user = new UserEntity();
user.setMobile(form.getMobile());
user.setUsername(form.getMobile());
user.setPassword(DigestUtils.sha256Hex(form.getPassword()));
user.setCreateTime(new Date());
userService.save(user);
return R.ok();
}
}
/**
* .
*
* Info
*
* !
*/
package io.renren.modules.sys.controller;
SysLog syslog = method.getAnnotation(SysLog.class);
if(syslog != null){
//注解上的描述
sysLog.setOperation(syslog.value());
}
//请求的方法名
String className = joinPoint.getTarget().getClass().getName();
String methodName = signature.getName();
sysLog.setMethod(className + "." + methodName + "()");
//请求的参数
Object[] args = joinPoint.getArgs();
try{
String params = new Gson().toJson(args);
sysLog.setParams(params);
}catch (Exception e){
}
//获取request
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
//设置IP地址
sysLog.setIp(IPUtils.getIpAddr(request));
//用户名
String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername();
sysLog.setUsername(username);
sysLog.setTime(time);
sysLog.setCreateDate(new Date());
//保存系统日志
sysLogService.save(sysLog);
}
}
/**
* .
*
* Thm
*
* !
*/
package io.renren.modules.app.interceptor;
String json = new Gson().toJson(R.error(HttpStatus.SC_UNAUTHORIZED, "invalid token"));
httpResponse.getWriter().print(json);
return false;
}
return executeLogin(request, response);
}
@Override
protected boolean onLoginFailure(AuthenticationToken token, AuthenticationException e, ServletRequest request, ServletResponse response) {
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setContentType("application/json;charset=utf-8");
httpResponse.setHeader("Access-Control-Allow-Credentials", "true");
httpResponse.setHeader("Access-Control-Allow-Origin", HttpContextUtils.getOrigin());
try {
//处理登录失败的异常
Throwable throwable = e.getCause() == null ? e : e.getCause();
R r = R.error(HttpStatus.SC_UNAUTHORIZED, throwable.getMessage());
String json = new Gson().toJson(r);
httpResponse.getWriter().print(json);
} catch (IOException e1) {
}
return false;
}
/**
* 获取请求的token
*/
private String getRequestToken(HttpServletRequest httpRequest){
//从header中获取token
String token = httpRequest.getHeader("token");
//如果header中不存在token,则从参数中获取token
if(StringUtils.isBlank(token)){
token = httpRequest.getParameter("token");
}
return token;
}
}
/**
* .
*
* Thm