他的回复:
在第三步修改契约里面,provider服务的sayHello方法中,@RequestParam改成 @VariableParam,会出现“Hello null”。需要改为“@QueryParam”,完整代码如下:package microservice.demo.training21days.provider.service; import java.util.Date; import javax.ws.rs.QueryParam; import org.apache.servicecomb.provider.rest.common.RestSchema; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @RestSchema(schemaId = "hello") // 该注解声明这是一个REST接口类,CSEJavaSDK会扫描到这个类,根据它的代码生成接口契约 @RequestMapping(path = "/provider/v0") // @RequestMapping是Spring的注解,这里在使用Spring MVC风格开发REST接口 public class HelloService { @RequestMapping(path = "/hello", method = RequestMethod.GET) public String sayHello(@QueryParam(value = "name") String name) { return "Hello," + name; } // } @PostMapping(path = "/greeting") public GreetingResponse greeting(@RequestBody Person person) { GreetingResponse greetingResponse = new GreetingResponse(); if (Gender.MALE.equals(person.getGender())) { greetingResponse.setMsg("Hello, Mr." + person.getName()); } else { greetingResponse.setMsg("Hello, Ms." + person.getName()); } greetingResponse.setTimestamp(new Date()); return greetingResponse; } }