스프링 프로젝트 살펴보기

Back-End/Spring 2019. 6. 2. 23:24
728x90
반응형

-Petclinic 프로젝트-


CRUD 프로젝트 이다.

(Create, Read, Update, Delete)


도메인이 Petclinic이기 때문에 도메인 클래스를 확인.


  전체적인 구조


  오너가 펫을 가지고 있고, 펫은 여러개를 가질수 있고 여러군데의 병원을 방문할 수 있다.

  수의사는 여러가지의 스페셜리스트 (전문)을 가지고 있다.





Owner 중 일부 (owner는 Pet를 여러개 가질수 있다.)

1
2
 @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
    private Set<Pet> pets;
cs



Pet 는 여러가지 type가 있다. (Pet 중 일부) 그리고 Visit로 이동

(펫이 언제 이 병원에 방문할건지 알아야 하기 때문)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public LocalDate getBirthDate() {
        return this.birthDate;
    }
 
    public PetType getType() {
        return this.type;
    }
 
    public void setType(PetType type) {
        this.type = type;
    }
 
    public Owner getOwner() {
        return this.owner;
    }
 
    protected void setOwner(Owner owner) {
        this.owner = owner;
    }
cs



Visit 도메인 (언제??? 에 해당되는 코드를 출력)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
 * Copyright 2012-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.samples.petclinic.visit;
 
import java.time.LocalDate;
 
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.validation.constraints.NotEmpty;
 
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.samples.petclinic.model.BaseEntity;
 
/**
 * Simple JavaBean domain object representing a visit.
 *
 * @author Ken Krebs
 * @author Dave Syer
 */
@Entity
@Table(name = "visits")
public class Visit extends BaseEntity {
 
    @Column(name = "visit_date")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate date;
 
    @NotEmpty
    @Column(name = "description")
    private String description;
 
    @Column(name = "pet_id")
    private Integer petId;
 
    /**
     * Creates a new instance of Visit for the current date
     */
    public Visit() {
        this.date = LocalDate.now();
    }
 
    public LocalDate getDate() {
        return this.date;
    }
 
    public void setDate(LocalDate date) {
        this.date = date;
    }
 
    public String getDescription() {
        return this.description;
    }
 
    public void setDescription(String description) {
        this.description = description;
    }
 
    public Integer getPetId() {
        return this.petId;
    }
 
    public void setPetId(Integer petId) {
        this.petId = petId;
    }
 
}
 
cs




Vet (수의사) (어떤 전문인지 알기위해서 Specialty로 이동)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * Copyright 2012-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.samples.petclinic.vet;
 
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
 
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlElement;
 
import org.springframework.beans.support.MutableSortDefinition;
import org.springframework.beans.support.PropertyComparator;
import org.springframework.samples.petclinic.model.Person;
 
/**
 * Simple JavaBean domain object representing a veterinarian.
 *
 * @author Ken Krebs
 * @author Juergen Hoeller
 * @author Sam Brannen
 * @author Arjen Poutsma
 */
@Entity
@Table(name = "vets")
public class Vet extends Person {
 
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "vet_specialties", joinColumns = @JoinColumn(name = "vet_id"), inverseJoinColumns = @JoinColumn(name = "specialty_id"))
    private Set<Specialty> specialties; //어떤쪽의 스페셜리스트 인지?? (전문인지)
 
    protected Set<Specialty> getSpecialtiesInternal() {
        if (this.specialties == null) {
            this.specialties = new HashSet<>();
        }
        return this.specialties;
    }
 
    protected void setSpecialtiesInternal(Set<Specialty> specialties) {
        this.specialties = specialties;
    }
 
    @XmlElement
    public List<Specialty> getSpecialties() {
        List<Specialty> sortedSpecs = new ArrayList<>(getSpecialtiesInternal());
        PropertyComparator.sort(sortedSpecs,
                new MutableSortDefinition("name"truetrue));
        return Collections.unmodifiableList(sortedSpecs);
    }
 
    public int getNrOfSpecialties() {
        return getSpecialtiesInternal().size();
    }
 
    public void addSpecialty(Specialty specialty) {
        getSpecialtiesInternal().add(specialty);
    }
 
}
 
cs



