Ejemplo n.º 1
0
  @RequestMapping(value = "/book/{bookid}", method = RequestMethod.GET)
  public String BookInfo(@PathVariable Integer bookid, Model model, HttpServletRequest request)
      throws JsonGenerationException, JsonMappingException, IOException {

    logger.info("----查看图书信息----");
    // 根据图书id获取图书信息
    Book book = bookService.selectBook(bookid);
    // 图书图书分类获取图书分类目录,,形成面包屑导航
    int classify = book.getBookclassid();
    List<Class> classlist = new ArrayList<Class>();
    Class classify2 = new Class();
    while (classify != 0) {
      classify2 = classifyService.SelectTwoClassify(classify);
      classify = classify2.getClassfatherid();
      classlist.add(classify2);
    }
    // 获取bookid和userid 判断用户之前是否已经收藏过该书
    //		 String userid=new String();
    //		 Cookie[]  cookies=  request.getCookies();
    //		 for(Cookie c:cookies){
    //			 if(c.getName().equals("userid")){
    //				 userid= c.getValue();
    //			 }
    //		 }

    User user = (User) request.getSession().getAttribute("user");
    System.out.println(user);
    if (user != null) {
      boolean valiCollect = collectService.selectCollect(bookid, user.getUserid());
      System.out.println(valiCollect);
      model.addAttribute("valiCollect", valiCollect);
    } else {
      model.addAttribute("valiCollect", null);
    }

    // 获取该书的评论
    List<CommentWapper> commentlist = commentWapperService.selectCommentByBookId(bookid);
    ObjectMapper mapper = new ObjectMapper();
    logger.info(mapper.writeValueAsString(classlist));
    // 反序
    Collections.reverse(classlist);
    logger.info(mapper.writeValueAsString(classlist));
    System.out.println("commentlist" + commentlist);
    logger.info("commentlist" + mapper.writeValueAsString(commentlist));
    model.addAttribute("classlist", classlist);
    model.addAttribute("book", book);
    model.addAttribute("commentlist", commentlist);
    return "home/book";
  }
Ejemplo n.º 2
0
 /**
  * 修改图书,图书回显
  *
  * @param model
  * @param id
  * @return
  * @throws JsonGenerationException
  * @throws JsonMappingException
  * @throws IOException
  */
 @RequestMapping(value = "/Book/{id}", method = RequestMethod.GET)
 public String modifyBook(Model model, @PathVariable Integer id)
     throws JsonGenerationException, JsonMappingException, IOException {
   logger.info("-----修改图书:id为" + id + "-----");
   Book book = bookService.selectBook(id);
   if (book != null) {
     ObjectMapper mapper = new ObjectMapper();
     System.out.println("输出原本的图书");
     logger.info(mapper.writeValueAsString(book));
     model.addAttribute(book);
   } else {
     logger.info("传入的id为:" + id + "修改失败,该书不存在");
   }
   return "book/modifyBook";
 }