springboot封装JsonUtil,CookieUtil工具类
2020-12-13 15:09
标签:mapper cookie null str cep equals eval class proc yls springboot封装JsonUtil,CookieUtil工具类 标签:mapper cookie null str cep equals eval class proc 原文地址:https://www.cnblogs.com/yloved/p/11574251.htmlspringboot封装JsonUtil,CookieUtil工具类
2019-9-23
public class JsonUtil {
private static ObjectMapper objectMapper = new ObjectMapper();
public static String objectToString(Object object) throws JsonProcessingException {
return objectMapper.writeValueAsString(object);
}
public static
public class CookieUtil {
public static String getCookie(HttpServletRequest request, String cookieName){
Cookie[] cookies = request.getCookies();
if(cookies != null){
for(Cookie cookie : cookies){
if(cookie.getName().equals(cookieName)){
return cookie.getValue();
}
}
}
return null;
}
public static void setCookie(HttpServletResponse response, String cookieName, String value,int cookieMaxAge){
Cookie cookie = new Cookie(cookieName,value);
cookie.setPath("/");
cookie.setMaxAge(cookieMaxAge);
response.addCookie(cookie);
}
public static void deleteCookie(HttpServletResponse response, String cookieName){
setCookie(response,cookieName,null,0);
}
}
上一篇:java.3
下一篇:STL源码剖析:算法
文章标题:springboot封装JsonUtil,CookieUtil工具类
文章链接:http://soscw.com/essay/34834.html