-
Notifications
You must be signed in to change notification settings - Fork 147
[Spring MVC] 한재원 미션 제출합니다 #324
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: breadquokka
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,16 @@ | ||
package roomescape.Controller; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
|
||
@Controller | ||
public class HomeController { | ||
@GetMapping("/") | ||
public String home(Model model1) { | ||
model1.addAttribute("name", "jaewon"); | ||
return "home"; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package roomescape.Controller; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import roomescape.Reservation; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@RestController | ||
//@RequestMapping("/reservation") | ||
public class ReservationController { | ||
|
||
List<Reservation> reservation = new ArrayList<>();// 전역변수. | ||
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. 여기 주석도 마찬가지! |
||
|
||
@GetMapping("/reservationData") | ||
|
||
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. 공백이 이상하게 들어가있네요 🥲 |
||
public List<Reservation> getReservations() { | ||
// 예약 목록을 담을 리스트 생성 | ||
|
||
reservation.add(new Reservation("1", "브라운", "2023-01-01", "10:00")); | ||
reservation.add(new Reservation("2", "브라운", "2023-01-02", "11:00")); | ||
|
||
// 예약 목록 반환 | ||
Comment on lines
+23
to
+28
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. 이 주석도 굳이 없어도 코드를 이해하는 데 문제가 없기 때문에 없어도 될 것 같네요 |
||
return reservation; | ||
} | ||
|
||
|
||
|
||
|
||
@GetMapping(value= "/reservation",produces = "text/html") | ||
public String world(Model model) { | ||
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. "world"라는 메서드 이름은 이 메서드가 무슨 일을 하는지 잘 알려주지 못하는 것 같아요! 다른 이름으로 수정해 보는 건 어떨까요? |
||
model.addAttribute("reservationData", reservation); | ||
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. 이 속성이 html에 존재하는 속성인가요? 어떤 이유로 추가해 주셨나요~? |
||
return "reservationpage";//html 페이지를 못찾아요 | ||
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. html실행이 안되고, reservationpage라는 문자열만 나타나요.. 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.
|
||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package roomescape; | ||
|
||
public class Reservation { | ||
private String id; | ||
private String name; | ||
private String date; | ||
private String time; | ||
Comment on lines
+3
to
+7
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. id가 식별자의 역할을 하고 있는데요, 그렇다면 id가 동일하면 동일한 객체인데, 지금 상태로는 new를 통해 id가 같은 객체를 두 개 만들면 두 객체가 다른 객체로 인식될 거예요. 그 이유는 무엇이고, 이를 방지하기 위해 어떤 것을 할 수 있을까요? |
||
|
||
// 생성자 | ||
public Reservation(String id, String name, String date, String time) { | ||
this.id = id; | ||
this.name = name; | ||
this.date = date; | ||
this.time = time; | ||
} | ||
|
||
// getter와 setter | ||
Comment on lines
+9
to
+17
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. 이러한 주석은 주석 없이도 메서드이름만으로 그 역할을 잘 나타내기 때문에 굳이 필요 없을 것 같습니다! |
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getDate() { | ||
return date; | ||
} | ||
|
||
public void setDate(String date) { | ||
this.date = date; | ||
} | ||
|
||
public String getTime() { | ||
return time; | ||
} | ||
|
||
public void setTime(String time) { | ||
this.time = time; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
<nav id="sidebar" class="text-white"> | ||
<!-- 로고 영역 --> | ||
<div class="sidebar-logo p-4"> | ||
<a href="/"> | ||
<a href="/static"> | ||
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. 이렇게 수정하신 이유가 궁금해요! |
||
<img src="https://avatars.githubusercontent.com/u/141792611?s=96&v=4" alt="logo" class="img-fluid rounded-circle"> | ||
</a> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,16 +4,37 @@ | |
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
|
||
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) | ||
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) | ||
public class MissionStepTest { | ||
|
||
@Test | ||
void 일단계() { | ||
RestAssured.given().log().all() | ||
.when().get("/") | ||
.then().log().all() | ||
.statusCode(200); | ||
} | ||
} | ||
|
||
|
||
//@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) | ||
//@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) | ||
Comment on lines
+23
to
+24
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. 여기도 주석 제거해주세요! |
||
|
||
|
||
@Test | ||
void 이단계() { | ||
RestAssured.given().log().all() | ||
.when().get("/reservation") | ||
.then().log().all() | ||
.statusCode(200); | ||
|
||
RestAssured.given().log().all() | ||
.when().get("/reservations") | ||
.then().log().all() | ||
.statusCode(200) | ||
.body("size()", is(3)); // 아직 생성 요청이 없으니 Controller에서 임의로 넣어준 Reservation 갯수 만큼 검증하거나 0개임을 확인하세요. | ||
} | ||
} |
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.
불필요한 주석은 제거해 주세요~