Bonjour à tous,
Je suis en train de travailler sur un projet de stage et je bloque un peu.
Je travaille avec Spring MVC, Hibernate et JSP.
J'arrive jusqu'à maintenant à afficher des listes de ce que j'ai dans ma base de données, supprimer des enregistrements et en ajouter.
Mais j'arrive pas à éditer quoi que se soit et c'est là ou se trouve mon problème pour l'instant.
je sais que cela peut vous paraitre banale mais je suis débutante avec tout ceci donc tout aide serait la bienvenue.
J'ai bien sur plusieurs tables et classes mais je vous pose celles de profil par exemple.
//Le contrôleur de Profil
//Le contrôleur du formulaire Profil
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 @Controller @RequestMapping("/profils/*") @SessionAttributes("profil") public class ProfilController { @Autowired private ProfilService profilService; @Autowired private Converter<Profil, ProfilDTO> profilConverter; @RequestMapping(value="/list",method = RequestMethod.GET) public ModelAndView list() { ModelAndView mav = new ModelAndView(); mav.setViewName("listProfil"); List<ProfilDTO> result = new ArrayList<ProfilDTO>(); List<Profil> list = profilService.findAll(); if(!CollectionUtils.isEmpty(list)){ for (Profil profil : list) { result.add(profilConverter.convert(profil)); } } mav.addObject("list", result); return mav; } @RequestMapping(value="/delete",method = RequestMethod.GET) public ModelAndView delete(@RequestParam Integer idProfil) { profilService.delete(idProfil); ModelAndView mav = new ModelAndView(); mav.setViewName("redirect:/profils/list"); return mav; } @RequestMapping(value="/edit",method = RequestMethod.GET) public ModelAndView edit(@RequestParam Integer idProfil) { ModelAndView mav = new ModelAndView(); mav.setViewName("editProfil"); Profil profil = new Profil(); profil = profilService.findById(idProfil); profilConverter.convert(profil); mav.addObject("profil", profil); return mav; } }
//La page JSP du formulaire
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 @Controller @RequestMapping("/profForm.html") @SessionAttributes("profil") public class ProfilFormController { private ProfilService profilService; @RequestMapping(method = RequestMethod.GET) public String showForm(ModelMap model) { Profil profil = new Profil(); model.addAttribute(profil); return "profilForm"; } @RequestMapping(method = RequestMethod.POST) public String onSubmit(@ModelAttribute("profil") Profil profil) { profilService.saveOrUpdate(profil); return "redirect:/profils/list"; } }
//La page JSP de la liste des profils
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 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Information profil</title> </head> <body> <h2>Veuillez remplir les informations suivantes:</h2> <form:form method="POST" commandName="profil"> <table> <!-- tr> <td>Identifiant :</td> <td><form:input path="idProfil" /></td> </tr--> <tr> <td>Libellé :</td> <td><form:input path="libele" /></td> </tr> <tr> <td colspan="2"><input type="submit"></td> </tr> </table> </form:form> </body> </html>
Merci d'avance,
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 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <html> <head> <link href="styles/style.css" rel="stylesheet" type="text/css" /> <title>Welcome</title> </head> <body> <%@include file="header.jsp" %> <h1><spring:message code="profils.titre" /></h1> <!--a href="<c:url value="/profils/test"></c:url>"> <spring:message code="welcome3.toDeleteThisEntry"></spring:message></a--></br> <a href="<c:url value="/profilForm.html" ></c:url>"> Ajouter</a> <br /> <br /> <table border="1px" width="100%"> <thead> <tr> <td class="col"><b><spring:message code="profils.idProfil" /></b></td> <td class="col"><b><spring:message code="profils.libele" /></b></td> <td class="col"></td> </tr> </thead> <c:forEach var="profil" items="${list}"> <tr> <td><c:out value="${profil.idProfil}" /></td> <td><c:out value="${profil.libele}" /></td> <td><a href="<c:url value="/profils/edit" ><c:param name="idProfil" value="${profil.idProfil}"/></c:url>"> Edit </a></td> <td><a href="<c:url value="/profils/delete" ><c:param name="idProfil" value="${profil.idProfil}"/></c:url>"> Delete</a></td> </tr> </c:forEach> </table> </body> </html>
Partager