From b54fa733ab77be16c14d543390f1658cadac083e Mon Sep 17 00:00:00 2001 From: tanghc Date: Fri, 24 May 2019 18:10:14 +0800 Subject: [PATCH] =?UTF-8?q?demo=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../storyweb/controller/AlipayController.java | 78 ++++++++++++++++++- .../storyweb/controller/StoryController.java | 61 --------------- 2 files changed, 76 insertions(+), 63 deletions(-) diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java index 20b63ffa..b6d53ec6 100644 --- a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java +++ b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java @@ -1,5 +1,6 @@ package com.gitee.sop.storyweb.controller; +import com.gitee.sop.servercommon.annotation.ApiAbility; import com.gitee.sop.servercommon.annotation.ApiMapping; import com.gitee.sop.story.api.domain.Story; import com.gitee.sop.storyweb.controller.param.StoryParam; @@ -7,6 +8,8 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiOperation; import lombok.Data; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; @@ -14,13 +17,71 @@ import java.util.Date; /** * 支付宝服务端,假设签名验证通过后,到达这里进行具体的业务处理。 - * 这里演示如何接受业务参数。 * @author tanghc */ @RestController @Api(tags = "故事接口") public class AlipayController { + // http://localhost:2222/story_get + // 原生的接口,可正常调用 + @RequestMapping("story_get") + public Story getStory4() { + Story story = new Story(); + story.setId(1); + story.setName("海底小纵队(原生)"); + return story; + } + + // http://localhost:2222/story.get/ + // 接口名,使用默认版本号 + @ApiMapping(value = "story.get") + public Story storyget() { + Story story = new Story(); + story.setId(1); + story.setName("海底小纵队(默认版本号)"); + return story; + } + + // http://localhost:2222/story.get/?version=1.1 + // 接口名 + 版本号 + @ApiMapping(value = "story.get", version = "1.1") + public Story getStory2() { + Story story = new Story(); + story.setId(1); + story.setName("海底小纵队1.0"); + return story; + } + + // http://localhost:2222/story.get/?name=111&version=2.0 + // 接口名 + 版本号 + @ApiMapping(value = "story.get", version = "2.0") + public Story getStory20(Story story) { + return story; + } + + // http://localhost:2222/getStory2 + // 遗留接口具备开放平台能力 + @ApiAbility + @GetMapping("getStory2") + public Story getStory2_0() { + Story story = new Story(); + story.setId(1); + story.setName("海底小纵队(默认版本号)"); + return story; + } + + // http://localhost:2222/getStory2?version=2.1 + // 遗留接口具备开放平台能力,在原来的基础上加版本号 + @ApiAbility(version = "2.1") + @RequestMapping("getStory2") + public Story getStory2_1() { + Story story = new Story(); + story.setId(1); + story.setName("海底小纵队2.1"); + return story; + } + @ApiMapping(value = "alipay.story.get") public Story getStory() { Story story = new Story(); @@ -29,10 +90,18 @@ public class AlipayController { return story; } + /** + * 参数绑定 + * @param story 对应biz_content中的内容,并自动JSR-303校验 + * @param request + * @return + */ @ApiOperation(value = "获取故事信息", notes = "说明接口的详细信息,介绍,用途,注意事项等。") @ApiMapping(value = "alipay.story.find") - // 参数必须封装在类中 public StoryVO getStory2(StoryParam story, HttpServletRequest request) { + System.out.println(story); + // 获取其它参数 + System.out.println(request.getParameter("app_id")); StoryVO storyVO = new StoryVO(); storyVO.id = 1L; storyVO.name = "白雪公主"; @@ -40,6 +109,11 @@ public class AlipayController { return storyVO; } + /** + * + * @param story 对应biz_content中的内容,并自动JSR-303校验 + * @return + */ @ApiMapping(value = "alipay.story.get", version = "1.2") public Story getStory11(Story story) { return story; diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/StoryController.java b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/StoryController.java index 11a7baf5..f43df8f6 100644 --- a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/StoryController.java +++ b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/StoryController.java @@ -1,12 +1,10 @@ package com.gitee.sop.storyweb.controller; import com.gitee.sop.servercommon.annotation.ApiAbility; -import com.gitee.sop.servercommon.annotation.ApiMapping; import com.gitee.sop.story.api.domain.Story; import com.gitee.sop.story.api.service.StoryService; import lombok.Data; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** @@ -24,65 +22,6 @@ public class StoryController implements StoryService { return story; } - // http://localhost:2222/story/story_get - // 原生的接口,可正常调用 - @RequestMapping("story_get") - public Story getStory4() { - Story story = new Story(); - story.setId(1); - story.setName("海底小纵队(原生)"); - return story; - } - - // http://localhost:2222/story/story.get/ - // 接口名,使用默认版本号 - @ApiMapping(value = "story.get") - public Story storyget() { - Story story = new Story(); - story.setId(1); - story.setName("海底小纵队(默认版本号)"); - return story; - } - - // http://localhost:2222/story/story.get/?version=1.1 - // 接口名 + 版本号 - @ApiMapping(value = "story.get", version = "1.1") - public Story getStory2() { - Story story = new Story(); - story.setId(1); - story.setName("海底小纵队1.0"); - return story; - } - - // http://localhost:2222/story/story.get/?version=2.0 - // 接口名 + 版本号 - @ApiMapping(value = "story.get", version = "2.0") - public Story getStory20(Story story) { - return story; - } - - // http://localhost:2222/story/getStory2 - // 遗留接口具备开放平台能力 - @ApiAbility - @GetMapping("getStory2") - public Story getStory2_0() { - Story story = new Story(); - story.setId(1); - story.setName("海底小纵队(默认版本号)"); - return story; - } - - // http://localhost:2222/story/getStory2?version=2.1 - // 在原来的基础上加版本号 - @ApiAbility(version = "2.1") - @RequestMapping("getStory2") - public Story getStory2_1() { - Story story = new Story(); - story.setId(1); - story.setName("海底小纵队2.1"); - return story; - } - // 测试参数绑定 @ApiAbility @GetMapping("getStory3")