IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Boot Java Discussion :

Envoyer des données du controleur vers la jstl


Sujet :

Spring Boot Java

  1. #1
    Membre actif
    Inscrit en
    Juin 2005
    Messages
    578
    Détails du profil
    Informations forums :
    Inscription : Juin 2005
    Messages : 578
    Points : 240
    Points
    240
    Par défaut Envoyer des données du controleur vers la jstl
    Bonjour

    J'ai 2 tables Client et Commande où un client peut passer plusieurs commandes.

    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
     
    package com.maidanda.model;
     
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.Table;
     
     
    @Entity
    @Table(name = "CLIENT")
    public class Client {
     
    	@Id
    	@GeneratedValue(strategy = GenerationType.IDENTITY)
    	@Column(name = "ID_CLIENT", updatable = false, nullable = false)
    	private long idClient;
     
    	@Column(name = "NOM",  insertable=true, updatable=true, nullable=true)
    	private String nom;
     
    	@Column(name = "PRENOM",  insertable=true, updatable=true, nullable=true)
    	private String prenom;
     
    	@Column(name = "TEL",  insertable=true, updatable=true, nullable=true)
    	private String tel;
     
    	@Column(name = "POITRINE", insertable=true, updatable=true, nullable=true)
    	private String poitrine;	
     
    	@Column(name = "HANCHE", insertable=true, updatable=true, nullable=true)
    	private String hanche;	
     
    	@Column(name = "MANCHE_LONGUE", insertable=true, updatable=true, nullable=true)
    	private String mancheLongue;
     
    	@Column(name = "MANCHE_COURTE", insertable=true, updatable=true, nullable=true)
    	private String mancheCourte;
     
    	@Column(name = "COU", insertable=true, updatable=true, nullable=true)
    	private String cou;
     
     
    	public Client() {
    		super();
    	}
     
    	public Client(String nom, String prenom, String tel,  String poitrine, String hanche, String mancheLongue,  String mancheCourte, String cou, boolean isDone) {
    		super();
    		this.nom = nom;
    		this.prenom = prenom;
    		this.tel = tel;		
    		this.poitrine = poitrine;
    		this.hanche = hanche;
    		this.mancheLongue = mancheLongue;
    		this.mancheCourte = mancheCourte;
    		this.cou = cou;
    	}
     
    	public long getIdClient() {
    		return idClient;
    	}
     
    	public void setIdClient(long idClient) {
    		this.idClient = idClient;
    	}
     
    	public String getNom() {
    		return nom;
    	}
     
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
     
    	public String getPrenom() {
    		return prenom;
    	}
     
    	public void setPrenom(String prenom) {
    		this.prenom = prenom;
    	}
     
    	public String getTel() {
    		return tel;
    	}
     
    	public void setTel(String tel) {
    		this.tel = tel;
    	}
     
     
    	public String getPoitrine() {
    		return poitrine;
    	}
     
    	public void setPoitrine(String poitrine) {
    		this.poitrine = poitrine;
    	}
     
    	public String getHanche() {
    		return hanche;
    	}
     
    	public void setHanche(String hanche) {
    		this.hanche = hanche;
    	}
     
    	public String getMancheLongue() {
    		return mancheLongue;
    	}
     
    	public void setMancheLongue(String mancheLongue) {
    		this.mancheLongue = mancheLongue;
    	}
     
    	public String getMancheCourte() {
    		return mancheCourte;
    	}
     
    	public void setMancheCourte(String mancheCourte) {
    		this.mancheCourte = mancheCourte;
    	}
     
    	public String getCou() {
    		return cou;
    	}
     
    	public void setCou(String cou) {
    		this.cou = cou;
    	}
     
    }

    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
     
    package com.maidanda.model;
     
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.persistence.Table;
     
    import com.maidanda.model.Client;
     
     
    @Entity
    @Table(name = "COMMANDE")
    public class Commande {
     
    	@Id
    	@GeneratedValue(strategy = GenerationType.IDENTITY)
    	@Column(name = "ID_COMMANDE", updatable = false, nullable = false)
    	private long idCommande;
     
    	@ManyToOne
        @JoinColumn(name="ID_CLIENT", nullable=false)
        private Client client;
     
    	@ManyToOne
        @JoinColumn(name="ID_MODELE", nullable=false)
        private Modele modele;
     
    	@Column(name = "COUPE",  insertable=true, updatable=true, nullable=false)
    	private String coupe;
     
    	@Column(name = "NOMBRE",  insertable=true, updatable=true, nullable=false)
    	private int nombre;	
     
    	@Column(name = "AVANCE",  insertable=true, updatable=true, nullable=false)
    	private String avance;	
     
    	@Column(name = "PRIX", insertable=true, updatable=true, nullable=true)
    	private String prix;
     
    	@Column(name = "DATE_COMMANDE", insertable=true, updatable=true, nullable=true)
    	private String dateCommande;	
     
    	@Column(name = "RDV", insertable=true, updatable=true, nullable=true)
    	private String rdv;	
     
    	@Column(name = "STATUT_COUTURE", insertable=true, updatable=true, nullable=true)
    	private String statutCouture;	
     
    	@Column(name = "STATUT_CONTACT_CLIENT", insertable=true, updatable=true, nullable=true)
    	private String statutContactClient;	
     
    	@Column(name = "STATUT_Paiement", insertable=true, updatable=true, nullable=true)
    	private String statutPaiement;	
     
    	public Commande() {
    		super();
    	}
     
    	public Commande(String coupe, String avance, int nombre,  String prix, String dateCommande, String rdv, String statutCouture,String statutContactClient, String statutPaiement, boolean isDone) {
    		super();
    		this.coupe = coupe;
    		this.avance = avance;
    		this.nombre = nombre;		
    		this.prix = prix;
    		this.dateCommande = dateCommande;	
    		this.rdv = rdv;	
    		this.statutCouture = statutCouture;	
    		this.statutContactClient = statutContactClient;	
    		this.statutPaiement = statutPaiement;
    	}
     
    	public long getIdCommande() {
    		return idCommande;
    	}
     
    	public void setIdCommande(long idCommande) {
    		this.idCommande = idCommande;
    	}
     
     
    	public String getCoupe() {
    		return coupe;
    	}
     
    	public void setCoupe(String coupe) {
    		this.coupe = coupe;
    	}
     
    	public String getAvance() {
    		return avance;
    	}
     
    	public void setAvance(String avance) {
    		this.avance = avance;
    	}
     
    	public int getNombre() {
    		return nombre;
    	}
     
    	public void setNombre(int nombre) {
    		this.nombre = nombre;
    	}
     
     
    	public String getPrix() {
    		return prix;
    	}
     
    	public void setPrix(String prix) {
    		this.prix = prix;
    	}
     
    	public String getDateCommande() {
    		return dateCommande;
    	}
     
    	public void setDateCommande(String dateCommande) {
    		this.dateCommande = dateCommande;
    	}
     
    	public String getRdv() {
    		return rdv;
    	}
     
    	public void setRdv(String rdv) {
    		this.rdv = rdv;
    	}
     
    	public String getStatutCouture() {
    		return statutCouture;
    	}
     
    	public void setStatutCouture(String statutCouture) {
    		this.statutCouture = statutCouture;
    	}
     
    	public String getStatutContactClient() {
    		return statutContactClient;
    	}
     
    	public void setStatutContactClient(String statutContactClient) {
    		this.statutContactClient = statutContactClient;
    	}
     
    	public String getStatutPaiement() {
    		return statutPaiement;
    	}
     
    	public void setStatutPaiement(String statutPaiement) {
    		this.statutPaiement = statutPaiement;
    	}
     
    	public Client getClient() {
    		return client;
    	}
    	public void setClient(Client client) {
    		this.client = client;
    	}
     
    	public Modele getModele() {
    		return modele;
    	}
    	public void setModele(Modele modele) {
    		this.modele = modele;
    	}
     
    }

    J'arrive à afficher la liste des clients dont les commandes sont soldées en faisant ceci:

    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     @Query("FROM Client WHERE idClient IN (select c.client.idClient from Commande c where statutPaiement= 'non soldé')")
    	 List<Client> findListeClientByCmdNonSoldee();

    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    	@RequestMapping(value = "/liste-commande-par-client", method = RequestMethod.GET)
    	public String showCmdsByClient(ModelMap commande, HttpSession session) {
     
    		commande.put("clients", clientService.findListeClientByCmdNonSoldee());
     
    		return "liste-commande-par-client";
    	}

    Code jstl : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    <table id="myTable" class="display compact table table-striped table-bordered" style="width:100%">
                                                    <thead>
                                                        <tr>
                                                            <th>#</th>
                                                            <th>Nom</th>
                                                            <th>Prénom</th>
                                                            <th>Téléphone</th>
                                                            <th>Nbr commande</th>
                                                            <th>Total à payer</th>                                                        
                                                            <th>Avance</th>
                                                            <th>Reste</th>                                                        
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <c:forEach items="${clients}" var="client" varStatus="boucle">
                                                        <tr>
                                                            <td>${boucle.count}</td>
                                                        	<td>${client.nom}</td>
                                                        	<td>${client.prenom}</td>
                                                        	<td>${client.tel}</td>
                                                        	<td></td>
                                                        	<td></td>
                                                        	<td></td>
                                                        	<td></td>
                                                        </tr>
                                                      </c:forEach>
                                                    </tbody>
                                                    <tfoot>
                                                        <tr>
                                                            <th>#</th>
                                                            <th>Nom</th>
                                                            <th>Prénom</th>
                                                            <th>Téléphone</th>
                                                            <th>Nbr commande</th>
                                                            <th>Total à payer</th>                                                        
                                                            <th>Avance</th>
                                                            <th>Reste</th>
                                                        </tr>
                                                    </tfoot>
                                                </table>

    Et voici le résultat:

    Nom : tablo.PNG
