-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
조은채 API 구축 코드 #6
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 첫번째 컨트롤러에서는 강의에서 배운 기본 Spring MVC, 두번째 컨트롤러에서는 RestAPI를 사용해 구현한 점이 좋았습니다~! 실제 구현 결과도 노션 링크로 남겨주세요
@@ -0,0 +1 @@ | |||
spring.application.name=bfp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
backend first project 인가요?🤔
public User getUser(@RequestParam("name") String name, @RequestParam("id") String id) { | ||
return new User(name, Integer.parseInt(id)); | ||
} | ||
static class User { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
내부 클래스를 쓰는것 보다, 별도의 클래스로 분리하는 걸 권장 드리는데요. 어떤 이유일지 한번 생각해보신 후 답변주시면 감사하겠습니다~!
@GetMapping("hello") | ||
public String hello(Model model, @RequestParam("name") String name) { | ||
model.addAttribute("data", name); | ||
return "hello"; // hello.html과 연결 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 컨트롤러에서는 기본 Spring MVC를 쓰셨네요~!
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/api/users") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
취향이지만 써주신 것처럼 api로 Url 구분 두는 방법도 좋은 방법중에 하나긴 합니다~
더 활용해서 api/v1/students 와 같이 버전을 명시하기도 해요
FirstController
: 여러 가지 형태로 텍스트 반환 (return 값, html, json)SecondController
: 사용자 추가, 조회, 삭제