在spring-data-rest中阻止HTTP方法 [英] Prevents HTTP method in spring-data-rest

查看:137
本文介绍了在spring-data-rest中阻止HTTP方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用spring-data-rest。

I'm using spring-data-rest.

给定以下存储库:

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

注释 @RestResource(exported = false) save()方法上的$ c>使框架在使用方法POST时返回 405 Method Not Allowed 错误, PUT和PATCH。

The annotation @RestResource(exported = false) on the save() method makes the framework return a 405 Method Not Allowed error when using methods POST, PUT and PATCH.

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

My question : How can I just return a 405 error on PUT method while POST and PATCH are still allowed for this repository ?

谢谢!

推荐答案

@SWiggels
感谢您的回复:)
您的解决方案对我不起作用。 .. PUT总是被允许。

@SWiggels Thanks for your response :) Your solution didn't work for me... PUT is always allowed.

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

For others I found this one that worked :

@BasePathAwareController
public class MyEntityController {

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

这篇关于在spring-data-rest中阻止HTTP方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