控制器 RequestMapping
@Controller
@RequestMapping("/appointments")
public class AppointmentsController {
//your handlers here, for example:
@RequestMapping(path = "/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";
}
}
使用 @Controller
註釋,你可以將 Java 類標記為包含多個 HTTP 處理程式的類,換句話說,是應用程式的 HTTP 訪問點。
@RequestMapping
註釋是用於在 @Controller 類中標記 HTTP 處理程式(應用程式的 HTTP 訪問點)的註釋