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