我正在改进现有的API,并且要求提供一种可以接受多个搜索条件并根据这些条件执行查询的单一get方法.
I'm improving an existing API, and the requirement is to provide a single get method which can accept multiple search criteria and based on those criteria perform the query.
我正在使用Spring MVC. get方法签名:
I'm using Spring MVC. The get method signature:
@GetMapping("/subscribers") public ResponseEntity<List<SubscriberDTO>> getAllSubscribers(Pageable pageable, @RequestBody List<SearchCriteria> lstSearchCriteria)该实现按预期在邮递员上进行了测试
The implementation is working as expected tested on Postman
现在我要去Angular实现前端,但是我找不到通过HttpClient Get方法发送正文的方法...
Now I was going to Angular to implementing the front end and I can't find a way to send a body through HttpClient Get method...
我有点卡住了.我应该在标题上发送搜索条件吗?还是有更好的方法呢?
I'm kind of stuck. Should I send the search criteria over headers? Or there's a better way of doing it?
推荐答案据我所知,您不能使用HttpClient get发送正文.您至少可以使用该查询来使它成为惯用语言. (或者,您可以尝试以某种方式强行解决此问题).
As far as I can tell you cannot use HttpClient get to send a body. You could use the query at least for it to be idiomatic. (Or you can try to force the issue somehow).
让我们说您有一个符合条件的数组:
Lets say you have an array with your criteria:
const criteria = [ {a: 25}, {b: 23} ]; http.get(url + '/?criteria='+ encodeURIComponent( JSON.stringify(criteria)));在GET请求中发送正文违反了某些RFC标准,即使可行,您也必须召唤一些神秘的恶魔.
Sending a body in a GET request is a violation of some RFC standard, and even though it might work you're bound to summon some arcane demons.
更多推荐
带主体的Angular HttpClient Get方法
发布评论