mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-21 14:55:51 +00:00
parent
3aac648f80
commit
e2c425844f
4 changed files with 108 additions and 63 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,13 +1,22 @@
|
|||
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";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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','list products on menu','th-list','Products')">
|
||||
<span class="glyphicon glyphicon-th-list" aria-hidden="true"></span>
|
||||
<span>Products</span>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
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>Veterinarians</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