gringrape / coding-life

여러가지 실험, 문제 풀이, 연습
1 stars 0 forks source link

Spring - petClinic #27

Closed gringrape closed 1 year ago

gringrape commented 1 year ago

source: https://github.com/spring-projects/spring-petclinic.git

gringrape commented 1 year ago

petClinic application 실행.

gringrape commented 1 year ago

Owner, Pet, Visit

gringrape commented 1 year ago

프로젝트 살펴보기에서 하는 일들.

image
gringrape commented 1 year ago

프로젝트 구조

gringrape commented 1 year ago

view 의 위치

gringrape commented 1 year ago

로그 모드 변경 - application.properties

gringrape commented 1 year ago

구현

gringrape commented 1 year ago

lastName 이 아닌 firstName 으로 owner 검색

쿼리를 직접지정하는 방식.

@Query("SELECT DISTINCT owner FROM Owner owner left join  owner.pets WHERE owner.firstName LIKE :firstName% ")
@Transactional(readOnly = true)
Page<Owner> findByFirstName(@Param("firstName") String firstName, Pageable pageable);
gringrape commented 1 year ago

@Query annotation -> named parameter https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.named-parameters

gringrape commented 1 year ago

H2 Data Types

gringrape commented 1 year ago

Owner table 에 age 정보 추가.

CREATE TABLE owners (
  id         INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
  first_name VARCHAR(30),
  last_name  VARCHAR_IGNORECASE(30),
  age        SMALLINT,
  address    VARCHAR(255),
  city       VARCHAR(80),
  telephone  VARCHAR(20)
);
gringrape commented 1 year ago

Owners에 나이 정보 추가

gringrape commented 1 year ago

Copy down cursor(IntelliJ)

Press ⌥ twice, and then without releasing it, press up or down arrow keys.

See. https://www.jetbrains.com/help/idea/multicursor.html#add-carets-above-or-below-the-current-caret

gringrape commented 1 year ago

Owner 조회 화면에 age 추가

image

URL: http://localhost:8080/owners/6

handler:

@GetMapping("/owners/{ownerId}")
public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) {
  ModelAndView mav = new ModelAndView("owners/ownerDetails");
  Owner owner = this.owners.findById(ownerId);
  mav.addObject(owner);
  return mav;
}
gringrape commented 1 year ago

Owner list age 추가

image
gringrape commented 1 year ago

Owner 추가에서 항목에 age 추가

URL: http://localhost:8080/owners/new