@RequestMapping(value="/book.do")//点击时
public String book(Integer id,ModelMap map,HttpSession session){
// 浏览历史
Goods good = goodService.getGoodById(id);
if (id != null) {
LinkedList<Goods> list=(LinkedList<Goods>) session.getAttribute("goods");
if(list==null){
list=new LinkedList<Goods>();
}
boolean isnottrue=true; //假设浏览历史中不存在!
for (Goods pro:list) {
if(pro.getId()==good.getId()){
isnottrue=false; //在浏览历史中存在;
break;
}
}
if(isnottrue){
if(list.size()==4){
list.removeLast();
list.addFirst(good);
}else{
list.addFirst(good);
}
}
session.setAttribute("goods", list);
}
String[] author=good.getAuthor().split(",");
map.put("good", good);
map.put("authors", author);
return "book";
}else{
return "forward:index.do";
}
}//以上是控制器代码