登录控制

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