其他分享
首页 > 其他分享> > @RequestMapping详解,消息队列kafka面试

@RequestMapping详解,消息队列kafka面试

作者:互联网

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”;

}

}

value的uri值为以下三类:

A) 可以指定为普通的具体值;

B) 可以指定为含有某变量的一类值(URI Template Patterns with Path Variables);

C) 可以指定为含正则表达式的一类值( URI Template Patterns with Regular Expressions);

example B)

@RequestMapping(value="/owners/{ownerId}", method=RequestMethod.POST)

public String findOwner(@PathVariable String ownerId, Model model) {

Owner owner = ownerService.findOwner(ownerId);

model.addAttribute(“owner”, owner);

return “displayOwner”;

}

example C)

@RequestMapping("/spring-web/{symbolicName:[a-z-]+}-{version:\d.\d.\d}.{extension:.[a-z]}")

public void handle(@PathVariable String version, @PathVariable String extension) {

// …

}

}

2 consumes、produces 示例

cousumes的样例:

@Controller

@RequestMapping(value = “/pets”, method = RequestMethod.POST, consumes=“application/json”)

public void addPet(@RequestBody Pet pet, Model model) {

// implementation omitted

}

方法仅处理request Content-Type为“application/json”类型的请求。

produces的样例:

@Controller

@RequestMapping(value = “/pets/{petId}”, method = RequestMethod.GET, produces=“application/json”)

@ResponseBody

public Pet getPet(@PathVariable String petId, Model model) {

// implementation omitted

}

方法仅处理request请求中Accept头中包含了”application/json”

【一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义】

开源分享完整内容戳这里

的请求,同时暗示了返回的内容类型为application/json;

3 params、headers 示例

params的样例:

@Controller

@RequestMapping("/owners/{ownerId}")

public class RelativePathUriTemplateController {

@RequestMapping(value = “/pets/{petId}”, method = RequestMethod.GET, params=“myParam=myValue”)

public void findPet(@PathVariable String ownerId, @PathVariable String petId, Model model) {

// implementation omitted

}

}

仅处理请求中包含了名为“myParam”,值为“myValue”的请求;

headers的样例:

@Controller

@RequestMapping("/owners/{ownerId}")

public class RelativePathUriTemplateController {

@RequestMapping(value = “/pets”, method = RequestMethod.GET, headers=“Referer=http://www.ifeng.com/”)

public void findPet(@PathVariable String ownerId, @PathVariable String petId, Model model) {

// implementation omitted

标签:PathVariable,RequestMethod,kafka,String,详解,method,public,RequestMapping
来源: https://blog.csdn.net/m0_63102494/article/details/121419660