ModalAndView
1234567891011public class HelloWorldController {"/helloWorld")(public ModelAndView helloWorld() {ModelAndView mav = new ModelAndView();mav.setViewName("helloWorld");//viewName 视图名称mav.addObject("message", "Hello World!");// 往视图传递对象return mav;}}在Class级别这是
@RequestMapping
1234567891011121314151617181920212223242526272829303132333435@Controller@RequestMapping("/appointments")public class AppointmentsController {private final AppointmentBook appointmentBook;@Autowiredpublic 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";}}@PathVirable
123456789101112@RequestMapping(value="/owners/{ownerId}", method=RequestMethod.GET)public String findOwner(@PathVariable String ownerId, Model model) {Owner owner = ownerService.findOwner(ownerId);model.addAttribute("owner", owner);return "displayOwner";}@RequestMapping(value="/owners/{ownerId}", method=RequestMethod.GET)public String findOwner(@PathVariable("ownerId") String ownerId, Model model) {// implementation omitted}
待完善…