我有一个像这样注释的 CRUD 的 RestController:
@RestController
@RequestMapping("/rest/v1/area")
public class AreaController
我的方法注释如下:
@RequestMapping(value = "/{uuid}", method = RequestMethod.PUT)
public ResponseEntity<Area> save(@Valid @RequestBody Area area) {
有没有办法使用方法的值来获得绝对路径?我想添加一个上传文件的方法,并且不想为此制作一个新的 Controller 。我想要一个像这样的方法:
@RequestMapping(value = "/rest/v1/area-upload", method = RequestMethod.PUT
public String handleFileUpload(@RequestParam("file") MultipartFile file, RedirectAttributes redirectAttributes) {
谢谢!
最佳答案
来自文档:(spring 2.5 api document of requestmapping)
Method-level mappings are only allowed to narrow the mapping expressed at the class level (if any)
因此您不能覆盖,只能将其缩小到子路径。
当然,如果您创建一个新的 Controller 类并将方法放在那里,您可以让它指向您喜欢的任何路径。
关于java - Spring @RequestMapping 绝对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38770256/