我在Spring Boot应用程序中使用Spring Data REST,我想将自定义路由重定向到生成的实体控制器。这是我的代码:
@RepositoryRestController
public class CustomUserController {
@RequestMapping(method = RequestMethod.PATCH, value = "/users/{id}/name/{newName}")
public ModelAndView enable(@PathVariable Long id,
@PathVariable String newName) {
User patchedUser = new User();
patchedUser.setName(newName);
// This is not working but I want to make a PATCH with my fragment of the user as the body
return new ModelAndView("/users/" + id, "message", patchedUser);
}
}
实际上,我只想为实体用户重写PATCH路由,但是对于一个特定字段。由于它由生成的控制器很好地处理,我以为我能够做一个简单的转发,但我无法找到正确的方法来做到这一点。
有什么想法吗?