栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

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

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

return appointmentBook.getAppointmentsForToday();

}

@RequestMapping(value="/{day}", method = RequestMethod.GET)

public Map 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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/583544.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号