본문 바로가기

전체 글474

회원 도메인과 리포지토리 만들기 패키지 구성 Member 클래스 package hello.hellospring.domain; public class Member { private Long id; 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; } } MemberRepository 인터페이스 package hello.hellospring.repository; import hello.hellospring.domain.Member; import .. 2022. 8. 5.
비즈니스 요구사항 정리 데이터: 회원ID, 이름 기능: 회원 등록, 조회 아직 데이터 저장소가 정해지지 않았다는 설정 일반적인 웹 애플리케이션 계층 구조 컨트롤러: 웹 mvc의 컨트롤러 역할 서비스: 핵심 비즈니스 로직 구현 리포지토리: 데이터베이스에 접근, 도메인 객체를 DB에 저장하고 관리 도메인: 비즈니스 도메인 객체 아직 데이터 저장소가 선정되지 않아서, 우선 인터페이스로 구현 클래스를 변경할 수 있도록 설계 개발을 진행하기 위해서 초기 개발 단계에서는 구현체로 가벼운 메모리 기반의 데이터 저장소 사용 2022. 8. 5.
API 컨트롤러 작성 @GetMapping("hello-string") @ResponseBody public String helloString(@RequestParam("name") String name) { return "hello " + name; // "hello spring" } 인텔리제이 자동완성 단축키: ctrl + alt + enter 실행 @ResponseBody: 리턴 데이터를 그대로를 보여주기 위해 필요한 어노테이션 json으로 데이터 보여주는 방법 (key, value로 구성되어있다.) 컨트롤러 작성 @GetMapping("hello-api") @ResponseBody public Hello helloApi(@RequestParam("name") String name) { Hello hell.. 2022. 8. 4.
MVC와 템플릿 엔진 MVC: Model, View, Controller Cotroller 작성 @GetMapping("hello-mvc") public String helloMvc(@RequestParam("name") String name, Model model) { model.addAttribute("name", name); return "hello-template"; } view 작성 hello! empty 파라미터를 url에 안적을때는 에러가 발생 인텔리제이에서 ctrl + p 명령어를 통해서 파라미터 정보를 확인이 가능하다 required가 기본적으로 true이기 때문에 필수로 데이터 입력을 해주어야한다. 값이 정상적으로 입력이 되었다면 template폴더안에 해당 html파일을 찾아 반환해준다. 아래는 정상 동작 2022. 8. 3.
정적 컨텐츠 공식문서 Spring Boot Reference Documentation Spring Boot Reference Documentation This section goes into more detail about how you should use Spring Boot. It covers topics such as build systems, auto-configuration, and how to run your applications. We also cover some Spring Boot best practices. Although there is nothing particularly spe docs.spring.io 프로젝트의 static이라는 폴더명에 파일을 넣어주면 스프링 부트에서 컨트롤러 설정을 하.. 2022. 8. 3.
스프링부트 프로젝트 jar 파일로 빌드하고 실행하기 나는 윈도우 환경을 사용해서 강의와 다른 명령어를 사용해야 했다. 우선 해당 프로젝트 폴더로 들어가서 명령어를 순서대로 입력한다. 1. ./gradlew.bat clean build -> 프로젝트를 빌드한다. 2. cd build -> build 폴더로 이동 3. cd libs -> jar 파일이 생성된 libs 폴더로 이동 4. java -jar hello-spring-0.0.1-SNAPSHOT.jar -> jar 파일 실행 프로젝트를 배포할때 jar파일을 생성하여 해당 서버에 옮긴 후 jar 파일을 실행시켜주면 된다. 2022. 8. 1.