Un probleme dans la Methode DELETE dans une RESTful web service avec Spring 3 mvc ...
Jais besoin de resoudre ce probleme
on a la Connextion
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 public Connection connexion() throws SQLException{ String url = "jdbc:mysql://localhost:3306/etud"; Connection con = DriverManager.getConnection(url,"root",""); return con; }
on a Le CONTROLEUR
Code : 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 package com.tp.controller; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import com.tp.model.Etudiant; import com.tp.service.EtudiantService; // @RestController annotation, which marks the class as a controller @RestController @RequestMapping("etudiants") @EnableAutoConfiguration public class EtudiantController { @RequestMapping(value = {"/supprimer/{idDeleted}"}, method = RequestMethod.DELETE) public void supprimer(@PathVariable("idDeleted") int numEtud ) throws ClassNotFoundException, SQLException { Etudiant etudiant = new Etudiant(); try { Connection con = etudiantService.connexion(); Statement stSupp = con.createStatement() ; stSupp.executeUpdate("DELETE FROM etudiant WHERE id="+etudiant.getId() ); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } }
ona la classe de resourece ETUDIANT
Code : 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 package com.tp.model; public class Etudiant { // attributes int id; private String nom; private String prenom; private String sexe; private String mail; private String nationalite; private String langue; private String codePostal; private String numTel; private String dateNaissance; private String Address; // getter and setter public int getId() { return id; } public void setId(int id) { this.id = id; } //@Column(name="nom",nullable=false,updatable=false) 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 getSexe() { return sexe; } public void setSexe(String sexe) { this.sexe = sexe; } public String getMail() { return mail; } public void setMail(String mail) { this.mail = mail; } public String getNationalite() { return nationalite; } public void setNationalite(String nationalite) { this.nationalite = nationalite; } public String getLangue() { return langue; } public void setLangue(String langue) { this.langue = langue; } public String getCodePostal() { return codePostal; } public void setCodePostal(String codePostal) { this.codePostal = codePostal; } public String getNumTel() { return numTel; } public void setNumTel(String numTel) { this.numTel = numTel; } public String getDateNaissance() { return dateNaissance; } public void setDateNaissance(String dateNaissance) { this.dateNaissance = dateNaissance; } public String getAddress() { return Address; } public void setAddress(String address) { Address = address; } }
et quand je test ... l'operation et valide
Code : 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 package com.tp.service; import java.sql.SQLException; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @Configuration @ComponentScan(basePackages={"com.tp.controller"}) @EnableAutoConfiguration public class WebServiceMain { public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException { SpringApplication.run(WebServiceMain.class, args); } }
Mais le probleme est : Aucun modification a labase de donnee et aucun erreur apparaite !!!!!!!!!
Aidez moi svp
Merci
Partager