Affichages : 66
Taille : 30,9 Ko

    Le problème est que j'aimerai afficher pour chaque client toutes les commandes qu'il a passées (somme de toutes les commandes) ainsi que le prix total.

    Merci

  2. #2
    Membre actif
    Inscrit en
    Juin 2005
    Messages
    578
    Détails du profil
    Informations forums :
    Inscription : Juin 2005
    Messages : 578
    Points : 240
    Points
    240
    Par défaut
    C'est bon j'ai trouvé:

    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    @RequestMapping(value = "/liste-commande-par-client", method = RequestMethod.GET)
    	public String showCmdsByClient(ModelMap commande, HttpSession session) {
     
    		commande.put("clients", clientService.findListeClientByCmdNonSoldee());
     
    		for (Client c : clientService.findListeClientByCmdNonSoldee()) {
    			commande.addAttribute("monClient", commandeService.findNbreCmdByIdClient(c.getIdClient()));
    		}
     
    		return "liste-commande-par-client";
    	}

    Code jstl : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
     
    <tbody>
      <c:forEach items="${clients}" var="client" varStatus="boucle">
    	<tr>
    		<td>${boucle.count}</td>
    		<td>${client.nom}</td>
    		<td>${client.prenom}</td>
    		<td>${client.tel}</td>
    		<td>
    		 <c:set var = "test">
    			 <c:out value="${monClient}" />
    		 </c:set>
    		 <c:out value="${test}" />
    	  </td>
    		<td></td>
    		<td></td>
    		<td></td>
    	</tr>
      </c:forEach>
    </tbody>

Discussions similaires

  1. envoyer des données d'android vers un serveur
    Par jasmine jas dans le forum API standards et tierces
    Réponses: 3
    Dernier message: 20/07/2016, 02h08
  2. Envoyer des données de Odoo vers un logiciel de ecommerce
    Par oitsuki dans le forum Odoo (ex-OpenERP)
    Réponses: 1
    Dernier message: 15/01/2015, 11h11
  3. comment utiliser cURL dans php pour envoyer des données de php vers application android
    Par myaset dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 0
    Dernier message: 15/04/2013, 13h44
  4. envoyer des données de flash vers mysql
    Par maxland dans le forum Flash
    Réponses: 3
    Dernier message: 22/01/2009, 15h01
  5. envoyer des informations du controleur vers la vue
    Par leon1983 dans le forum Servlets/JSP
    Réponses: 1
    Dernier message: 22/05/2008, 15h36

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo