gpt4 book ai didi

java - 防止 spring-data-rest 中的 HTTP 方法

转载 作者:搜寻专家 更新时间:2023-11-01 03:19:25 25 4
gpt4 key购买 nike

我正在使用 spring-data-rest。

给定以下存储库:

@RepositoryRestResource
public interface MyRepository extends PagingAndSortingRepository<MyEntity, Long> {}

save() 方法上的注释 @RestResource(exported = false) 使框架在以下情况下返回 405 Method Not Allowed 错误使用方法 POST、PUT 和 PATCH。

我的问题:我如何才能在 PUT 方法上返回 405 错误,而 POST 和 PATCH 仍然允许此存储库?

谢谢!

最佳答案

@SWiggels感谢您的答复 :)您的解决方案对我不起作用...始终允许 PUT。

对于其他人,我发现这个有效:

@BasePathAwareController
public class MyEntityController {

@RequestMapping(value = "/myentity/{id}", method = RequestMethod.PUT)
public ResponseEntity<?> preventsPut() {
return new ResponseEntity<>(HttpStatus.METHOD_NOT_ALLOWED);
}
}

关于java - 防止 spring-data-rest 中的 HTTP 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35154162/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com