스프링

 

 

초급자를 위해 준비한
[웹 개발, 백엔드] 강의입니다.

Spring-PetClinic이라는 스프링 공식 예제 프로젝트의 코드를 보며, 다음의 스프링의 핵심 기능을 쉽고 빠르게 이해할 수 있습니다.

개정판 강좌를 수강해볼까요? 
예제로 배우는 스프링 입문(개정판) 바로가기 >> 

 

https://www.inflearn.com/course/spring#

 

 

예제로 배우는 스프링 입문 

https://www.inflearn.com/course/spring_revised_edition

 

 

소스 :

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

 

 

 

강의자료 : https://drive.google.com/file/d/1Q8LGrUKzV_EX6MToQaynhv0CnPDCTgbM/view

https://github.com/braverokmc79/course-petclinic/blob/main/예제로배우슨%20스프링입문.pdf

 

 

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface LogExecutionTime {

}

 

@Component
@Aspect
public class LogAspect {
    Logger logger = LoggerFactory.getLogger(LogAspect.class);
    @Around("@annotation(LogExecutionTime)")
    public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        Object proceed = joinPoint.proceed();
        stopWatch.stop();
        logger.info(stopWatch.prettyPrint());
        return proceed;
    }
}

 

 

 

 

1. 프로젝트 구조

이미지크게

 

 

2. 테이블 구조

 

이미지 크게

 

 

 

 

2. 공통모델

 

이미지크게

 

 

 

4. 엔티티와   DB 관계 

 

이미지크게

 

 

 

 

 

 

 

5 . 화면

1)메인화면

 

2)펫 소유자 찾기 화면

 

3)펫 소유자 등록화면

 

4)펫 소유자 목록화면

 

5)펫 소유자 상세화면

 

 

6)수의사 목록화면

 

 

7)에러 화면

 

 

 

수의사

 

VetRepository

/*
 * 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 org.springframework.cache.annotation.Cacheable;
import org.springframework.dao.DataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;

/**
 * <code>Vet</code> 도메인 개체에 대한 리포지토리 클래스 모든 메서드 이름은 호환됩니다.
 * 이 인터페이스를 Spring용으로 쉽게 확장할 수 있도록 Spring Data 명명 규칙 사용
 * 데이터. 보다:
 * https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation
 *
 * @author Ken Krebs
 * @author Juergen Hoeller
 * @author Sam Brannen
 * @author Michael Isvy
 */
public interface VetRepository extends Repository<Vet, Integer> {

	/**
	 * 데이터 저장소에서 모든 <code>Vet</code>를 검색합니다.
	 * @return <code>Vet</code>의 <code>컬렉션</code>
	 */
	@Transactional(readOnly = true)
	@Cacheable("vets")
	Collection<Vet> findAll() throws DataAccessException;

	/**
	 * 페이지의 데이터 저장소에서 모든 <code>Vet</code> 검색
	 * @param pageable
	 * @return
	 * @throws DataAccessException
	 */
	@Transactional(readOnly = true)
	@Cacheable("vets")
	Page<Vet> findAll(Pageable pageable) throws DataAccessException;

}

 

 

 

 

 

 

VetController

/*
 * 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.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Juergen Hoeller
 * @author Mark Fisher
 * @author Ken Krebs
 * @author Arjen Poutsma
 */
@Controller
class VetController {

	private final VetRepository vetRepository;

	public VetController(VetRepository clinicService) {
		this.vetRepository = clinicService;
	}

	@GetMapping("/vets.html")
	public String showVetList(@RequestParam(defaultValue = "1") int page, Model model) {
		// Here we are returning an object of type 'Vets' rather than a collection of Vet
		// objects so it is simpler for Object-Xml mapping
		Vets vets = new Vets();
		Page<Vet> paginated = findPaginated(page);
		vets.getVetList().addAll(paginated.toList());
		return addPaginationModel(page, paginated, model);

	}

	private String addPaginationModel(int page, Page<Vet> paginated, Model model) {
		List<Vet> listVets = paginated.getContent();
		model.addAttribute("currentPage", page);
		model.addAttribute("totalPages", paginated.getTotalPages());
		model.addAttribute("totalItems", paginated.getTotalElements());
		model.addAttribute("listVets", listVets);
		return "vets/vetList";
	}

	private Page<Vet> findPaginated(int page) {
		int pageSize = 5;
		Pageable pageable = PageRequest.of(page - 1, pageSize);
		return vetRepository.findAll(pageable);
	}

	@GetMapping({ "/vets" })
	public @ResponseBody Vets showResourcesVetList() {
		// Here we are returning an object of type 'Vets' rather than a collection of Vet
		// objects so it is simpler for JSon/Object mapping
		Vets vets = new Vets();
		vets.getVetList().addAll(this.vetRepository.findAll());
		return vets;
	}

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

about author

PHRASE

Level 60  라이트

드는 돌에 낯 붉는다 , 원인이 있어서 결과가 생긴다는 말.

댓글 ( 4)

댓글 남기기

작성