Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从角度传递时,spring boot无法识别路径变量数据_Javascript_Java_Angular_Spring_Typescript - Fatal编程技术网

Javascript 从角度传递时,spring boot无法识别路径变量数据

Javascript 从角度传递时,spring boot无法识别路径变量数据,javascript,java,angular,spring,typescript,Javascript,Java,Angular,Spring,Typescript,我使用了angular 7,我将angular服务等级的值传递为: executeHelloWorldBeanServiceWithPathVariable(name){ console.log("name coming from here"+name); return this.httpClient.get<HelloWorldBean>('http://localhost:8080/hello-world/path-variable/${name}');

我使用了angular 7,我将angular服务等级的值传递为:

executeHelloWorldBeanServiceWithPathVariable(name){
    console.log("name coming from here"+name);
    return this.httpClient.get<HelloWorldBean>('http://localhost:8080/hello-world/path-variable/${name}');
     console.log("hello world bean service executed");
   }
它在控制台中打印,因为这里没有问题

在我的弹簧靴中,我声明:

@GetMapping(path="/hello-world/path-variable/{name}")  
    public HelloWorldBean helloWorldBeanPathVariable(@PathVariable("name") String name) {
        System.out.print("name is"+name);
        return new HelloWorldBean(String.format("Hello world %s", name));
    }
当我尝试使用以下方法进行调试时,从angular传递的name参数未打印:

System.out.print("name is"+name);
但它是在el表达式中显示的

因此,在我的UI中,我得到:


您似乎没有在
executeHelloWorldBeanServiceWithPathVariable
方法上使用实际语法。我假设您试图使用它是因为
${}
表达式

这可能是请求未正确解析的原因。您应该使用反引号(`),而不是单引号或双引号

executeHelloWorldBeanServiceWithPathVariable(name){
  return this.httpClient.get<HelloWorldBean>(`http://localhost:8080/hello-world/path-variable/${name}`);
}

在处理typescript时,使用backticks`而不是使用'或'。
特别是当你计算一些值时,比如“我的字符串”+${myname}

@ashwinkarki很乐意帮忙!这不是问题的答案,更像是一个评论。
executeHelloWorldBeanServiceWithPathVariable(name){
  return this.httpClient.get<HelloWorldBean>(`http://localhost:8080/hello-world/path-variable/${name}`);
}
constructor(
  private yourService: YourService,
) { }

ngOnInit() {
  this.yourService.executeHelloWorldBeanServiceWithPathVariable('someName').subscribe(res => {
    console.log(res);
    // do the rest here
  })
}