org.springframework.web.bind.MissingPathVariableException: Missing URI template variable 'productCode' for method parameter of type String

今天在写项目的时候,遇到了一个错误:org.springframework.web.bind.MissingPathVariableException: Missing URI template variable 'productCode' for method parameter of type String

咋回事呢?其实也简单,主要是自己对注解的理解不清楚导致的。

错误写法:

 

 这是在网关写的,@pathvariable注解表示的是请求过来的地址必须包含这个参数,而自己使用测试软件进行测试的时候。

 

 正确的写发:使用@requestpara注解,表示的是前端调用网关的具体方法要传递的参数,不是请求路径拼接的。

 

 而网关在调用后面的服务类路径的时候是可以使用@pathvariable注解拼接参数的。

下面是服务端的逻辑处理路径,使用的是restful风格。

 

posted on 2020-03-20 18:12  ~码铃薯~  阅读(15945)  评论(2编辑  收藏  举报

导航