File tree Expand file tree Collapse file tree 6 files changed +17
-20
lines changed
java/guru/springframework Expand file tree Collapse file tree 6 files changed +17
-20
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,6 @@ public void setProductService(ProductService productService) {
22
22
@ RequestMapping (value = "/products" , method = RequestMethod .GET )
23
23
public String list (Model model ){
24
24
model .addAttribute ("products" , productService .listAllProducts ());
25
- System .out .println ("Returning rpoducts:" );
26
25
return "products" ;
27
26
}
28
27
@@ -46,10 +45,14 @@ public String newProduct(Model model){
46
45
47
46
@ RequestMapping (value = "product" , method = RequestMethod .POST )
48
47
public String saveProduct (Product product ){
49
-
50
48
productService .saveProduct (product );
51
-
52
49
return "redirect:/product/" + product .getId ();
53
50
}
54
51
52
+ @ RequestMapping ("product/delete/{id}" )
53
+ public String delete (@ PathVariable Integer id ){
54
+ productService .deleteProduct (id );
55
+ return "redirect:/products" ;
56
+ }
57
+
55
58
}
Original file line number Diff line number Diff line change @@ -9,4 +9,6 @@ public interface ProductService {
9
9
Product getProductById (Integer id );
10
10
11
11
Product saveProduct (Product product );
12
+
13
+ void deleteProduct (Integer id );
12
14
}
Original file line number Diff line number Diff line change @@ -28,4 +28,9 @@ public Product getProductById(Integer id) {
28
28
public Product saveProduct (Product product ) {
29
29
return productRepository .save (product );
30
30
}
31
+
32
+ @ Override
33
+ public void deleteProduct (Integer id ) {
34
+ productRepository .delete (id );
35
+ }
31
36
}
Original file line number Diff line number Diff line change 1
1
<!DOCTYPE html>
2
2
< html xmlns:th ="http://www.thymeleaf.org ">
3
3
< head lang ="en ">
4
- < meta http-equiv ="Content-Type " content ="text/html; charset=UTF-8 "/>
5
- < link href ="http://cdn.jsdelivr.net/webjars/bootstrap/3.3.4/css/bootstrap.min.css "
6
- th:href ="@{/webjars/bootstrap/3.3.4/css/bootstrap.min.css} "
7
- rel ="stylesheet " media ="screen "/>
8
4
9
- < script src ="http://cdn.jsdelivr.net/webjars/jquery/2.1.4/jquery.min.js "
10
- th:src ="@{/webjars/jquery/2.1.4/jquery.min.js} "> </ script >
11
-
12
- < link href ="../../static/css/guru.css "
13
- th:href ="@{css/guru.css} " rel ="stylesheet " media ="screen "/>
14
5
</ head >
15
6
< body >
16
7
22
13
< a class ="navbar-brand " href ="# " th:href ="@{/} "> Home</ a >
23
14
< ul class ="nav navbar-nav ">
24
15
< li > < a href ="# " th:href ="@{/products} "> Products</ a > </ li >
25
- < li > < a href ="# " th:href ="@{/products /new} "> Create Product</ a > </ li >
16
+ < li > < a href ="# " th:href ="@{/product /new} "> Create Product</ a > </ li >
26
17
</ ul >
27
18
28
19
</ div >
Original file line number Diff line number Diff line change @@ -15,12 +15,6 @@ <h2>Product Details</h2>
15
15
< form class ="form-horizontal " th:object ="${product} " th:action ="@{/product} " method ="post ">
16
16
< input type ="hidden " th:field ="*{id} "/>
17
17
< input type ="hidden " th:field ="*{version} "/>
18
- < div class ="form-group ">
19
- < label class ="col-sm-2 control-label "> Product Id:</ label >
20
- < div class ="col-sm-10 ">
21
- < input type ="text " class ="form-control " th:field ="*{productId} "/>
22
- </ div >
23
- </ div >
24
18
< div class ="form-group ">
25
19
< label class ="col-sm-2 control-label "> Description:</ label >
26
20
< div class ="col-sm-10 ">
Original file line number Diff line number Diff line change @@ -19,14 +19,16 @@ <h2>Product List</h2>
19
19
< th > Price</ th >
20
20
< th > View</ th >
21
21
< th > Edit</ th >
22
+ < th > Delete</ th >
22
23
</ tr >
23
24
< tr th:each ="product : ${products} ">
24
25
< td th:text ="${product.id} "> < a href ="/product/${product.id} "> Id</ a > </ td >
25
26
< td th:text ="${product.productId} "> Product Id</ td >
26
27
< td th:text ="${product.description} "> descirption</ td >
27
28
< td th:text ="${product.price} "> price</ td >
28
- < td > < a th:href ="${ '/product/' + product.id} "> View</ a > </ td >
29
+ < td > < a th:href ="${'/product/' + product.id} "> View</ a > </ td >
29
30
< td > < a th:href ="${'/product/edit/' + product.id} "> Edit</ a > </ td >
31
+ < td > < a th:href ="${'/product/delete/' + product.id} "> Delete</ a > </ td >
30
32
</ tr >
31
33
</ table >
32
34
You can’t perform that action at this time.
0 commit comments