0711 ~ 0717


# 0711 ~ 0717

# 0711 - @AttributeOverrides ๋งคํ•‘ ์ •๋ณด ์žฌ์ •์˜

@MappedSuperclass๋ฅผ ํ†ตํ•ด ์ƒ์† ๋ฐ›์€ ๊ฒฝ์šฐ๋‚˜ @Embedded๋ฅผ ํ†ตํ•ด ๋‹ค๋ฅธ ๊ฐ์ฒด๋ฅผ ํ•„๋“œ์— ์„ ์–ธํ•œ ๊ฒฝ์šฐ ํ•ด๋‹น ์—”ํ‹ฐํ‹ฐ์—์„œ๋Š” ๋‹ค๋ฅธ ์ปฌ๋Ÿผ๋ช…์„ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์„ ๋•Œ๊ฐ€ ์žˆ๋‹ค. ์ด๋Ÿฌํ•œ ๊ฒฝ์šฐ์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์–ด๋…ธํ…Œ์ด์…˜์ด๋‹ค.
@AttributeOverride ํ˜น์€ @AttributeOverrides๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

@MappedSuperclass
public class Vehicle {
    @Id
    @GeneratedValue
    private Integer id;
    private String identifier;
    private Integer numberOfWheels;
    
    // standard getters and setters
}
@Entity
@AttributeOverride(name = "identifier", column = @Column(name = "VIN"))
public class Car extends Vehicle {
    private String model;
    private String name;

    // standard getters and setters
}

๋ถ€๋ชจ ํด๋ž˜์Šค(Vehicle)์˜ identifier ์†์„ฑ์„ VIN์œผ๋กœ ์žฌ์ •์˜ํ•˜์—ฌ ์‚ฌ์šฉํ•จ

@Entity
@AttributeOverrides({
	@AttributeOverride(name = "id", column = @Column(name = "CAR_ID"))
	@AttributeOverride(name = "identifier", column = @Column(name = "VIN"))
})
public class Car extends Vehicle {
    private String model;
    private String name;

    // standard getters and setters
}

์—ฌ๋Ÿฌ ํ•„๋“œ๋ฅผ ์žฌ์ •์˜ํ•  ์ˆ˜ ์žˆ๋‹ค.

# ์ž„๋ฒ ๋””๋“œ ํƒ€์ž… ์† ์ž„๋ฒ ๋””๋“œ ํƒ€์ž… ์†์„ฑ ์žฌ์ •์˜ํ•˜๊ธฐ

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Setter
@Getter
public class Member{

    @Id @GeneratedValue
    @Column(name = "MEMBER_ID")
    private Long id;


    private String name;

    @Embedded
    @AttributeOverrides({
            @AttributeOverride(name = "city", column = @Column(name = "HOME_CITY")),
            @AttributeOverride(name = "street", column = @Column(name = "HOME_STREET")),
            @AttributeOverride(name = "zipcode.zip", column = @Column(name = "HOME_ZIP")),
            @AttributeOverride(name = "zipcode.plusFour", column = @Column(name = "HOME_PLUS_FOUR")),
    })
    private Address homeAddress;


    @Embedded
    @AttributeOverrides({
            @AttributeOverride(name = "city", column = @Column(name = "COMPANY_CITY")),
            @AttributeOverride(name = "street", column = @Column(name = "COMPANY_STREET")),
            @AttributeOverride(name = "zipcode.zip", column = @Column(name = "COMPANY_ZIP")),
            @AttributeOverride(name = "zipcode.plusFour", column = @Column(name = "COMPANY_PLUS_FOUR")),
    })
    private Address companyAddress;


}
@Embeddable
public class Address {

    private String city;
    private String street;

    @Embedded
    private Zipcode zipcode;
}
@Embeddable
public class Zipcode {

    private String zip;
    private String plusFour;
}

name์— .์„ ํ†ตํ•ด ์„ค์ •


# 0712 - ๋ฐฑ์—”๋“œ API ํŒจํ„ด - ๋ ˆ์ด์–ด๋“œ ์•„ํ‚คํ…์ฒ˜ ํŒจํ„ด(layered architecture)

