foreach不是只能遍历不能修改么,为何以下代码会生效?
public void updateNum(Long itemId, Long num, HttpServletRequest request, HttpServletResponse response) {
List<Cart> carts = queryCartList(request);
// 判断购物车是否有商品
for (Cart c : carts) {
if (c.getItemId().longValue() == itemId.longValue()) {
c.setNum(num.intValue());
c.setUpdated(new Date());
break;
}
}
try {
CookieUtils.setCookie(request, response, COOKIE_NAME, MAPPER.writeValueAsString(carts), COOKIE_TIME, true);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
长风秋雁
蝴蝶不菲
撒科打诨
MYYA
沧海一幻觉
有只小跳蛙
相关分类