Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How do I display the number of clients that placed an order for a particular product?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 272
    Answer it

    I'm a beginner in java and I want to display the number of clients that placed an order for a particular product on my MVC WebApp. I came up with a logical way of doing this but I stumbled upon a dead end.

    Here's what I tried to do. Any help would be greatly appreciated.


     public String Home15(Model model,  @PathVariable("id") int id, HttpServletRequest request, @Valid User user) {
        HttpSession session = request.getSession(false);
        if (session != null) {
            for(User user_: userRepository.verify(session.getAttribute("email"), session.getAttribute("password"))) {
            model.addAttribute("num_clients", orderRepository.countClientById(?)); //'?'<- All I need is this value
                    //These codes are not relevant. Please ignore.
                    //For originality purpose
                    model.addAttribute("num", productRepository.countProductById(id) + " Produtos");
                    model.addAttribute("users_cat", categoryRepository.findById(id));
                    model.addAttribute("name", user_.getName());
                    model.addAttribute("users", productRepository.findProductByCategoryId(id));
                else {
                    return "redirect:/index";
                return "/produtos-crud/produtos-da-categoria-admin";


    public interface OrderRepository extends CrudRepository<Pedido, Integer> {
    @Query(value = "SELECT COUNT(client) FROM order WHERE product = ?;", nativeQuery = true)
        int countClientById(int ?); //Feel free to set a variable


    <!DOCTYPE html>
    <meta charset="UTF-8">
    <title>Category Items</title>
    <meta content="Dashboard" property="og:title">
    <meta content="Dashboard" property="twitter:title">
    <meta content="width=device-width, initial-scale=1" name="viewport">
    <meta content="Webflow" name="generator">
    <link href="css/normalize.css" rel="stylesheet" type="text/css">
    <link href="css/webflow.css" rel="stylesheet" type="text/css">
    <link href="css/ui-login-teste.webflow.css" rel="stylesheet" type="text/css">
       <!-- Irrelevant codes have been removed for to shorten code--> 
      <div class="valida-table-field estatuto">
         <div th:text="${num_clients}">14</div> <!-- Main focus -->

 0 Answer(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: