diff --git a/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/DemoConsumerController.java b/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/DubboConsumerController.java similarity index 59% rename from sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/DemoConsumerController.java rename to sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/DubboConsumerController.java index 016be701..e75eefff 100644 --- a/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/DemoConsumerController.java +++ b/sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/DubboConsumerController.java @@ -2,48 +2,38 @@ package com.gitee.sop.bookweb.controller; import com.alibaba.dubbo.config.annotation.Reference; import com.gitee.sop.servercommon.annotation.ApiMapping; +import com.gitee.sop.story.api.domain.Story; import com.gitee.sop.story.api.param.DemoParam; import com.gitee.sop.story.api.result.DemoResult; import com.gitee.sop.story.api.service.DemoService; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** * 调用dubbo服务,provider是story,见DefaultDemoService.java * dubbo配置方式参见:https://github.com/apache/dubbo-spring-boot-project/blob/0.2.x/README_CN.md - * + *
* 对比SpringCloud提供的Feign,dubbo会方便很多。 - * + *
* Feign的使用方式参见:com.gitee.sop.bookweb.controller.AlipayBookController#getBook2() */ @RestController -public class DemoConsumerController { +public class DubboConsumerController { @Reference(version = "${demo.service.version}", application = "${dubbo.application.id}", url = "dubbo://localhost:12345") private DemoService demoService; - // http://localhost:3333/sayHello?name=jim - @RequestMapping("/sayHello") - public String sayHello(@RequestParam String name) { - return demoService.sayHello(name); - } - - // http://localhost:3333/dubboStory - @RequestMapping("/dubboStory") - public DemoResult dubboStory() { - DemoParam demoParam = new DemoParam(); - demoParam.setId(1); - return demoService.getStory(demoParam); - } - // 作为开放接口 @ApiMapping(value = "dubbo.story.get") - public DemoResult openApi(DemoParam demoParam) { + public Story openApi(DemoParam demoParam) { // 通过dubbo调用story提供的服务 - return demoService.getStory(demoParam); + DemoResult dubboStory = demoService.getStory(demoParam); + Story story = new Story(); + story.setId(dubboStory.getId()); + story.setName(dubboStory.getName()); + return story; } + } \ No newline at end of file diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/service/DefaultDemoService.java b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/service/DefaultDemoService.java index 3d4dde31..e9596e8a 100644 --- a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/service/DefaultDemoService.java +++ b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/service/DefaultDemoService.java @@ -22,7 +22,7 @@ public class DefaultDemoService implements DemoService { @Override public DemoResult getStory(DemoParam param) { DemoResult demoResult = new DemoResult(); - demoResult.setId(2); + demoResult.setId(param.getId()); demoResult.setName("dubbo 白雪公主, param=" + param); return demoResult; } diff --git a/sop-website/website-front/pages/doc/doc.js b/sop-website/website-front/pages/doc/doc.js index 1b09e526..601689f0 100644 --- a/sop-website/website-front/pages/doc/doc.js +++ b/sop-website/website-front/pages/doc/doc.js @@ -152,8 +152,7 @@ layui.config({ ' "code": "10000",\n' + ' "msg": "Success",\n' + bizResult + - ' },\n' + - ' "sign": "xxxxxx"\n' + + ' }' + '}'; json = formatJson(json); $('#responseExampleJson').text(json); @@ -164,8 +163,7 @@ layui.config({ ' "msg": "Service is temporarily unavailable",\n' + ' "sub_code": "isp.unknow-error",\n' + ' "sub_msg": "服务暂不可用"\n' + - ' },\n' + - ' "sign": "xxxxxxx"\n' + + ' }' + '}'; errorJson = formatJson(errorJson); $('#responseErrorJson').text(errorJson);