登录控制

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;
@ -21,43 +23,46 @@ import com.cya.service.impl.LoginServiceImpl;
@Controller @Controller
@ResponseBody @ResponseBody
public class LoginController { public class LoginController {
@Autowired @Autowired
private ILoginService loginServiceImpl; //注入ILoginService实现类 private ILoginService loginServiceImpl;
@RequestMapping("login") //验证用户信息 // 处理登录请求
public List login(HttpServletRequest request, @RequestBody Login login) { @RequestMapping("login")
List list=loginServiceImpl.login(login); public List login(HttpServletRequest request, @RequestBody Login login) {
if(list.size()==1) { //如果验证通过,返回信息列表 List list=loginServiceImpl.login(login);
HttpSession session=request.getSession(); if(list.size()==1) {
session.setAttribute(login.getRole(), list); HttpSession session=request.getSession();
System.out.println("session="+session.getAttribute(login.getRole())); session.setAttribute(login.getRole(), list);
} System.out.println("session="+session.getAttribute(login.getRole()));
return list; }
} return list;
}
@RequestMapping("getSession") //获取指定用户的信息,并返回信息列表
public List getSession(HttpServletRequest request,@RequestBody Login login){ // 获取会话信息
System.out.println(login); @RequestMapping("getSession")
System.out.println(request.getSession().getAttribute(login.getRole())); public List getSession(HttpServletRequest request,@RequestBody Login login){
List list=new ArrayList<>(); System.out.println(login);
list.add(request.getSession().getAttribute(login.getRole())); System.out.println(request.getSession().getAttribute(login.getRole()));
return list; List list=new ArrayList<>();
} list.add(request.getSession().getAttribute(login.getRole()));
return list;
@RequestMapping("exitSys") //移除指定用户信息 }
public Result exitSys(HttpServletRequest request) {
String exit=""; // 退出系统
try { @RequestMapping("exitSys")
if(request.getParameter("exit")!=null) { public Result exitSys(HttpServletRequest request) {
exit=request.getParameter("exit"); String exit="";
} try {
request.getSession().removeAttribute(exit); if(request.getParameter("exit")!=null) {
return new Result(true, "注销成功"); exit=request.getParameter("exit");
} catch (Exception e) { }
// TODO: handle exception request.getSession().removeAttribute(exit);
e.printStackTrace(); return new Result(true, "注销成功");
return new Result(false, "注销失败"); } catch (Exception e) {
} // TODO: 处理异常
} e.printStackTrace();
return new Result(false, "注销失败");
}
}
} }
Loading…
Cancel
Save