Specialty (어느쪽의 전문인지 표시)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 * Copyright 2012-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.samples.petclinic.vet;
 
import java.io.Serializable;
 
import javax.persistence.Entity;
import javax.persistence.Table;
 
import org.springframework.samples.petclinic.model.NamedEntity;
 
/**
 * Models a {@link Vet Vet's} specialty (for example, dentistry).
 *
 * @author Juergen Hoeller
 */
@Entity
@Table(name = "specialties")
public class Specialty extends NamedEntity implements Serializable {
 
}
 
cs




data.sql (쿼리문이 이미 들어가있음)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
INSERT INTO vets VALUES (1'James''Carter');
INSERT INTO vets VALUES (2'Helen''Leary');
INSERT INTO vets VALUES (3'Linda''Douglas');
INSERT INTO vets VALUES (4'Rafael''Ortega');
INSERT INTO vets VALUES (5'Henry''Stevens');
INSERT INTO vets VALUES (6'Sharon''Jenkins');
 
INSERT INTO specialties VALUES (1'radiology');
INSERT INTO specialties VALUES (2'surgery');
INSERT INTO specialties VALUES (3'dentistry');
 
INSERT INTO vet_specialties VALUES (21);
INSERT INTO vet_specialties VALUES (32);
INSERT INTO vet_specialties VALUES (33);
INSERT INTO vet_specialties VALUES (42);
INSERT INTO vet_specialties VALUES (51);
 
INSERT INTO types VALUES (1'cat');
INSERT INTO types VALUES (2'dog');
INSERT INTO types VALUES (3'lizard');
INSERT INTO types VALUES (4'snake');
INSERT INTO types VALUES (5'bird');
INSERT INTO types VALUES (6'hamster');
 
INSERT INTO owners VALUES (1'George''Franklin''110 W. Liberty St.''Madison''6085551023');
INSERT INTO owners VALUES (2'Betty''Davis''638 Cardinal Ave.''Sun Prairie''6085551749');
INSERT INTO owners VALUES (3'Eduardo''Rodriquez''2693 Commerce St.''McFarland''6085558763');
INSERT INTO owners VALUES (4'Harold''Davis''563 Friendly St.''Windsor''6085553198');
INSERT INTO owners VALUES (5'Peter''McTavish''2387 S. Fair Way''Madison''6085552765');
INSERT INTO owners VALUES (6'Jean''Coleman''105 N. Lake St.''Monona''6085552654');
INSERT INTO owners VALUES (7'Jeff''Black''1450 Oak Blvd.''Monona''6085555387');
INSERT INTO owners VALUES (8'Maria''Escobito''345 Maple St.''Madison''6085557683');
INSERT INTO owners VALUES (9'David''Schroeder''2749 Blackhawk Trail''Madison''6085559435');
INSERT INTO owners VALUES (10'Carlos''Estaban''2335 Independence La.''Waunakee''6085555487');
 
INSERT INTO pets VALUES (1'Leo''2010-09-07'11);
INSERT INTO pets VALUES (2'Basil''2012-08-06'62);
INSERT INTO pets VALUES (3'Rosy''2011-04-17'23);
INSERT INTO pets VALUES (4'Jewel''2010-03-07'23);
INSERT INTO pets VALUES (5'Iggy''2010-11-30'34);
INSERT INTO pets VALUES (6'George''2010-01-20'45);
INSERT INTO pets VALUES (7'Samantha''2012-09-04'16);
INSERT INTO pets VALUES (8'Max''2012-09-04'16);
INSERT INTO pets VALUES (9'Lucky''2011-08-06'57);
INSERT INTO pets VALUES (10'Mulligan''2007-02-24'28);
INSERT INTO pets VALUES (11'Freddy''2010-03-09'59);
INSERT INTO pets VALUES (12'Lucky''2010-06-24'210);
INSERT INTO pets VALUES (13'Sly''2012-06-08'110);
 
INSERT INTO visits VALUES (17'2013-01-01''rabies shot');
INSERT INTO visits VALUES (28'2013-01-02''rabies shot');
INSERT INTO visits VALUES (38'2013-01-03''neutered');
INSERT INTO visits VALUES (47'2013-01-04''spayed');
 
cs


728x90
반응형
: