简体   繁体   中英

how i can remove object from shopping cart with boolean method?

i have problem. i have project to do and i have to make boolean method for remove book from the cart

i tried this

in my cart model

    public boolean supprimer(String isbn)
    {

        List<LivreAchete> listelivre = (List<LivreAchete>) request.getSession().getAttribute("panier");
        listelivre = this.getListe();

        if(listelivre.removeIf((e)->e.getIsbn().equals(livre.getIsbn())))
        {

            request.getSession().setAttribute("panier",listelivre);
            return true;

        }
        else
            return false;   

    }

and in my controller

@RequestMapping(value="/librairie/supprimerLivre/{isbn}", method = RequestMethod.GET)
public String supprimerLivre(@PathVariable("isbn") String isbn, HttpServletRequest request){
    try{
     gestPanier = new GestPanier(request);
      //rechercher le livre qui correspond a l'isbn passer en parametre
     //LivreAchete livre = gestPanier.getListe().stream().filter(c -> c.getIsbn().equals(isbn)).findFirst().get();
    //supprimer le livre
    gestPanier.supprimer(isbn);
    return "redirect:/librairie/afficherPanier";  
    }
    catch(Exception ex){
        return "redirect:/librairie/"Error"
    }
}

but when i run my project and i try to delete book its dont work can someone help me to find my mistake please?

It's kind of hard to see what is going on since we cannot see the rest of your classes, but my first impression is that this code here does not make sense:

List<LivreAchete> listelivre = (List<LivreAchete>)request.getSession().getAttribute("panier");
listelivre = this.getListe();

You are initializing a reference of List of LivreAchete to the session attribute, and then directly after that you are setting this newly declared listelivre to the return value of getList().

I would take a closer look at this section of code, but it's hard for me to tell what your intention is with this code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM