728x90 반응형 스프링 Spring/스프링 입문24 [회원 관리 예제 - 백엔드 개발] 회원 도메인과 리포지토리 만들기 회원 도메인과 리포지토리 만들기 회원 객체 public class Member { private Long id; // 시스템이 정해주는 값(sequence) private String name; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } 회원 리포지토리 인터페이스 public interface MemberRepository { Member save(Member member); Optional findById(Long id); // n.. 2022. 1. 11. [회원 관리 예제 - 백엔드 개발] 비즈니스 요구사항 정리 비즈니스 요구사항 정리 데이터: 회원ID, 이름 기능: 회원 등록, 조회 아직 데이터 저장소가 선정되지 않음(가상의 시나리오) 컨트롤러 웹 MVC의 컨트롤러 역할 서비스 핵심 비즈니스 로직 구현 리포지토리 데이터베이스에 접근, 도메인 객체를 DB에 저장하고 관리 도메인 비즈니스 도메인 객체, 예) 회원, 주문, 쿠폰 등등 주로 데이터베이스에 저장하고 관리됨 아직 데이터 저장소가 선정되지 않아서, 우선 인터페이스로 구현 클래스를 변경할 수 있도록 설계 데이터 저장소는 RDB, NoSQL 등등 다양한 저장소를 고민중인 상황으로 가정 개발을 진행하기 위해서 초기 개발 단계에서는 구현체로 가벼운 메모리 기반의 데이터 저장소 사용 2022. 1. 11. [스프링 웹 개발 기초] API API // HelloController.java @GetMapping("hello-string") @ResponseBody // http body 부분에 데이터를 직접 넣겠다. public String helloString(@RequestParam("name") String name) { return "hello " + name; } 결과 페이지 소스 보기 // HelloController.java @GetMapping("hello-api") @ResponseBody public Hello helloApi(@RequestParam("name") String name) { Hello hello = new Hello(); hello.setName(name); return hello; // 객체를 반환하면 .. 2022. 1. 10. [스프링 웹 개발 기초] MVC와 템플릿 엔진 MVC와 템플릿 엔진 view : 화면을 그리는데 모든 역량을 집중 Controller : 비즈니스 로직, 내분 처리에 집중 resource > templates > hello-template.html 생성 hello! empty // HelloController.java @GetMapping("hello-mvc") // @RequestParam : 외부에서 파라미터를 받을거다 public String helloMvc(@RequestParam("name") String name, Model model) { model.addAttribute("name", name); return "hello-template"; } 결과 로그를 확인 하면 아래와 같은 WARN을 발견할 수 있다. WARN 27040 --- .. 2022. 1. 9. [스프링 웹 개발 기초] 정적 컨텐츠 정적 컨텐츠 스프링 부튼 정적 컨테츠 기능 https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/spring-bootfeatures.html#boot-features-spring-mvc-static-content 7.1.5. Static Content By default, Spring Boot serves static content from a directory called /static (or /public or /resources or /META-INF/resources) in the classpath or from the root of the ServletContext. It uses the ResourceHttpRequestHa.. 2022. 1. 8. [프로젝트 환경설정] 빌드하고 실행하기 IntelliJ 실행을 멈춘뒤에 다음을 진행 1. cmd 창에서 아래 명령어 실행 1) gradlew build 2) cd build/libs 3) java -jar hello-spring-0.0.1-SNAPSHOT.jar 4) 실행 확인 2. Git bash 에서 실행 1. ./gradlew build 2. cd build/libs 3. java -jar hello-spring-0.0.1-SNAPSHOT.jar 4. 실행 확인 ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk-11.0.11\bin Please set the JAVA_HOME variable in your environment to match the lo.. 2022. 1. 8. [프로젝트 환경설정] View 환경설정 View 환경설정 Welcome Page 만들기 위치 : resource > static > index.html Hello hello URL : http://localhost:8080 접속 결과 스프링 부트가 제공하는 Welcome Page 기능 참고 https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/spring-boot-features.html#boot-features-spring-mvc-welcome-page 7.1.6. Welcome Page Spring Boot supports both static and templated welcome pages. It first looks for an index.html file in t.. 2022. 1. 7. [프로젝트 환경설정] 프로젝트 생성 https://start.spring.io/ 에 접속하여 아래와 같이 작성후 GENERATE를 눌러 다운을 받는다. 받은 파일을 IntelliJ로 실행 IntelliJ버전은 Gradle을 통해서 실행하는 것이 기본 설정이며 이렇게 하면 실행속도가 느리다. 설정을 아래와 같이 수정하여 자바로 바로 실행하여 실행속도를 더 빠르게 변경한다. File > Settings... HelloSpringApplication.java 실행 http://localhost:8080/ 에 접속하여 아래와 같이 나오면 제대로 된 것이다. 인프런 강의 "스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술"을 정리한 것 입니다. [무료] 스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술.. 2022. 1. 6. 이전 1 2 3 다음 728x90 반응형