我已经用 Java 为我的 Web 应用程序创建了一个简单的休息服务。据我了解,您可以从浏览器进行休息调用。在我的应用程序中,我希望用户从列表中选择一个选项,并根据他所选择的内容选择我希望应用程序显示某些信息。我将使用 JavaScirpt 进行 Get 调用并基于 Json 数据显示信息。如何阻止用户进行删除调用并从数据库中删除一些数据?我使用 Spring Boot 以及 JPA 和 Rest 存储库构建了服务器部分。
这是我的存储库的代码:
@RepositoryRestResource(collectionResourceRel =
"people", path = "people")
public interface PersonRepository extends
CrudRepository<Person, Long> {
List<Person> findByLastName(@Param("name")
String name);
}
此接口(interface)实现了 crudRepository,它具有删除对象的方法,我如何限制用户使用它?
最佳答案
好吧,我已经弄清楚了。为了隐藏 CrudRepository 接口(interface)中的一些不需要的方法,我让我的存储库扩展了 Repository 接口(interface)(它是 CrudRepository 的父级),并且我只从 Crud 中复制了我需要的那些方法:
public interface RestService extends Repository<Patient,Long>{
Optional<Patient> findById(Id Long);
boolean existsById(Id ong);
Iterable<Patient> findAll();
Iterable<Patient> findAllById(Iterable<Id> ids);
long count();
}
GET 后的任何其他调用都会抛出 405 方法不允许
关于javascript - 休息服务 骚扰电话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57086768/