mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 22:35:49 +00:00
Controller Products done
This commit is contained in:
parent
c913233388
commit
6012c8afda
4 changed files with 51 additions and 8 deletions
|
@ -0,0 +1,13 @@
|
|||
package org.springframework.samples.petclinic.product;
|
||||
|
||||
public class Product {
|
||||
private String description;
|
||||
|
||||
public Product (String description){
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getDescription(){
|
||||
return description;
|
||||
}
|
||||
}
|
|
@ -1,18 +1,26 @@
|
|||
package org.springframework.samples.petclinic.product;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.ui.Model;
|
||||
|
||||
@RestController
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
@Controller
|
||||
public class ProductController {
|
||||
|
||||
@GetMapping("/products")
|
||||
public String showProductList(){
|
||||
public String showProductList(Model model){
|
||||
List<Product> prods = new ArrayList<Product>();
|
||||
model.addAttribute( "products", prods);
|
||||
prods.add(new Product("p1"));
|
||||
prods.add(new Product( "p2"));
|
||||
|
||||
return "C:\\Users\\gfick\\Downloads\\Download.png";
|
||||
return "products/productsList";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
22
src/main/resources/templates/Products/productsList.html
Normal file
22
src/main/resources/templates/Products/productsList.html
Normal file
|
@ -0,0 +1,22 @@
|
|||
<!DOCTYPE html>
|
||||
<<html xmlns:th="https://www.thymeleaf.org"
|
||||
th:replace="~{fragments/layout :: layout (~{::body},'products')}">
|
||||
|
||||
<body>
|
||||
|
||||
<h2>Products List</h2>
|
||||
|
||||
<table id="products" class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="product : ${products}">
|
||||
<td th:text="${product.description}"></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
|
@ -59,9 +59,9 @@
|
|||
<span>Veterinarians</span>
|
||||
</li>
|
||||
|
||||
<li th:replace="::menuItem ('/oups','error','trigger a RuntimeException to see how it is handled','warning-sign','Error')">
|
||||
<li th:replace="::menuItem ('/products','products','products','th-list','Products')">
|
||||
<span class="glyphicon glyphicon-warning-sign" aria-hidden="true"></span>
|
||||
<span>Error</span>
|
||||
<span>Products</span>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
Loading…
Reference in a new issue