Différences
Ci-dessous, les différences entre deux révisions de la page.
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 | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ====== TD 2 ====== | + | ====== TD n°2 ====== |
+ | Notions abordées : | ||
+ | * Models/ | ||
+ | * JPA + Hibernate | ||
+ | * H2 | ||
+ | * Persistance | ||
- | <sxh xml> | + | ===== Création ===== |
- | <!-- https:// | + | 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**, | ||
+ | |||
+ | <sxh; | ||
+ | spring.datasource.url=jdbc: | ||
+ | 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=/ | ||
+ | |||
+ | server.servlet.context-path=/ | ||
+ | |||
+ | # Mustache Template engine | ||
+ | spring.mustache.prefix=classpath:/ | ||
+ | spring.mustache.suffix=.html | ||
+ | </ | ||
+ | |||
+ | Ajouter webJars à pom.xml pour intégrer Semantic-UI : | ||
+ | <sxh xml; | ||
+ | <!-- https:// | ||
< | < | ||
< | < | ||
- | < | + | < |
- | < | + | < |
</ | </ | ||
</ | </ | ||
+ | |||
+ | Ajouter la dépendance pour jQuery (indispensable avec Semantic) | ||
+ | <sxh xml; | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | Créer une classe de configuration de l' | ||
+ | <sxh java; | ||
+ | @Configuration | ||
+ | @EnableWebMvc | ||
+ | public class WebConfig implements WebMvcConfigurer { | ||
+ | |||
+ | @Override | ||
+ | public void addResourceHandlers(ResourceHandlerRegistry registry) { | ||
+ | registry | ||
+ | .addResourceHandler("/ | ||
+ | .addResourceLocations("/ | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Créer les templates : | ||
+ | |||
+ | <sxh html; | ||
+ | < | ||
+ | <html lang=" | ||
+ | < | ||
+ | <meta charset=" | ||
+ | < | ||
+ | <link rel=" | ||
+ | href="/ | ||
+ | </ | ||
+ | < | ||
+ | <div class=" | ||
+ | </ | ||
+ | |||
+ | <sxh html; | ||
+ | </ | ||
+ | <script src="/ | ||
+ | <script src="/ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ===== 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 | ||
+ | |||
+ | |||
+ | {{: | ||
+ | |||
+ | ===== Création des Repositories ===== | ||
+ | |||
+ | Créer les repositories correspondant à chacune des classes dans **s4.spring.td2.repositories**. | ||
+ | |||
+ | ===== Création des routes ===== | ||
+ | |||
+ | ==== / | ||
+ | |||
+ | {{: | ||
+ | |||
+ | ==== /orgas/new ==== | ||
+ | |||
+ | {{: | ||
+ | |||
+ | ==== / | ||
+ | |||
+ | {{: | ||
+ | ==== / | ||
+ | Confirmation avant la suppression d'une organisation : | ||
+ | |||
+ | {{: | ||
+ | |||
+ | ==== / | ||
+ | |||
+ | {{: | ||
+ | |||
+ | ==== / | ||
+ | Recherche une organisation en fonction de la valeur contenue de l'un de ses champs visibles, puis redirige vers **/orgas/** | ||
+ | |||
+ | ==== / | ||
+ | |||
+ | |||
+ | {{: | ||
+ |