int id = Integer.parseInt(request.getParameter("id"));
HttpSession session = request.getSession();
List<BookInfoDto> bookList = (List<BookInfoDto>)session.getAttribute("bookList");
for(int i = 0; i < bookList.size();i++){
if(bookList.get(i).getId() == id){
session.removeAttribute("bookList");
}
}
从页面获取id值,再对id所对应的信息进行删除。我这样是删除session里的全部信息了。请问该怎么改才能删除id所对应的信息。
------解决方案--------------------
int id = Integer.parseInt(request.getParameter("id"));
HttpSession session = request.getSession();
List<BookInfoDto> bookList = (List<BookInfoDto>)session.getAttribute("bookList");
for(int i = 0; i < bookList.size();i++){
if(bookList.get(i).getId() == id){
boolList.remove(i);
session.setAttribute("bookList",bookList);
break;
}
}
------解决方案--------------------
id是在bookList里面封装的,所以应该是对bookList对象进行操作才行
- Java code
int id = Integer.parseInt(request.getParameter("id"));HttpSession session = request.getSession();List<BookInfoDto> bookList = (List<BookInfoDto>)session.getAttribute("bookList");for(int i = 0; i < bookList.size();i++){if(bookList.get(i).getId() == id){ bookList.remove(i);}}