json - 如何在不知道 json 中的 id 的情况下发送删除请求?
问题描述
例如,如果我使用了 findByEmail,我的 url 将类似于 http://localhost:8080/api/carts/search/findByEmail?email=helloworld@gmail.com
如果我在 JPA 存储库中有 deleteByEmail,删除请求的 URL 将如何显示
这就是我的 JPA 的样子
public interface CartRepository extends JpaRepository<Cart, Integer> {
@Transactional
@RestResource(exported = true)
List<Cart> deleteByEmail(String email);
}
解决方案
您可以拥有一个作为http://localhost:8080/api/carts/email/ {emailId} 的 REST API,并将 PathVariable HttpMethod 中的 emailId 作为 DELETE。在服务方法中,您通过 emailId 搜索,然后使用 ID 删除它。
推荐阅读
- reactjs - 如何区分useEffect是否被路由改变触发
- ruby-on-rails - Rails 6 - Yarn 字体包在生产中不起作用
- sql - 查询第二个查询计数等于 0 的记录
- javascript - 如果满足某些条件则重新加载页面的Javascript函数是无限地重新加载页面
- python - 图像已上传但未保存在媒体和数据库 Django 中
- java - 如何使用 ClassLoader 从另一个 jar 加载 bean XML 文件
- c# - 霍夫变换寻找直线
- python - Python:为机器学习格式化时间序列数据
- mfc - 控制台到 Windows 中的第二个显示
- flutter - Flutter中如何模糊DecorationImage的背景图?