mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-21 14:55:51 +00:00
Sextou éusguri
This commit is contained in:
parent
de9ddc9069
commit
961fc26b74
4 changed files with 55 additions and 5 deletions
|
@ -0,0 +1,12 @@
|
||||||
|
package org.springframework.samples.petclinic.product;
|
||||||
|
|
||||||
|
public class Product {
|
||||||
|
private String description;
|
||||||
|
Product(String desc){
|
||||||
|
this.description = desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,14 +1,23 @@
|
||||||
package org.springframework.samples.petclinic.product;
|
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.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@Controller
|
||||||
public class ProductController {
|
public class ProductController {
|
||||||
|
|
||||||
@GetMapping("/products")
|
@GetMapping("/products")
|
||||||
public String showProductList(){
|
public String showProductList(Model model){
|
||||||
return "Hacker 2.0";
|
List<Product> prods = new ArrayList<Product>();
|
||||||
|
model.addAttribute("products",prods);
|
||||||
|
prods.add(new Product("Aninha"));
|
||||||
|
prods.add(new Product("Leozinho"));
|
||||||
|
return "products/productsList";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,11 +58,17 @@
|
||||||
<span class="glyphicon glyphicon-th-list" aria-hidden="true"></span>
|
<span class="glyphicon glyphicon-th-list" aria-hidden="true"></span>
|
||||||
<span>Veterinarians</span>
|
<span>Veterinarians</span>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li th:replace="::menuItem ('/products','products','products','th-list','Products')">
|
||||||
|
<span class="glyphicon glyphicon-th-list" aria-hidden="true"></span>
|
||||||
|
<span>Products</span>
|
||||||
|
</li>
|
||||||
|
|
||||||
<li th:replace="::menuItem ('/oups','error','trigger a RuntimeException to see how it is handled','warning-sign','Error')">
|
<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 class="glyphicon glyphicon-warning-sign" aria-hidden="true"></span>
|
||||||
<span>Error</span>
|
<span>Error</span>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
23
src/main/resources/templates/products/ProductsList.html
Normal file
23
src/main/resources/templates/products/ProductsList.html
Normal 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="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>
|
Loading…
Reference in a new issue