-
Notifications
You must be signed in to change notification settings - Fork 164
[Spring MVC] 진웨이얀 미션 제출합니다. #505
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
base: zinyan
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package roomescape; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
|
||
@Controller | ||
public class HomeController { | ||
|
||
@GetMapping("/") | ||
public String home() { | ||
return "home"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package roomescape; | ||
|
||
|
||
public record Reservation(long id, String name, String date, String time) {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. record 를 사용하셨네요! class 와 record 의 차이점이 무엇인가요? record를 사용하면 장점이 무엇인가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. class는 저희가 일반적으로 사용하는 data와 operations모두 가질 수 있고, 생성자, getter등은 직접 구현해야되는데 record 같은 경우에는 스프링을 배울 때 처음 알았던 불변 data 저장 할 수 있는 기능인데 생성자, getter등을 자동으로 생성해줘서 더 간결해진다는 장점이 있습니다. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package roomescape; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Controller | ||
public class ReservationController { | ||
|
||
// Temporary data | ||
private final List<Reservation> reservations = new ArrayList<>( | ||
List.of( | ||
new Reservation(1L, "브라운", "2023-01-01", "10:00"), | ||
new Reservation(2L, "브라운", "2023-01-02", "11:00"), | ||
new Reservation(3L, "브라운", "2023-01-03", "12:00") | ||
) | ||
); | ||
|
||
// render reservation.html | ||
@GetMapping("/reservation") | ||
public String reservationPage() { | ||
return "reservation"; | ||
} | ||
|
||
// JSON list | ||
@GetMapping("/reservations") | ||
@ResponseBody | ||
public List<Reservation> list() { | ||
return reservations; | ||
} | ||
} |
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.
자바엔 long과 Long 타입이 있습니다. 이 글 을 참고하여 둘의 차이점과 각각 어느 때에 쓰이는지 알아보면 좋을 것 같습니다.
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.
감사합니다!! 찾아 봤는데 long은 저희가 늘 쓰는 primitive type이라 int의 범위를 초과하는 숫자를 다룰 때 쓰고, Long은 long을 객체 형태로 감싼 wrapper 클래스라서 다양한 메서드(parseLong())등을 사용하고 싶을 때 쓰는것 같습니다.