Spring 的MVC @RequestMapping
来源:互联网 发布:json嵌套json数据 编辑:程序博客网 时间:2024/05/02 01:03
@RequestMapping
@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("/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";
}
}
/appointments/new.do
映射方法是getNewForm()
/appointments.do
GET请求映射方法是 get()
POST请求映射方法是add(@Valid AppointmentForm appointment, BindingResult result)
映射方法是getNewForm()
/appointments.do
GET请求映射方法是 get()
POST请求映射方法是add(@Valid AppointmentForm appointment, BindingResult result)
通过参数条件缩小路径映射
URL中只有存在myParam=myValue参数时才被允许访问路径映射的方法
@RequestMapping(value = "/path", params="myParam=myValue")public void add(){...}http://localhost:8080/DynamicWebProject/hao/hello.do?myParam=myValue
URL中只有存在myParam=myValue参数时才被允许访问路径映射的方法
@RequestMapping(value = "/path", method = RequestMethod.POST, headers="content-type=text/*")public void add(){...}只有在URL的头信息中包含有content-type=text/*(content-type=text/xml)的POST请求才能访问add()方法
- Spring 的MVC @RequestMapping
- Spring 的MVC @RequestMapping
- spring mvc中的@RequestMapping的用法
- spring mvc中的@RequestMapping的用法
- spring mvc中的@RequestMapping的用法
- Spring MVC (2) 注解RequestMapping的使用
- Spring MVC 中的 @RequestMapping 的使用方法
- Spring Mvc @RequestMapping 详解
- Spring MVC @RequestMapping
- Spring MVC @RequestMapping使用方法
- Spring MVC RequestMapping
- Spring MVC 中的RequestMapping
- Spring MVC @RequestMapping
- spring-mvc @RequestMapping
- Spring MVC--4.@RequestMapping
- Spring MVC @RequestMapping注解
- Spring mvc中@Requestmapping再探
- Spring MVC之@RequestMapping 详解
- matlab 基本幅度调制
- 估算那点事 .
- iOS 基于键盘的编程所需技巧
- spring scope="prototype" 和scope="singleton"区分
- 总结所学的命令
- Spring 的MVC @RequestMapping
- singleton(单例设计模式)
- 游戏软件功能测试用例编写
- 记下几个有用的函数
- linux常用命令-磁盘管理篇
- javascript typeof 运算符
- 组件映射和集合映射
- OpenXml 获取Excel文件指定工作簿中的表格部件和表格数量
- 单片机实验代码——可调时间的时钟程序