Salut mes amis
Je suis entrain de réalisé un projet de spring j'ai une classe de Personne
et la l'interface IPersonneRepository
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 @SuppressWarnings("serial") @Entity public class Personne implements Serializable { @Id @GeneratedValue private Long id; @Column(length = 80, name = "NOM") private String nom; @Column(length = 80, name = "PRENOM") private String prenom; @Column(length = 80, name = "ADRESSE") private String adresse; @Column(length = 80, name = "EMAIL") private String email; @Column(length = 80, name = "TELEPHONE") private String telephone; //avec les getters et le setters et le constructeurs sans et avec parametres
Et le controlleur de personne sous le nom de PersonneController qui définit les methode d'ajout, Modification, Suppression avec l'affichage de toute les personnes
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 import com.example.entities.Personne; public interface IPersonneRepository extends JpaRepository<Personne, Long> { }
je ne sais pas où du le problème? Pourquoi m'afficher ce message d'erreur sur tout les commandes de findOne "The method findOne(Example<S>) in the type QueryByExampleExecutor<Personne> is not applicable for the arguments (Long)" Malgré que j'ai déjà utilisé le getOne() au lieu de findOne() qui ne me donne pas la même requête pour me recevoir une personne.
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 import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.example.entities.Personne; import com.example.repositories.IPersonneRepository; @RestController @RequestMapping(value = "/personne") public class PersonController { @Autowired private IPersonneRepository iPersonneRepository; @PostMapping(value = "/create") public Personne createPersonne(@RequestBody Personne personne) { return iPersonneRepository.save(personne); } @PutMapping(value = "/update/{id}") public Personne updatePersonne(@PathParam(value = "id") Long id, @RequestBody Personne personne) { if (id != null) { Personne p = iPersonneRepository.findOne(id); if (p != null) { iPersonneRepository.save(personne); } } return personne; } @DeleteMapping(value = "/delete/{id}") public void delete(@PathParam(value = "id") Long id) { if (id != null) { Personne p = iPersonneRepository.findOne(id); if (p != null) { iPersonneRepository.delete(p); } } } @GetMapping(value = "/all") public List<Personne> allPerson() { return iPersonneRepository.findAll(); } @GetMapping(value = "/per/{id}") public Personne getOne(@PathParam(value = "id") Long id) { if (id != null) { Personne p = iPersonneRepository.findOne(id); return p; } } }
Aider moi SVP
Partager