| Prochaine révision | Révision précédente |
| framework-web:spring:td2 [2019/02/07 16:08] – créée jcheron | framework-web:spring:td2 [2019/08/31 14:21] (Version actuelle) – modification externe 127.0.0.1 |
|---|
| ====== TD 2 ====== | ====== TD n°2 ====== |
| |
| | Notions abordées : |
| | * Models/Entities |
| | * JPA + Hibernate |
| | * H2 |
| | * Persistance |
| |
| <sxh xml> | ===== Création ===== |
| <!-- https://mvnrepository.com/artifact/org.webjars/vue --> | Créer le projet td2 : |
| | * Group : s4.spring |
| | * Artifact : td2 |
| | * Packaging : War |
| | * Description : Gestion de messagerie |
| | * Dependencies : Web, Devtools, Mustache, H2, JPA |
| | |
| | Configurer le projet dans **application.properties**, pour que le contextPath soit **/**, configurer Mustache, H2 |
| | |
| | <sxh;gutter:false> |
| | spring.datasource.url=jdbc:h2:file:./data/messagerie;DB_CLOSE_ON_EXIT=FALSE |
| | spring.datasource.username=sa |
| | spring.datasource.password= |
| | spring.datasource.driverClassName=org.h2.Driver |
| | spring.jpa.hibernate.ddl-auto=update |
| | spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect |
| | |
| | spring.h2.console.enabled=true |
| | spring.h2.console.path=/h2-console |
| | |
| | server.servlet.context-path=/ |
| | |
| | # Mustache Template engine |
| | spring.mustache.prefix=classpath:/templates/ |
| | spring.mustache.suffix=.html |
| | </sxh> |
| | |
| | Ajouter webJars à pom.xml pour intégrer Semantic-UI : |
| | <sxh xml;gutter:false> |
| | <!-- https://mvnrepository.com/artifact/org.webjars/Semantic-UI --> |
| <dependency> | <dependency> |
| <groupId>org.webjars</groupId> | <groupId>org.webjars</groupId> |
| <artifactId>vue</artifactId> | <artifactId>Semantic-UI</artifactId> |
| <version>2.0.0</version> | <version>2.4.1</version> |
| </dependency> | </dependency> |
| </sxh> | </sxh> |
| | |
| | Ajouter la dépendance pour jQuery (indispensable avec Semantic) |
| | <sxh xml;gutter:false> |
| | <dependency> |
| | <groupId>org.webjars</groupId> |
| | <artifactId>jquery</artifactId> |
| | <version>3.3.1-1</version> |
| | </dependency> |
| | </sxh> |
| | |
| | Créer une classe de configuration de l'application pour définir des mappings vers les webJars : |
| | <sxh java;title:s4.spring.td2.WebConfig.java> |
| | @Configuration |
| | @EnableWebMvc |
| | public class WebConfig implements WebMvcConfigurer { |
| | |
| | @Override |
| | public void addResourceHandlers(ResourceHandlerRegistry registry) { |
| | registry |
| | .addResourceHandler("/webjars/**") |
| | .addResourceLocations("/webjars/"); |
| | } |
| | } |
| | </sxh> |
| | |
| | Créer les templates : |
| | |
| | <sxh html;title:main/header.html> |
| | <!doctype html> |
| | <html lang="fr"> |
| | <head> |
| | <meta charset="UTF-8"> |
| | <title>Messagerie</title> |
| | <link rel="stylesheet" |
| | href="/webjars/Semantic-UI/2.4.1/semantic.min.css" /> |
| | </head> |
| | <body> |
| | <div class="ui container"> |
| | </sxh> |
| | |
| | <sxh html;title:main/footer.html> |
| | </div> |
| | <script src="/webjars/jquery/3.3.1-1/jquery.min.js"></script> |
| | <script src="/webjars/Semantic-UI/2.4.1/semantic.min.js"></script> |
| | </body> |
| | </html> |
| | </sxh> |
| | |
| | ===== Création des Entities ===== |
| | |
| | Créer les classes métier correspondant au diagramme de classes suivant dans **s4.spring.td2.entities** : |
| | * penser à ajouter les relations : |
| | * oneToMany |
| | * manyToOne |
| | * manyToMany |
| | |
| | |
| | {{:framework-web:spring:classdiagram.png|}} |
| | |
| | ===== Création des Repositories ===== |
| | |
| | Créer les repositories correspondant à chacune des classes dans **s4.spring.td2.repositories**. |
| | |
| | ===== Création des routes ===== |
| | |
| | ==== /orgas/(index)? ==== |
| | |
| | {{:framework-web:spring:orgas-lnk.png?800|}} |
| | |
| | ==== /orgas/new ==== |
| | |
| | {{:framework-web:spring:oragas-frm.png?800|}} |
| | |
| | ==== /orgas/edit/{id} ==== |
| | |
| | {{:framework-web:spring:oragas-frm-id.png?800|}} |
| | ==== /orgas/delete/{id} ==== |
| | Confirmation avant la suppression d'une organisation : |
| | |
| | {{:framework-web:spring:orga-delete.png?800|}} |
| | |
| | ==== /orgas/display/{id} ==== |
| | |
| | {{:framework-web:spring:orgas-display-id-lnk.png?800|}} |
| | |
| | ==== /orgas/search/ ==== |
| | Recherche une organisation en fonction de la valeur contenue de l'un de ses champs visibles, puis redirige vers **/orgas/** |
| | |
| | ==== /orgas/details/{id} ==== |
| | |
| | |
| | {{:framework-web:spring:orgas-details.png?800|}} |
| | |