Product list created

This commit is contained in:
joaoMoraesJr 2019-08-09 17:00:01 -03:00
parent 827c0eccc8
commit 9a19be0ef5
4 changed files with 53 additions and 6 deletions

View file

@ -0,0 +1,15 @@
package org.springframework.samples.petclinic.product;
public class Product {
private String description;
public Product(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
}

View file

@ -1,12 +1,21 @@
package org.springframework.samples.petclinic.product;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
import java.util.ArrayList;
import java.util.List;
@Controller
public class ProductController {
@GetMapping("/products")
public String showProductList(){
return "Hello";
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 "products/productsList";
}
}

View file

@ -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')">
<span class="glyphicon glyphicon-warning-sign" aria-hidden="true"></span>
<span>Error</span>
<li th:replace="::menuItem ('/products','products','products','th-products','Products')">
<span class="glyphicon glyphicon-th-products" aria-hidden="true"></span>
<span>Products</span>
</li>
</ul>

View file

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html xmlns:th="https://www.thymeleaf.org"
th:replace="~{fragments/layout :: layout (~{::body},'products')}">
<body>
<h2>Product List</h2>
<table id="vets" class="table table-striped">
<thead>
<tr>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr th:each="product : ${products}">
<td th:text="${product.description}" ></tr>
</tr>
</tbody>
</table>
</body>
</html>