81,095
社区成员
发帖
与我相关
我的任务
分享
ObjectMapper om = new ObjectMapper();
om.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
//购物车对象转Json
//对象转Json 写过程
StringWriter json = new StringWriter();
try {
om.writeValue(json, buyCart);
} catch(IOException e) {
e.printStackTrace();
}
//购物车装进Cookie
Cookie cookie = new Cookie(Constants.BUYCART_COOKIE, json.toString());
System.out.println(json);
System.out.println(json.toString());
//关闭浏览器也要有Cookie
cookie.setMaxAge(3600 * 24);
cookie.setPath("/");
response.addCookie(cookie);