This commit is contained in:
2020-04-16 01:53:25 +08:00
parent b1ded445bf
commit a05953ec75
4 changed files with 82 additions and 26 deletions

View File

@@ -0,0 +1,15 @@
package com.yutou.tools.utils;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
public class Tools {
public static Cookie getCookie(HttpServletRequest request,String key){
for (Cookie cookie : request.getCookies()) {
if(cookie.getName().equals(key)){
return cookie;
}
}
return null;
}
}

View File

@@ -0,0 +1,23 @@
package com.yutou.tools.web;
import com.alibaba.fastjson.JSONObject;
import com.yutou.tools.utils.Tools;
import org.springframework.stereotype.Controller;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
@Controller
public class userController {
public String getLoginState(HttpServletRequest request){
JSONObject json=new JSONObject();
Cookie cookie= Tools.getCookie(request,"user");
if(cookie==null){
json.put("code",-1);
json.put("msg","未登录");
return json.toJSONString();
}
return "";
}
}