Bonjour,
voici une table de donnée qui contient le nom des routes et sa cléf étrangère:
Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 select * from matiere; +----+--------------+---------+-------------+ | id | name_matiere | route | sommaire_id | +----+--------------+---------+-------------+ | 1 | aquarel | aquarel | 1 | | 2 | aq2 | aq2 | 1 | | 3 | paysage | paysage | 2 | +----+--------------+---------+-------------+
je souhaite rechercher tous les noms des route ayant comme sommmaire_id = 1
voici mes 2 entités:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 public class Matiere implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String nameMatiere; private String route; @ManyToOne private Sommaire sommaire; }voici mon dao
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 public class Sommaire implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String nameSommaire; private String route; //un sommaire peut avoir plusieur matieres @OneToMany(mappedBy = "sommaire") private Collection<Matiere> matieres = new ArrayList<>(); }
lorsque que je regarde cette page des matières voici ce que je vois:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 @RepositoryRestResource public interface MatiereRepository extends JpaRepository<Matiere, Long> { public Matiere findByNameMatiere(String nameMatiere); @RestResource(path="/byRoute") public List<Matiere> findBySommaire(@Param("rt") String sommaire); }
dans le dictionnaire je ne vois pas ma recherche "findBySommaire"
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 { "_embedded" : { "matieres" : [ { "nameMatiere" : "aquarel", "route" : "aquarel", "_links" : { "self" : { "href" : "http://localhost:8181/matieres/1" }, "matiere" : { "href" : "http://localhost:8181/matieres/1" }, "sommaire" : { "href" : "http://localhost:8181/matieres/1/sommaire" } } }, { "nameMatiere" : "aq2", "route" : "aq2", "_links" : { "self" : { "href" : "http://localhost:8181/matieres/2" }, "matiere" : { "href" : "http://localhost:8181/matieres/2" }, "sommaire" : { "href" : "http://localhost:8181/matieres/2/sommaire" } } }, { "nameMatiere" : "paysage", "route" : "paysage", "_links" : { "self" : { "href" : "http://localhost:8181/matieres/3" }, "matiere" : { "href" : "http://localhost:8181/matieres/3" }, "sommaire" : { "href" : "http://localhost:8181/matieres/3/sommaire" } } } ] }, "_links" : { "self" : { "href" : "http://localhost:8181/matieres{?page,size,sort}", "templated" : true }, "profile" : { "href" : "http://localhost:8181/profile/matieres" }, "search" : { "href" : "http://localhost:8181/matieres/search" } }, "page" : { "size" : 20, "totalElements" : 3, "totalPages" : 1, "number" : 0 } }
quel est le code à mettre et ou le mettre pour obtenir mon résultat des nom des routes(mettre la méthode findBySommaire dans le reposirtory de matière est t'il bon ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 public List<Matiere> findBySommaire(@Param("rt") String sommaire);
quel est la bonne url pour obtenir le nom des "route" en ayant le numéro id_sommaire ?
merci de vos réponses ?
Partager