File tree Expand file tree Collapse file tree 4 files changed +16
-0
lines changed
java/guru/springframework Expand file tree Collapse file tree 4 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -55,4 +55,11 @@ public String saveOrUpdateProduct(Product product){
55
55
Product savedProduct = productService .saveOrUpdateProduct (product );
56
56
return "redirect:/product/" + savedProduct .getId ();
57
57
}
58
+
59
+ @ RequestMapping ("/product/delete/{id}" )
60
+ public String delete (@ PathVariable Integer id ){
61
+ productService .deleteProduct (id );
62
+
63
+ return "redirect:/products" ;
64
+ }
58
65
}
Original file line number Diff line number Diff line change @@ -14,4 +14,6 @@ public interface ProductService {
14
14
Product getProductById (Integer id );
15
15
16
16
Product saveOrUpdateProduct (Product product );
17
+
18
+ void deleteProduct (Integer id );
17
19
}
Original file line number Diff line number Diff line change @@ -46,6 +46,11 @@ private Integer getNextKey(){
46
46
return Collections .max (products .keySet ()) + 1 ;
47
47
}
48
48
49
+ @ Override
50
+ public void deleteProduct (Integer id ) {
51
+ products .remove (id );
52
+ }
53
+
49
54
private void loadProducts (){
50
55
products = new HashMap <>();
51
56
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ <h2>Product List</h2>
26
26
< th > Image URL</ th >
27
27
< th > List</ th >
28
28
< th > Edit</ th >
29
+ < th > Delete</ th >
29
30
</ tr >
30
31
< tr th:each ="product : ${products} ">
31
32
< td th:text ="${product.id} "> </ td >
@@ -34,6 +35,7 @@ <h2>Product List</h2>
34
35
< td th:text ="${product.imageUrl} "> </ td >
35
36
< td > < a th:href ="${'/product/' + product.id} "> View</ a > </ td >
36
37
< td > < a th:href ="${'/product/edit/' + product.id} "> Edit</ a > </ td >
38
+ < td > < a th:href ="${'/product/delete/' + product.id} "> Delete</ a > </ td >
37
39
</ tr >
38
40
</ table >
39
41
</ div >
You can’t perform that action at this time.
0 commit comments