登录控制

main
王祎程 11 months ago
parent 8eb889e0bf
commit c37e0d899d

@ -1,8 +1,10 @@
package com.controller; package com.cya.controller;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.management.relation.Role;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
@ -23,12 +25,13 @@ import com.cya.service.impl.LoginServiceImpl;
public class LoginController { public class LoginController {
@Autowired @Autowired
private ILoginService loginServiceImpl; //注入ILoginService实现类 private ILoginService loginServiceImpl;
@RequestMapping("login") //验证用户信息 // 处理登录请求
@RequestMapping("login")
public List login(HttpServletRequest request, @RequestBody Login login) { public List login(HttpServletRequest request, @RequestBody Login login) {
List list=loginServiceImpl.login(login); List list=loginServiceImpl.login(login);
if(list.size()==1) { //如果验证通过,返回信息列表 if(list.size()==1) {
HttpSession session=request.getSession(); HttpSession session=request.getSession();
session.setAttribute(login.getRole(), list); session.setAttribute(login.getRole(), list);
System.out.println("session="+session.getAttribute(login.getRole())); System.out.println("session="+session.getAttribute(login.getRole()));
@ -36,7 +39,8 @@ public class LoginController {
return list; return list;
} }
@RequestMapping("getSession") //获取指定用户的信息,并返回信息列表 // 获取会话信息
@RequestMapping("getSession")
public List getSession(HttpServletRequest request,@RequestBody Login login){ public List getSession(HttpServletRequest request,@RequestBody Login login){
System.out.println(login); System.out.println(login);
System.out.println(request.getSession().getAttribute(login.getRole())); System.out.println(request.getSession().getAttribute(login.getRole()));
@ -45,7 +49,8 @@ public class LoginController {
return list; return list;
} }
@RequestMapping("exitSys") //移除指定用户信息 // 退出系统
@RequestMapping("exitSys")
public Result exitSys(HttpServletRequest request) { public Result exitSys(HttpServletRequest request) {
String exit=""; String exit="";
try { try {
@ -55,7 +60,7 @@ public class LoginController {
request.getSession().removeAttribute(exit); request.getSession().removeAttribute(exit);
return new Result(true, "注销成功"); return new Result(true, "注销成功");
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: 处理异常
e.printStackTrace(); e.printStackTrace();
return new Result(false, "注销失败"); return new Result(false, "注销失败");
} }

Loading…
Cancel
Save