java - java - 如何在spring boot java中编写一个函数来处理JPA存储库中的自定义查询?
问题描述
基本上我使用spring boot在服务器端托管一个数据库。我想从客户端编写自定义查询,该查询是用角度开发的,并从服务器端调用一个函数来给我所需的结果。
服务器端的功能将如下所示:
List<rows> func(String customQuery){
//fetch rows from table using this custom query and return those rows
//which I can use in client side.
}
Below are examples of customQuery which I need to send from client side:
select * from table;
select * from table where id>10;
select * from table where id>20 and id<30;
到目前为止,我在互联网上搜索我找不到任何解决方案。请帮忙。
解决方案
直接从客户端发送 SQL 将是一个完整的安全失败,因为恶意用户可以很容易地弄清楚它是如何工作的并发送一个delete from table
来杀死你的整个应用程序。更糟糕的是,他们甚至可以运行create user ...
以完全访问您的整个数据库、获取敏感信息、安装恶意软件等。
相反,您将希望使用以下方法在应用程序中创建 REST 服务
GET /table
GET /table?minId=10
GET /table?minId=20&maxId=30
以application/json
或类似的数据格式返回,仅返回您的 Angular 应用程序真正需要的信息。然后,Angular 将负责有选择地使用您的数据更新显示。
编辑:这是我找到的用于创建基于 Spring Boot 和 Angular 的基本 Web 应用程序的指南。对您来说可能是一个很好的起点: https ://www.baeldung.com/spring-boot-angular-web
推荐阅读
- python - 从 [-1; 转换图像;1] 到 [0; 255]
- r - 在 Shiny Dashboard 中同时加载所有页面
- c# - 如何从 C# .net 核心中的动态 json 对象读取数据
- python - 查询具有列表值的 pandas 数据框列
- python - 如何从文本文件中读取列表,该文件位于python中某些文本的下方?
- java - 如何在Java中解密字符串中的加密消息
- wpf - 如何捕获并优雅地处理 WPF 中数据库不可用的异常
- oracle - sql loader 不使用数据库密码
- javascript - JavaScript将单斜杠替换为双斜杠?
- java - 无法从 selenium 中的侦听器类捕获屏幕截图总是得到空指针异常