如何从 Angular 的 API 响应中仅检索相似的对象?
我想要的是我有一个带有端点 api/v1/bank/search 的 POST API,这给了我保存在 MongoDB 中的所有银行。
这是我在java spring中的后端bankController代码
@PostMapping("/search")
@ResponseBody
public ResponseEntity<Wrapper<List<BankDTO>>> searchBanks(@RequestBody BankSearchDTO bankSearchDTO) {
log.info("Post Mapping Search Bank");
return ResponseEntity.ok(Wrapper.wrap(bankService.searchBanks(bankSearchDTO)));
}
这是spring中的BankService
// Returning all the existing banks
public List<BankDTO> searchBanks(BankSearchDTO bankSearchDTO) {
log.info("Searching Bank");
return bankRepository.findAll().stream().map(bankTranslator::toDTO).collect(Collectors.toList());
}
现在我想要的是我的前端是有角度的,当我以角度调用此 API 前端 service.ts 文件,事情是它会加载 UI 中的所有银行,因此将来 UI 上会有更多负载
public getSearchBank(
address : string,
city : string,
bankId: string,
bankName: string,
branch: string,
ifscCode: string,
passBookNo : string
){
const postData : Create = {
ifscCode: ifscCode,
address: '',
city : '',
bankId: '',
bankName: '',
branch: '',
passBookNo: ''
}
{
return this.http.post('http://localhost:9900/api/v1/bank/search',postData)
.subscribe((responseData)=>
{
console.log(responseData);
}
那么有没有就像我只能找到与我匹配的银行IFSCCode 或类似的东西有什么方法可以让我在调用此帖子 API 时过滤响应。
通过使用参数或其他东西,顺便说一句,我无法更改 API 端点。< /em>
The thing I want is that I have an POST API with end point api/v1/bank/search this gives me all the banks which are saved in my MongoDB.
This is my bankController code of backend its in java spring
@PostMapping("/search")
@ResponseBody
public ResponseEntity<Wrapper<List<BankDTO>>> searchBanks(@RequestBody BankSearchDTO bankSearchDTO) {
log.info("Post Mapping Search Bank");
return ResponseEntity.ok(Wrapper.wrap(bankService.searchBanks(bankSearchDTO)));
}
This is th BankService in spring
// Returning all the existing banks
public List<BankDTO> searchBanks(BankSearchDTO bankSearchDTO) {
log.info("Searching Bank");
return bankRepository.findAll().stream().map(bankTranslator::toDTO).collect(Collectors.toList());
}
Now the thing I want is that I have my front end in angular and when I am calling this API front service.ts file in angular the thing is that It loads all the banks in the UI due to which in future there will be more load on UI
public getSearchBank(
address : string,
city : string,
bankId: string,
bankName: string,
branch: string,
ifscCode: string,
passBookNo : string
){
const postData : Create = {
ifscCode: ifscCode,
address: '',
city : '',
bankId: '',
bankName: '',
branch: '',
passBookNo: ''
}
{
return this.http.post('http://localhost:9900/api/v1/bank/search',postData)
.subscribe((responseData)=>
{
console.log(responseData);
}
So Is there any way Like I can get only the bank which matches my IFSCCode or like is there any way I can filter the response while calling this post API.
By using parameters or something btw I cannot change the API endpoint .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要 rxjs 库及其管道运算符来过滤流。
You need rxjs library and their pipe operators to filter the stream.