我正在使用 spring-data-rest。
给出以下存储库:
@RepositoryRestResource
public interface MyRepository extends PagingAndSortingRepository<MyEntity, Long> {}
注释@RestResource(exported = false)
on the save()
方法使框架返回一个405 Method Not Allowed
使用 POST、PUT 和 PATCH 方法时出错。
我的问题:当该存储库仍然允许 POST 和 PATCH 时,如何在 PUT 方法上返回 405 错误?
谢谢 !
@Swiggels
感谢您的答复 :)
你的解决方案对我不起作用... PUT 总是允许的。
对于其他人,我发现这个有效:
@BasePathAwareController
public class MyEntityController {
@RequestMapping(value = "/myentity/{id}", method = RequestMethod.PUT)
public ResponseEntity<?> preventsPut() {
return new ResponseEntity<>(HttpStatus.METHOD_NOT_ALLOWED);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)