【问题标题】:Calling RESTful Webservice with @RequestParam and @RequestBody together using Angular使用 Angular 一起调用带有 @RequestParam 和 @RequestBody 的 RESTful Web 服务
【发布时间】:2020-05-02 02:55:38
【问题描述】:

如何编写 Angular 服务方法参数来调用在其签名中同时具有 @RequestBody 和 @RequestParam 的宁静 Web 服务 Spring MVC。

java代码:

@RequestMapping(value = "/getChargements", method = RequestMethod.POST)
    @ResponseBody
    public PlanificationEtSuiviChargementDto getChargements (@RequestBody CriteriaPlanificationDto criteriaPlanificationDto,
              @RequestParam boolean historique) {
        LOG.info("getChargements");
        return demandeChargementService.getChargementCalendrier(criteriaPlanificationDto.getParams(),
                criteriaPlanificationDto.getStep(), criteriaPlanificationDto.getPage(), historique);
    }

Angular 服务方法:

    public getPlanification(criteria: Criteria, step: number, page: number,historique: boolean): Observable<PlanificationData> {

        return this.http.post(this.config.getIp() + 'chargements/getChargements.html/',
            { 'params': criteria, 'step': step, 'page': page },historique,
            this.http.getJsonOptions()).pipe(map((rep: Response) => rep.json()));
    }

如果你能帮助我,我将不胜感激。 祝你有美好的一天!

【问题讨论】:

  • 您可以将该 requestparam 变量添加为 DTO 对象本身的一部分。所以在你的情况下 historique 应该是 criteriaPlanificationDto 的一部分

标签: angular spring spring-mvc angular-fullstack


【解决方案1】:
 @PutMapping("/{id}")
        public Customer updateCustomerInfo(@PathVariable Long id, 
                                           @RequestBody Customer requestCustomer) {

【讨论】:

  • 我不想使用@pathvariable。是否可以同时使用 RequestParam 和 RequestBody 调用 Web 服务?
  • 它们几乎相同。只需通过它的 indefier 获取一个变量。 baeldung.com/spring-request-param
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多