/appointments로 이동하면 get() 액션이 호출되므로 뷰는 get.jsp가됩니다 (사용자가 .jsp를 사용하고 있다고 가정하고 매핑 액션 이름을보기로 변경)?스프링의 워드 프로세서에서 볼 수있는 코드
그리고 getnewform은 어떻습니까? 물건을 돌려 준 것 같니? 기본적으로보기로 전달됩니까?
@Controller @RequestMapping("/appointments") public class AppointmentsController {
private final AppointmentBook appointmentBook;
@Autowired
public AppointmentsController(AppointmentBook appointmentBook) {
this.appointmentBook = appointmentBook;
}
@RequestMapping(method = RequestMethod.GET)
public Map<String, Appointment> get() {
return appointmentBook.getAppointmentsForToday();
}
@RequestMapping(value="/{day}", method = RequestMethod.GET)
public Map<String, Appointment> getForDay(@PathVariable @DateTimeFormat(iso=ISO.DATE) Date day, Model model) {
return appointmentBook.getAppointmentsForDay(day);
}
@RequestMapping(value="/new", method = RequestMethod.GET)
public AppointmentForm getNewForm() {
return new AppointmentForm();
}
@RequestMapping(method = RequestMethod.POST)
public String add(@Valid AppointmentForm appointment, BindingResult result) {
if (result.hasErrors()) {
return "appointments/new";
}
appointmentBook.addAppointment(appointment);
return "redirect:/appointments";
} }
예에서 @RequestMapping은 여러 위치에서 사용됩니다. 첫 번째 용도는 유형 (클래스) 수준에 있으며이 컨트롤러의 모든 처리 방법은/약속 경로와 관련이 있음을 나타냅니다. get() 메소드는 @RequestMapping 상세 검색 기능을 제공합니다. 즉, GET 요청 만 허용합니다. 즉,/appointments에 대한 HTTP GET이이 메소드를 호출합니다. post()도 비슷한 세밀 함을 가지고 있으며 getNewForm()은 HTTP 메소드와 path의 정의를 하나로 결합하여 약속/신규에 대한 GET 요청이 해당 메소드에 의해 처리되도록합니다.
그래서 새로운 AppointmentForm()을 호출하면 뷰가 해석되고 AppointmentForm을 특성/모델로 전달합니다. – Blankman
@Blankman : Correct – skaffman