mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-21 06:45:49 +00:00
Teste
This commit is contained in:
parent
d109b39341
commit
bb9683e775
6 changed files with 37 additions and 7 deletions
|
@ -1,9 +1,17 @@
|
||||||
package org.springframework.samples.petclinic.product;
|
package org.springframework.samples.petclinic.product;
|
||||||
|
|
||||||
public class Product {
|
import org.springframework.samples.petclinic.model.BaseEntity;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name="products")
|
||||||
|
public class Product extends BaseEntity {
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
public Product(String description){
|
public void setDescription(String description){
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,17 +6,22 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class ProductController {
|
public class ProductController {
|
||||||
|
|
||||||
|
private final ProductRepository products;
|
||||||
|
|
||||||
|
public ProductController(ProductRepository products) {
|
||||||
|
this.products = products;
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/products")
|
@GetMapping("/products")
|
||||||
public String showProductList(Model model){
|
public String showProductList(Model model){
|
||||||
List<Product> prods = new ArrayList<Product>();
|
Collection<Product> prods = products.findAll();
|
||||||
model.addAttribute("products", prods);
|
model.addAttribute("products", prods);
|
||||||
prods.add(new Product("p1"));
|
|
||||||
prods.add(new Product("p2"));
|
|
||||||
|
|
||||||
return "products/productsList";
|
return "products/productsList";
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
package org.springframework.samples.petclinic.product;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.Repository;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public interface ProductRepository extends Repository<Product, Integer> {
|
||||||
|
Collection<Product> findAll();
|
||||||
|
}
|
|
@ -51,3 +51,6 @@ INSERT INTO visits VALUES (1, 7, '2013-01-01', 'rabies shot');
|
||||||
INSERT INTO visits VALUES (2, 8, '2013-01-02', 'rabies shot');
|
INSERT INTO visits VALUES (2, 8, '2013-01-02', 'rabies shot');
|
||||||
INSERT INTO visits VALUES (3, 8, '2013-01-03', 'neutered');
|
INSERT INTO visits VALUES (3, 8, '2013-01-03', 'neutered');
|
||||||
INSERT INTO visits VALUES (4, 7, '2013-01-04', 'spayed');
|
INSERT INTO visits VALUES (4, 7, '2013-01-04', 'spayed');
|
||||||
|
|
||||||
|
INSERT INTO products VALUES (1, 'product p1');
|
||||||
|
INSERT INTO products VALUES (2, 'product p2');
|
||||||
|
|
|
@ -5,7 +5,7 @@ DROP TABLE visits IF EXISTS;
|
||||||
DROP TABLE pets IF EXISTS;
|
DROP TABLE pets IF EXISTS;
|
||||||
DROP TABLE types IF EXISTS;
|
DROP TABLE types IF EXISTS;
|
||||||
DROP TABLE owners IF EXISTS;
|
DROP TABLE owners IF EXISTS;
|
||||||
|
DROP TABLE products IF EXISTS;
|
||||||
|
|
||||||
CREATE TABLE vets (
|
CREATE TABLE vets (
|
||||||
id INTEGER IDENTITY PRIMARY KEY,
|
id INTEGER IDENTITY PRIMARY KEY,
|
||||||
|
@ -62,3 +62,8 @@ CREATE TABLE visits (
|
||||||
);
|
);
|
||||||
ALTER TABLE visits ADD CONSTRAINT fk_visits_pets FOREIGN KEY (pet_id) REFERENCES pets (id);
|
ALTER TABLE visits ADD CONSTRAINT fk_visits_pets FOREIGN KEY (pet_id) REFERENCES pets (id);
|
||||||
CREATE INDEX visits_pet_id ON visits (pet_id);
|
CREATE INDEX visits_pet_id ON visits (pet_id);
|
||||||
|
|
||||||
|
CREATE TABLE products(
|
||||||
|
id INTEGER IDENTITY PRIMARY KEY,
|
||||||
|
description VARCHAR(80)
|
||||||
|
);
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
<span>Veterinarians</span>
|
<span>Veterinarians</span>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li th:replace="::menuItem ('/products','products','products','warning-sign','products')">
|
<li th:replace="::menuItem ('/products','products','products','apple','products')">
|
||||||
<span class="glyphicon glyphicon-warning-sign" aria-hidden="true"></span>
|
<span class="glyphicon glyphicon-warning-sign" aria-hidden="true"></span>
|
||||||
<span>Products</span>
|
<span>Products</span>
|
||||||
</li>
|
</li>
|
||||||
|
|
Loading…
Reference in a new issue