[Spring Boot] 1. 스프링부트 맛보기 (1)

김주희's avatar
Mar 17, 2025
[Spring Boot] 1. 스프링부트 맛보기 (1)

0. 프로젝트 생성

notion image
 
 
notion image
 
notion image
 
 

1. 코드 작성

notion image
 
package org.example.first.controller; import org.example.first.repository.UserRepository; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; // 책임 : 외부 클라이언트 요청 받기, 응답 하기 @RestController public class UserController { UserRepository userRepository = new UserRepository(); // GET 요청 (url을 브라우저에 적기, 하이퍼링크) // http://localhost:8080/user/1 @GetMapping("/user/1") public String getData(){ return userRepository.getData(); } @GetMapping("/user") public String getDataAll(){ return userRepository.getDataAll(); } }
 
package org.example.first.repository; // 책임 : 데이터 관리자 (DB, FileSystem, 외부 서버) public class UserRepository { public String getData(){ return "user 1"; } public String getDataAll(){ return "user 1, user 2, user 3, user 4, user 5"; } }
notion image
 
 
notion image
Share article

jay0628