mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-21 06:45:49 +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";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<!doctype html>
|
||||
<html th:fragment="layout (template, menu)">
|
||||
|
||||
<head>
|
||||
<head>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
<meta charset="utf-8">
|
||||
|
@ -19,75 +19,75 @@
|
|||
|
||||
<link rel="stylesheet" th:href="@{/resources/css/petclinic.css}"/>
|
||||
|
||||
</head>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-default" role="navigation">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<a class="navbar-brand" th:href="@{/}"><span></span></a>
|
||||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#main-navbar">
|
||||
<span class="sr-only"><os-p>Toggle navigation</os-p></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="navbar-collapse collapse" id="main-navbar">
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
|
||||
<li th:fragment="menuItem (path,active,title,glyph,text)" class="active" th:class="${active==menu ? 'active' : ''}">
|
||||
<a th:href="@{__${path}__}" th:title="${title}">
|
||||
<nav class="navbar navbar-default" role="navigation">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<a class="navbar-brand" th:href="@{/}"><span></span></a>
|
||||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#main-navbar">
|
||||
<span class="sr-only"><os-p>Toggle navigation</os-p></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="navbar-collapse collapse" id="main-navbar">
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
|
||||
<li th:fragment="menuItem (path,active,title,glyph,text)" class="active" th:class="${active==menu ? 'active' : ''}">
|
||||
<a th:href="@{__${path}__}" th:title="${title}">
|
||||
<span th:class="'glyphicon glyphicon-'+${glyph}" class="glyphicon glyphicon-home" aria-hidden="true"></span>
|
||||
<span th:text="${text}">Template</span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li th:replace="::menuItem ('/','home','home page','home','Home')">
|
||||
<span class="glyphicon glyphicon-home" aria-hidden="true"></span>
|
||||
<span>Home</span>
|
||||
</li>
|
||||
|
||||
<li th:replace="::menuItem ('/owners/find','owners','find owners','search','Find owners')">
|
||||
<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
|
||||
<span>Find owners</span>
|
||||
</li>
|
||||
|
||||
<li th:replace="::menuItem ('/vets.html','vets','veterinarians','th-list','Veterinarians')">
|
||||
<span class="glyphicon glyphicon-th-list" aria-hidden="true"></span>
|
||||
<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>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="container-fluid">
|
||||
<div class="container xd-container">
|
||||
|
||||
<th:block th:include="${template}"/>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li th:replace="::menuItem ('/','home','home page','home','Home')">
|
||||
<span class="glyphicon glyphicon-home" aria-hidden="true"></span>
|
||||
<span>Home</span>
|
||||
</li>
|
||||
|
||||
<li th:replace="::menuItem ('/owners/find','owners','find owners','search','Find owners')">
|
||||
<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
|
||||
<span>Find owners</span>
|
||||
</li>
|
||||
|
||||
<li th:replace="::menuItem ('/vets.html','vets','veterinarians','th-list','Veterinarians')">
|
||||
<span class="glyphicon glyphicon-th-list" aria-hidden="true"></span>
|
||||
<span>Veterinarians</span>
|
||||
</li>
|
||||
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="container-fluid">
|
||||
<div class="container xd-container">
|
||||
|
||||
<th:block th:include="${template}"/>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-12 text-center">
|
||||
<img src="../static/resources/images/spring-pivotal-logo.png" th:src="@{/resources/images/spring-pivotal-logo.png}"
|
||||
alt="Sponsored by Pivotal"/></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12 text-center">
|
||||
<img src="../static/resources/images/spring-pivotal-logo.png" th:src="@{/resources/images/spring-pivotal-logo.png}"
|
||||
alt="Sponsored by Pivotal"/></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script th:src="@{/webjars/jquery/jquery.min.js}"></script>
|
||||
<script th:src="@{/webjars/jquery-ui/jquery-ui.min.js}"></script>
|
||||
<script th:src="@{/webjars/bootstrap/js/bootstrap.min.js}"></script>
|
||||
<script th:src="@{/webjars/jquery/jquery.min.js}"></script>
|
||||
<script th:src="@{/webjars/jquery-ui/jquery-ui.min.js}"></script>
|
||||
<script th:src="@{/webjars/bootstrap/js/bootstrap.min.js}"></script>
|
||||
|
||||
</body>
|
||||
|
||||
|
|
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