๊ฐœ๋ฐœ ๋‹จ๊ณ„์—์„œ ์ข‹์€ ์ฝ”๋“œ์˜ ๊ตฌ์กฐ๋ฅผ ์ƒ๊ฐํ•˜๋Š” ๊ฒƒ์€ ์‰ฝ์ง€ ์•Š๋‹ค. ์ฝ”๋“œ ์•„ํ‚คํ…์ฒ˜๋ฅผ ๊ตฌ์‚ฌํ•  ๋•Œ๋Š”

  • ํ™•์žฅ์„ฑ(extensibility)
  • ์žฌ์‚ฌ์šฉ์„ฑ(reusability)
  • ์œ ์ง€ ๋ณด์ˆ˜ ๊ฐ€๋Šฅ์„ฑ(maintainability)
  • ๊ฐ€๋…์„ฑ(readability)
    ์™€ ๊ฐ™์€ ์š”์†Œ๋“ค์„ ์—ผ๋‘ํ•ด์•ผ ํ•œ๋‹ค.

๋‹คํ–‰์ด๋„ ์ฝ”๋“œ์˜ ๊ตฌ์กฐ๋ฅผ ์–ด๋–ป๊ฒŒ ๊ตฌ์ƒํ•˜๊ณ  ๊ด€๋ฆฌํ•ด์•ผ ํ•˜๋Š”์ง€๋Š” ์ด๋ฏธ ๋งŽ์ด ๋‹ค๋ฃจ์–ด์กŒ์œผ๋ฉฐ, ๊ทธ์— ๊ด€ํ•œ ์ •์„ฑ์ด๋‚˜ ํŒจํ„ด์€ ๋งŽ์ด ๋‚˜์™€ ์žˆ๋‹ค. ๊ทธ ์ค‘์—์„œ ๋ฐฑ์—”๋“œ API ์ฝ”๋“œ์— ๊ฐ€์žฅ ๋„๋ฆฌ ์ ์šฉ๋˜๋Š” ํŒจํ„ด ์ค‘ ํ•˜๋‚˜๋Š” ๋ ˆ์ด์–ด๋“œ ์•„ํ‚คํ…์ฒ˜ ํŒจํ„ด์ด๋‹ค.

Multi-tier ์•„ํ‚คํ…์ฒ˜ ํŒจํ„ด์ด๋ผ๊ณ ๋„ ํ•˜๋Š” ๋ ˆ์ด์–ด๋“œ ์•„ํ‚คํ…์ฒ˜๋Š” ์ฝ”๋“œ๋ฅผ ๋…ผ๋ฆฌ์ ์ธ ๋ถ€๋ถ„ ํ˜น์€ ์—ญํ• ์— ๋”ฐ๋ผ ๋…๋ฆฝ๋œ ๋ชจ๋“ˆ๋กœ ๋‚˜๋ˆ„์–ด์„œ ๊ตฌ์„ฑํ•˜๋Š” ํŒจํ„ด์ด๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ฐ ๋ชจ๋“ˆ์ด ์„œ๋กœ์˜ ์˜์กด๋„์— ๋”ฐ๋ผ ์ธต์ธตํžˆ ์Œ“๋“ฏ์ด ์—ฐ๊ฒฐ๋˜์–ด์„œ ์ „์ฒด์˜ ์‹œ์Šคํ…œ์„ ๊ตฌํ˜„ํ•˜๋Š” ๊ตฌ์กฐ์ด๋‹ค. ๊ทธ๋ž˜์„œ ๋งˆ์น˜ ๋ ˆ์ด์–ด(layer)๋ฅผ ์Œ“์•„ ๋†“์€ ๊ฒƒ ๊ฐ™์€ ํ˜•ํƒœ์˜ ๊ตฌ์กฐ๊ฐ€ ๋œ๋‹ค.

๊ฐ ์‹œ์Šคํ…œ ๋งˆ๋‹ค ๊ฒฝ์šฐ๊ฐ€ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์œผ๋‚˜ ์ผ๋ฐ˜์ ์œผ๋กœ ๋ณดํ†ต ๋‹ค์Œ๊ณผ ๊ฐ™์€ 3๊ฐœ์˜ ๋ ˆ์ด์–ด๊ฐ€ ์กด์žฌํ•œ๋‹ค.

  • presentation layer
  • business layer
  • persistence

image

# Presentation layer (User Interface)

