【问题标题】:pass parameter in the body spring boot and angular在车身弹簧靴和角度中传递参数
【发布时间】:2022-07-21 21:04:39
【问题描述】:

我正在使用 spring boot 和 angular,并在正文中作为 get 请求中的参数传递

 @GetMapping("/parAdresse")
    public List<Object> parAdresse(@RequestBody String adresse) {
        
          return dis.finddis(adresse) ; 
          
 }

我怎样才能在前面做同样的事情?

  pieChart(add: string) {

return  this.http.get("http://localhost:9095/distri/parAdresse");
   
  }

【问题讨论】:

  • 不认为 GET 请求可以与 @RequestBody 一起使用,您的意思是 @PathVariable
  • 我不希望参数显示在 url 中

标签: angular spring-boot


【解决方案1】:

GET方法不能有请求body,你可以将Java action转换成POST方法。

 @PostMapping("/parAdresse")

然后从 angular 传递 post 方法 body 中的信息。

return this.http.post("http://localhost:9095/distri/parAdresse", {
  adresse: add
});

【讨论】:

    【解决方案2】:

    后台

     @GetMapping("/parAdresse")
                public List<Object> parAdresse( @RequestParam String adresse) {
                    
                      return dis.finddis(adresse) ; 
                      
             }
    

    正面

    pieChart(add: string) {
        let queryParams = new HttpParams();
        queryParams = queryParams.append("adresse","TUNIS");
        return  this.http.get("http://localhost:9095/distri/parAdresse", {params:queryParams});
       
      }
    

    【讨论】:

      猜你喜欢
      • 2020-08-06
      • 2023-03-29
      • 2018-08-09
      • 2019-05-17
      • 1970-01-01
      • 1970-01-01
      • 2019-05-03
      • 1970-01-01
      • 2017-12-22
      相关资源
      最近更新 更多