Skip to content

Commit b7b97e9

Browse files
Added Create a Product
1 parent d75c97e commit b7b97e9

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/main/java/guru/springframework/controllers/ProductController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ public String getProduct(@PathVariable Integer id, Model model){
3838
return "product";
3939
}
4040

41+
@RequestMapping("product/edit/{id}")
42+
public String edit(@PathVariable Integer id, Model model){
43+
model.addAttribute("product", productService.getProductById(id));
44+
return "productform";
45+
}
46+
4147
@RequestMapping("/product/new")
4248
public String newProduct(Model model){
4349
model.addAttribute("product", new Product());

src/main/resources/templates/products.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ <h2>Product List</h2>
2525
<th>Price</th>
2626
<th>Image URL</th>
2727
<th>List</th>
28+
<th>Edit</th>
2829
</tr>
2930
<tr th:each="product : ${products}">
3031
<td th:text="${product.id}"></td>
3132
<td th:text="${product.description}"></td>
3233
<td th:text="${product.price}"></td>
3334
<td th:text="${product.imageUrl}"></td>
3435
<td><a th:href="${'/product/' + product.id}">View</a> </td>
36+
<td><a th:href="${'/product/edit/' + product.id}">Edit</a> </td>
3537
</tr>
3638
</table>
3739
</div>

0 commit comments

Comments
 (0)