Presentation layer๋Š” ํ•ด๋‹น ์‹œ์Šคํ…œ์„ ์‚ฌ์šฉํ•˜๋Š” ์‚ฌ์šฉ์ž ํ˜น์€ ํด๋ผ์ด์–ธํŠธ ์‹œ์Šคํ…œ๊ณผ ์ง์ ‘์ ์œผ๋กœ ์—ฐ๊ฒฐ๋˜๋Š” ๋ถ€๋ถ„์ด๋‹ค. ์›น์‚ฌ์ดํŠธ์—์„œ๋Š” UI ๋ถ€๋ถ„์— ํ•ด๋‹นํ•˜๊ณ  ๋ฐฑ์—”๋“œ API์—์„œ๋Š” ์—”ํŠธํฌ์ธํŠธ ๋ถ€๋ถ„์— ํ•ด๋‹นํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ presentation layer์—์„œ API์˜ ์—”๋“œํฌ์ธํŠธ๋“ค์„ ์ •์˜ํ•˜๊ณ  ์ „์†ก๋œ HTTP ์š”์ฒญ(request)๋ฅผ ์ฝ์–ด ๋“ค์ด๋Š” ๋กœ์ง์„ ๊ตฌํ˜„ํ•œ๋‹ค. ํ•˜์ง€๋งŒ ๊ทธ ์ด์ƒ์˜ ์—ญํ• ์€ ๋‹ด๋‹นํ•˜์ง€ ์•ˆํ”๋‹ค. ์‹ค์ œ ์‹œ์Šคํ…œ์ด ๊ตฌํ˜„ํ•˜๋Š” ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์€ ๋‹ค์Œ ๋ ˆ์ด์–ด๋กœ ๋„˜๊ธฐ๊ฒŒ ๋œ๋‹ค.

  • EndPoint
  • Authentication
  • JSON Translation

# Business lyaer (Business Logic)

Business layer๋ผ๋Š” ์ด๋ฆ„ ๊ทธ๋Œ€๋กœ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ๊ตฌํ˜„ํ•˜๋Š” ๋ถ€๋ถ„์ด๋‹ค. ์‹ค์ œ ์‹œ์Šคํ…œ์ด ๊ตฌํ˜„ํ•ด์•ผํ•˜๋Š” ๋กœ์ง์„ ์ด ๋ ˆ์ด์–ด์—์„œ ๊ตฌํ˜„ํ•˜๊ฒŒ ๋œ๋‹ค. ๋ฐฑ์—”๋“œ API์—์„œ๋Š” Presentation layer์—์„œ ์ „์†ก๋œ ์š”์ฒญ์„ ์ฝ์–ด๋“ค์—ฌ ์š”์ฒญ์— ๋งž๊ฒŒ ๋™์ž‘ํ•˜๋Š” ๋กœ์ง์„ ๊ตฌํ˜„ํ•˜๋ฉด ๋œ๋‹ค.

  • Business Logic
  • Validation
  • Authoristion

# Persistence layer (Data Access)

Persistence layer๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€ ๊ด€๋ จ๋œ ๋กœ์ง์„ ๊ตฌํ˜„ํ•˜๋Š” ๋ถ€๋ถ„์ด๋‹ค. Business layer์—์„œ ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ์ƒ์„ฑ, ์ˆ˜์ •, ์ฝ๊ธฐ ๋“ฑ์„ ์ฒ˜๋ฆฌํ•˜์—ฌ ์‹ค์ œ๋กœ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅ, ์ˆ˜์ •, ์ฝ๊ธฐ ์ž‘์—…์„ ํ•˜๋Š” ์—ญํ•˜์„ ํ•œ๋‹ค.

  • Storage Logic

# ๋ ˆ์ด์–ด๋“œ ์•„ํ‚คํ…์ฒ˜์˜ ํ•ต์‹ฌ ์š”์†Œ

