BaseEntity
. Used as a base class for objects
24 | * needing these properties.
25 | *
26 | * @author Ken Krebs
27 | * @author Juergen Hoeller
28 | */
29 | @MappedSuperclass
30 | public class NamedEntity extends BaseEntity {
31 |
32 | @Column(name = "name")
33 | private String name;
34 |
35 | public String getName() {
36 | return this.name;
37 | }
38 |
39 | public void setName(String name) {
40 | this.name = name;
41 | }
42 |
43 | @Override
44 | public String toString() {
45 | return this.getName();
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/petclinic-latest/src/main/java/org/springframework/samples/petclinic/model/Person.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2013 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.springframework.samples.petclinic.model;
17 |
18 | import javax.persistence.Column;
19 | import javax.persistence.MappedSuperclass;
20 |
21 | import org.hibernate.validator.constraints.NotEmpty;
22 |
23 | /**
24 | * Simple JavaBean domain object representing an person.
25 | *
26 | * @author Ken Krebs
27 | */
28 | @MappedSuperclass
29 | public class Person extends BaseEntity {
30 |
31 | @Column(name = "first_name")
32 | @NotEmpty
33 | protected String firstName;
34 |
35 | @Column(name = "last_name")
36 | @NotEmpty
37 | protected String lastName;
38 |
39 | public String getFirstName() {
40 | return this.firstName;
41 | }
42 |
43 | public void setFirstName(String firstName) {
44 | this.firstName = firstName;
45 | }
46 |
47 | public String getLastName() {
48 | return this.lastName;
49 | }
50 |
51 | public void setLastName(String lastName) {
52 | this.lastName = lastName;
53 | }
54 |
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/petclinic-latest/src/main/java/org/springframework/samples/petclinic/model/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The classes in this package represent utilities used by the domain.
3 | */
4 | package org.springframework.samples.petclinic.model;
5 |
6 |
--------------------------------------------------------------------------------
/petclinic-latest/src/main/java/org/springframework/samples/petclinic/owner/PetRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2013 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.springframework.samples.petclinic.owner;
17 |
18 | import java.util.List;
19 |
20 | import org.springframework.data.jpa.repository.Query;
21 | import org.springframework.data.repository.Repository;
22 | import org.springframework.transaction.annotation.Transactional;
23 |
24 | /**
25 | * Repository class for Pet
domain objects All method names are compliant with Spring Data naming
26 | * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
27 | *
28 | * @author Ken Krebs
29 | * @author Juergen Hoeller
30 | * @author Sam Brannen
31 | * @author Michael Isvy
32 | */
33 | public interface PetRepository extends RepositoryValidator
for Pet
forms.
24 | * 25 | * We're not using Bean Validation annotations here because it is easier to define such validation rule in Java. 26 | *
27 | * 28 | * @author Ken Krebs 29 | * @author Juergen Hoeller 30 | */ 31 | public class PetValidator implements Validator { 32 | 33 | private static final String REQUIRED = "required"; 34 | 35 | @Override 36 | public void validate(Object obj, Errors errors) { 37 | Pet pet = (Pet) obj; 38 | String name = pet.getName(); 39 | // name validation 40 | if (!StringUtils.hasLength(name)) { 41 | errors.rejectValue("name", REQUIRED, REQUIRED); 42 | } 43 | 44 | // type validation 45 | if (pet.isNew() && pet.getType() == null) { 46 | errors.rejectValue("type", REQUIRED, REQUIRED); 47 | } 48 | 49 | // birth date validation 50 | if (pet.getBirthDate() == null) { 51 | errors.rejectValue("birthDate", REQUIRED, REQUIRED); 52 | } 53 | } 54 | 55 | /** 56 | * This Validator validates *just* Pet instances 57 | */ 58 | @Override 59 | public boolean supports(Class> clazz) { 60 | return Pet.class.isAssignableFrom(clazz); 61 | } 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /petclinic-latest/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.system; 2 | 3 | import org.springframework.cache.annotation.EnableCaching; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Profile; 6 | 7 | /** 8 | * Cache could be disable in unit test. 9 | */ 10 | @Configuration 11 | @EnableCaching 12 | @Profile("production") 13 | class CacheConfig { 14 | } 15 | -------------------------------------------------------------------------------- /petclinic-latest/src/main/java/org/springframework/samples/petclinic/system/CrashController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.system; 17 | 18 | import org.springframework.stereotype.Controller; 19 | import org.springframework.web.bind.annotation.RequestMapping; 20 | import org.springframework.web.bind.annotation.RequestMethod; 21 | 22 | /** 23 | * Controller used to showcase what happens when an exception is thrown 24 | * 25 | * @author Michael Isvy 26 | * 27 | * Also see how a view that resolves to "error" has been added ("error.html"). 28 | */ 29 | @Controller 30 | class CrashController { 31 | 32 | @RequestMapping(value = "/oups", method = RequestMethod.GET) 33 | public String triggerException() { 34 | throw new RuntimeException( 35 | "Expected: controller used to showcase what " + "happens when an exception is thrown"); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /petclinic-latest/src/main/java/org/springframework/samples/petclinic/system/LazyInitBeanFactoryPostProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.system; 17 | 18 | import org.springframework.beans.BeansException; 19 | import org.springframework.beans.factory.config.BeanDefinition; 20 | import org.springframework.beans.factory.config.BeanFactoryPostProcessor; 21 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; 22 | 23 | // @Component 24 | public class LazyInitBeanFactoryPostProcessor implements BeanFactoryPostProcessor { 25 | 26 | private Class>[] exclusionList; 27 | 28 | public LazyInitBeanFactoryPostProcessor() { 29 | } 30 | 31 | public LazyInitBeanFactoryPostProcessor(Class>[] exclusionList) { 32 | this.exclusionList = exclusionList; 33 | } 34 | 35 | @Override 36 | public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { 37 | 38 | // Iterate over all bean, mark them as lazy if they are not in the exclusion list. 39 | for (String beanName : beanFactory.getBeanDefinitionNames()) { 40 | if (isLazy(beanName, beanFactory)) { 41 | BeanDefinition definition = beanFactory.getBeanDefinition(beanName); 42 | definition.setLazyInit(true); 43 | } 44 | } 45 | } 46 | 47 | private boolean isLazy(String beanName, ConfigurableListableBeanFactory beanFactory) { 48 | if (exclusionList == null || exclusionList.length == 0) { 49 | return true; 50 | } 51 | for (Class> clazz : exclusionList) { 52 | if (beanFactory.isTypeMatch(beanName, clazz)) { 53 | return false; 54 | } 55 | } 56 | return true; 57 | } 58 | } -------------------------------------------------------------------------------- /petclinic-latest/src/main/java/org/springframework/samples/petclinic/system/LazyRepositoryPostProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.system; 17 | 18 | import org.springframework.beans.BeansException; 19 | import org.springframework.beans.factory.config.BeanPostProcessor; 20 | import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport; 21 | 22 | // @Component 23 | public class LazyRepositoryPostProcessor implements BeanPostProcessor { 24 | 25 | @Override 26 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 27 | if (bean instanceof RepositoryFactoryBeanSupport) { 28 | RepositoryFactoryBeanSupport, ?, ?> support = (RepositoryFactoryBeanSupport, ?, ?>) bean; 29 | support.setLazyInit(true); 30 | } 31 | return bean; 32 | } 33 | } -------------------------------------------------------------------------------- /petclinic-latest/src/main/java/org/springframework/samples/petclinic/system/WelcomeController.java: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.system; 2 | 3 | 4 | import org.springframework.stereotype.Controller; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | 7 | @Controller 8 | class WelcomeController { 9 | 10 | @RequestMapping("/") 11 | public String welcome() { 12 | return "welcome"; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /petclinic-latest/src/main/java/org/springframework/samples/petclinic/vet/Specialty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.vet; 17 | 18 | import javax.persistence.Entity; 19 | import javax.persistence.Table; 20 | 21 | import org.springframework.samples.petclinic.model.NamedEntity; 22 | 23 | /** 24 | * Models a {@link Vet Vet's} specialty (for example, dentistry). 25 | * 26 | * @author Juergen Hoeller 27 | */ 28 | @Entity 29 | @Table(name = "specialties") 30 | public class Specialty extends NamedEntity { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /petclinic-latest/src/main/java/org/springframework/samples/petclinic/vet/VetController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.vet; 17 | 18 | import java.util.Map; 19 | 20 | import org.springframework.beans.factory.annotation.Autowired; 21 | import org.springframework.context.annotation.Lazy; 22 | import org.springframework.stereotype.Controller; 23 | import org.springframework.web.bind.annotation.RequestMapping; 24 | import org.springframework.web.bind.annotation.ResponseBody; 25 | 26 | /** 27 | * @author Juergen Hoeller 28 | * @author Mark Fisher 29 | * @author Ken Krebs 30 | * @author Arjen Poutsma 31 | */ 32 | @Controller 33 | class VetController { 34 | 35 | private final VetRepository vets; 36 | 37 | @Autowired 38 | public VetController(@Lazy VetRepository clinicService) { 39 | this.vets = clinicService; 40 | } 41 | 42 | @RequestMapping(value = { "/vets.html" }) 43 | public String showVetList(MapVet
domain objects All method names are compliant with Spring Data naming
27 | * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
28 | *
29 | * @author Ken Krebs
30 | * @author Juergen Hoeller
31 | * @author Sam Brannen
32 | * @author Michael Isvy
33 | */
34 | public interface VetRepository extends RepositoryVet
s from the data store.
38 | *
39 | * @return a Collection
of Vet
s
40 | */
41 | @Transactional(readOnly = true)
42 | @Cacheable("vets")
43 | CollectionVisit
domain objects All method names are compliant with Spring Data naming
26 | * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
27 | *
28 | * @author Ken Krebs
29 | * @author Juergen Hoeller
30 | * @author Sam Brannen
31 | * @author Michael Isvy
32 | */
33 | public interface VisitRepository extends RepositoryVisit
to the data store, either inserting or updating it.
37 | *
38 | * @param visit the Visit
to save
39 | * @see BaseEntity#isNew
40 | */
41 | void save(Visit visit) throws DataAccessException;
42 |
43 | ListException message
9 | 10 | 11 | -------------------------------------------------------------------------------- /petclinic-latest/src/main/resources/templates/fragments/inputField.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /petclinic-latest/src/main/resources/templates/fragments/selectField.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 28 | 29 | -------------------------------------------------------------------------------- /petclinic-latest/src/main/resources/templates/owners/createOrUpdateOwnerForm.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 |Name | 13 |Address | 14 |City | 15 |Telephone | 16 |Pets | 17 |
---|---|---|---|---|
22 | 23 | | 24 |25 | | 26 | | 27 | | 28 | |
Name | 16 |Birth Date | 17 |Type | 18 |Owner | 19 |
---|---|---|---|
23 | | 25 | | 26 | | 28 | |
Date | 52 |Description | 53 |
---|---|
56 | | 57 | |
Name | 14 |Specialties | 15 |
---|---|
20 | | none | 23 |
View 30 | as XML | 31 |View as JSON | 32 |
BaseEntity
. Used as a base class for objects
24 | * needing these properties.
25 | *
26 | * @author Ken Krebs
27 | * @author Juergen Hoeller
28 | */
29 | @MappedSuperclass
30 | public class NamedEntity extends BaseEntity {
31 |
32 | @Column(name = "name")
33 | private String name;
34 |
35 | public String getName() {
36 | return this.name;
37 | }
38 |
39 | public void setName(String name) {
40 | this.name = name;
41 | }
42 |
43 | @Override
44 | public String toString() {
45 | return this.getName();
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/petclinic/src/main/java/org/springframework/samples/petclinic/model/Person.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2013 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.springframework.samples.petclinic.model;
17 |
18 | import javax.persistence.Column;
19 | import javax.persistence.MappedSuperclass;
20 |
21 | import org.hibernate.validator.constraints.NotEmpty;
22 |
23 | /**
24 | * Simple JavaBean domain object representing an person.
25 | *
26 | * @author Ken Krebs
27 | */
28 | @MappedSuperclass
29 | public class Person extends BaseEntity {
30 |
31 | @Column(name = "first_name")
32 | @NotEmpty
33 | protected String firstName;
34 |
35 | @Column(name = "last_name")
36 | @NotEmpty
37 | protected String lastName;
38 |
39 | public String getFirstName() {
40 | return this.firstName;
41 | }
42 |
43 | public void setFirstName(String firstName) {
44 | this.firstName = firstName;
45 | }
46 |
47 | public String getLastName() {
48 | return this.lastName;
49 | }
50 |
51 | public void setLastName(String lastName) {
52 | this.lastName = lastName;
53 | }
54 |
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/petclinic/src/main/java/org/springframework/samples/petclinic/model/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The classes in this package represent utilities used by the domain.
3 | */
4 | package org.springframework.samples.petclinic.model;
5 |
6 |
--------------------------------------------------------------------------------
/petclinic/src/main/java/org/springframework/samples/petclinic/owner/PetRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2002-2013 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.springframework.samples.petclinic.owner;
17 |
18 | import java.util.List;
19 |
20 | import org.springframework.data.jpa.repository.Query;
21 | import org.springframework.data.repository.Repository;
22 | import org.springframework.transaction.annotation.Transactional;
23 |
24 | /**
25 | * Repository class for Pet
domain objects All method names are compliant with Spring Data naming
26 | * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
27 | *
28 | * @author Ken Krebs
29 | * @author Juergen Hoeller
30 | * @author Sam Brannen
31 | * @author Michael Isvy
32 | */
33 | public interface PetRepository extends RepositoryValidator
for Pet
forms.
24 | * 25 | * We're not using Bean Validation annotations here because it is easier to define such validation rule in Java. 26 | *
27 | * 28 | * @author Ken Krebs 29 | * @author Juergen Hoeller 30 | */ 31 | public class PetValidator implements Validator { 32 | 33 | private static final String REQUIRED = "required"; 34 | 35 | @Override 36 | public void validate(Object obj, Errors errors) { 37 | Pet pet = (Pet) obj; 38 | String name = pet.getName(); 39 | // name validation 40 | if (!StringUtils.hasLength(name)) { 41 | errors.rejectValue("name", REQUIRED, REQUIRED); 42 | } 43 | 44 | // type validation 45 | if (pet.isNew() && pet.getType() == null) { 46 | errors.rejectValue("type", REQUIRED, REQUIRED); 47 | } 48 | 49 | // birth date validation 50 | if (pet.getBirthDate() == null) { 51 | errors.rejectValue("birthDate", REQUIRED, REQUIRED); 52 | } 53 | } 54 | 55 | /** 56 | * This Validator validates *just* Pet instances 57 | */ 58 | @Override 59 | public boolean supports(Class> clazz) { 60 | return Pet.class.isAssignableFrom(clazz); 61 | } 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /petclinic/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.system; 2 | 3 | import org.springframework.cache.annotation.EnableCaching; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Profile; 6 | 7 | /** 8 | * Cache could be disable in unit test. 9 | */ 10 | @Configuration 11 | @EnableCaching 12 | @Profile("production") 13 | class CacheConfig { 14 | } 15 | -------------------------------------------------------------------------------- /petclinic/src/main/java/org/springframework/samples/petclinic/system/CrashController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.system; 17 | 18 | import org.springframework.stereotype.Controller; 19 | import org.springframework.web.bind.annotation.RequestMapping; 20 | import org.springframework.web.bind.annotation.RequestMethod; 21 | 22 | /** 23 | * Controller used to showcase what happens when an exception is thrown 24 | * 25 | * @author Michael Isvy 26 | * 27 | * Also see how a view that resolves to "error" has been added ("error.html"). 28 | */ 29 | @Controller 30 | class CrashController { 31 | 32 | @RequestMapping(value = "/oups", method = RequestMethod.GET) 33 | public String triggerException() { 34 | throw new RuntimeException( 35 | "Expected: controller used to showcase what " + "happens when an exception is thrown"); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /petclinic/src/main/java/org/springframework/samples/petclinic/system/WelcomeController.java: -------------------------------------------------------------------------------- 1 | package org.springframework.samples.petclinic.system; 2 | 3 | 4 | import org.springframework.stereotype.Controller; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | 7 | @Controller 8 | class WelcomeController { 9 | 10 | @RequestMapping("/") 11 | public String welcome() { 12 | return "welcome"; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /petclinic/src/main/java/org/springframework/samples/petclinic/vet/Specialty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.vet; 17 | 18 | import javax.persistence.Entity; 19 | import javax.persistence.Table; 20 | 21 | import org.springframework.samples.petclinic.model.NamedEntity; 22 | 23 | /** 24 | * Models a {@link Vet Vet's} specialty (for example, dentistry). 25 | * 26 | * @author Juergen Hoeller 27 | */ 28 | @Entity 29 | @Table(name = "specialties") 30 | public class Specialty extends NamedEntity { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /petclinic/src/main/java/org/springframework/samples/petclinic/vet/VetController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.samples.petclinic.vet; 17 | 18 | import java.util.Map; 19 | 20 | import org.springframework.beans.factory.annotation.Autowired; 21 | import org.springframework.stereotype.Controller; 22 | import org.springframework.web.bind.annotation.RequestMapping; 23 | import org.springframework.web.bind.annotation.ResponseBody; 24 | 25 | /** 26 | * @author Juergen Hoeller 27 | * @author Mark Fisher 28 | * @author Ken Krebs 29 | * @author Arjen Poutsma 30 | */ 31 | @Controller 32 | class VetController { 33 | 34 | private final VetRepository vets; 35 | 36 | @Autowired 37 | public VetController(VetRepository clinicService) { 38 | this.vets = clinicService; 39 | } 40 | 41 | @RequestMapping(value = { "/vets.html" }) 42 | public String showVetList(MapVet
domain objects All method names are compliant with Spring Data naming
27 | * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
28 | *
29 | * @author Ken Krebs
30 | * @author Juergen Hoeller
31 | * @author Sam Brannen
32 | * @author Michael Isvy
33 | */
34 | public interface VetRepository extends RepositoryVet
s from the data store.
38 | *
39 | * @return a Collection
of Vet
s
40 | */
41 | @Transactional(readOnly = true)
42 | @Cacheable("vets")
43 | CollectionVisit
domain objects All method names are compliant with Spring Data naming
26 | * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
27 | *
28 | * @author Ken Krebs
29 | * @author Juergen Hoeller
30 | * @author Sam Brannen
31 | * @author Michael Isvy
32 | */
33 | public interface VisitRepository extends RepositoryVisit
to the data store, either inserting or updating it.
37 | *
38 | * @param visit the Visit
to save
39 | * @see BaseEntity#isNew
40 | */
41 | void save(Visit visit) throws DataAccessException;
42 |
43 | ListException message
9 | 10 | 11 | -------------------------------------------------------------------------------- /petclinic/src/main/resources/templates/fragments/inputField.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /petclinic/src/main/resources/templates/fragments/selectField.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 28 | 29 | -------------------------------------------------------------------------------- /petclinic/src/main/resources/templates/owners/createOrUpdateOwnerForm.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 |Name | 15 |16 | |
---|---|
Address | 19 |20 | |
City | 23 |24 | |
Telephone | 27 |28 | |
45 |
|
55 |
56 |
|
77 |
Name | 13 |Address | 14 |City | 15 |Telephone | 16 |Pets | 17 |
---|---|---|---|---|
22 | 23 | | 24 |25 | | 26 | | 27 | | 28 | |
Name | 16 |Birth Date | 17 |Type | 18 |Owner | 19 |
---|---|---|---|
23 | | 25 | | 26 | | 28 | |
Date | 52 |Description | 53 |
---|---|
56 | | 57 | |
Name | 14 |Specialties | 15 |
---|---|
20 | | none | 23 |
View 30 | as XML | 31 |View as JSON | 32 |