image ๋ ˆ์ด์–ด๋“œ ์•„ํ‚คํ…์ฒ˜์˜ ํ•ต์‹ฌ ์š”์†Œ๋Š” ๋‹จ๋ฐฉํ–ฅ ์˜์กด์„ฑ์ด๋‹ค. ๊ฐ๊ฐ์˜ ๋ ˆ์ด์–ด๋Š” ์˜ค์ง ์ž๊ธฐ๋ณด๋‹ค ํ•˜์œ„์— ์žˆ๋Š” ๋ ˆ์ด์–ด์—๋งŒ ์˜์กดํ•œ๋‹ค.
๋˜ ๋‹ค๋ฅธ ํ•ต์‹ฌ ์š”์†Œ๋Š” "sepration of concerns"์ด๋‹ค. ์ฆ‰ ๊ฐ ๋ ˆ์ด์–ด์˜ ์—ญํ• ์ด ๋ช…ํ™•ํ•˜๋‹ค๋Š” ์˜๋ฏธ์ด๋‹ค.
์œ„์™€ ๊ฐ™์€ ์š”์†Œ๋“ค ๋•Œ๋ฌธ์— ๋ ˆ์ด์–ด๋“œ ์•„ํ‚คํ…์ฒ˜์˜ ๊ตฌ์กฐ๋กœ ์ฝ”๋“œ๋ฅผ ๊ตฌํ˜„ํ•˜๋ ค๋ฉด ๊ฐ ๋ ˆ์ด์–ด๊ฐ€ ๋…๋ฆฝ์ ์ด๊ณ  ์—ญํ• ์ด ๋ถ„๋ช…ํ•˜๋ฏ€๋กœ ์ฝ”๋“œ์˜ ํ™•์žฅ์„ฑ์ด ๋†’์•„์ง„๋‹ค. ์ฝ”๋“œ์˜ ๊ตฌ์กฐ๋ฅผ ํŒŒ์•…ํ•˜๊ธฐ ์‰ฌ์šธ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅ์„ฑ๋„ ๋†’์•„์ง„๋‹ค.
๋˜ํ•œ ์—ญํ• ์ด ๋ช…ํ™•ํ•˜๊ฒŒ ๋‚˜๋‰˜์–ด ์žˆ์œผ๋ฏ€๋กœ ๊ฐ ๋ ˆ์ด์–ด๋ฅผ ํ…Œ์ŠคํŠธ ํ•˜๋Š” ํ…Œ์ŠคํŠธ ์ฝ”๋“œ์˜ ์ž‘์„ฑ๋„ ํ›จ์”ฌ ์ˆ˜์›”ํ•ด์ง„๋‹ค.


# 0714 - IntelliJ์˜ .http ์‚ฌ์šฉ

# .http ์žฅ์ 

  • Code highlighting
  • ์ฝ”๋“œ ์ž๋™ ์™„์„ฑ
  • ์ง๊ด€์ ์ธ HttpRequest ๊ตฌ์กฐ
  • Request Body์— ์“ธ JSON ๋“ฑ ์ ๊ทน์  ์ง€์›(Language injections)
  • ๋ฆฌํŒฉํ† ๋ง
  • ํŒŒ์ผ ๊ด€๋ฆฌ๊ฐ€๋Šฅ

# .http ์‚ฌ์šฉ๋ฒ•

# GET ์š”์ฒญ

  • HTTP Request ํŒŒ์ผ์ƒ์„ฑ
GET https://www.devbeginner.com

ํŒŒ์ผ์˜ ์ฒซ์ค„์—๋Š” HTTP Method์™€ URL
๋‘˜์งธ์ค„์—๋Š” RequestHeader ์ž‘์„ฑ

# POST ์š”์ฒญ

POST https://localhost:8080/group
Content-Type: application/json

{
  "groupName": "๊ทธ๋ฃน๋ช…",
  "members": [
    "ํšŒ์›1",
    "ํšŒ์›2",
    "ํšŒ์›3"
  ],
  "date": {
    "year": 2018,
    "month": 1,
    "day": 24
  }
}

# json์„ ํŒŒ์ผ๋กœ ์‚ฌ์šฉ๊ฐ€๋Šฅ

POST http://localhost:8080/group
Content-Type: application/json

< ./post.json
  • ๊บฝ์‡ (<)๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํŒŒ์ผ ์œ„์น˜๋ฅผ ์ง€์ •ํ•˜๋ฉด ํ•ด๋‹น ํŒŒ์ผ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ „์†ก
  • Request Header์™€ ๋ฐ์ดํ„ฐํ˜•ํƒœ๋ฅผ ๋ณ€๊ฒฝํ•˜์—ฌ multipart/form-data์™€ ๊ฐ™์ด ํŒŒ์ผ ์—…๋กœ๋“œ, ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ ํ…Œ์ŠคํŠธ ๊ฐ€๋Šฅ

# Request Header ์ˆ˜์ •

GET http://localhost:8080/real/hello
Authorization: Bearer {token}
GET https://localhost:8080/cookie
Cookie: user=ahnjs
  • key=value ํ˜•์‹์œผ๋กœ ์ž‘์„ฑ

# Log

Intellij์˜ .http ์š”์ฒญ์€ ๋ชจ๋‘ ๋กœ๊ทธ๋กœ ๋‚จ๊ฒจ์ง„๋‹ค. ๋กœ๊ทธ ํŒŒ์ผ ์œ„์น˜ ํ”„๋กœ์ ํŠธํด๋”/.idea/httpRequests/

# Controller๋กœ ์ž๋™์ƒ์„ฑ๊ฐ€๋Šฅ

Last update: September 13, 2022 21:44
Contributors: ahnjs