From ff20b1069a38ba9d4c20d976ef33ee2232846e1b Mon Sep 17 00:00:00 2001 From: tanghc Date: Mon, 29 Apr 2019 19:58:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96ApiArgumentResolver?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/docs/files/10020_新增接口.md | 4 +--- .../gitee/sop/servercommon/param/ApiArgumentResolver.java | 5 ++--- .../com/gitee/sop/storyweb/controller/AlipayController.java | 4 ++-- .../gitee/sop/storyweb/controller/JSR303DemoController.java | 2 +- .../com/gitee/sop/storyweb/controller/param/GoodsParam.java | 6 +++--- 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/doc/docs/files/10020_新增接口.md b/doc/docs/files/10020_新增接口.md index 891b9c29..7f6c35cc 100644 --- a/doc/docs/files/10020_新增接口.md +++ b/doc/docs/files/10020_新增接口.md @@ -59,14 +59,12 @@ public class GoodsParam { ```java @ApiMapping(value = "goods.add") -public Object addGoods(GoodsParam param/* 业务参数必须放在第一位对应biz_content */, HttpServletRequest request) { +public Object addGoods(GoodsParam param, HttpServletRequest request) { System.out.println(request.getParameter("method")); return param; } ``` -**注意**:业务参数必须放在第一位 - ## 接口命名 接口命名没有做强制要求,但我们还是推荐按照下面的方式进行命名: diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/ApiArgumentResolver.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/ApiArgumentResolver.java index dbe4604c..b34e7cdc 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/ApiArgumentResolver.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/ApiArgumentResolver.java @@ -28,9 +28,8 @@ public class ApiArgumentResolver implements HandlerMethodArgumentResolver { } boolean hasAnnotation = methodParameter.getMethodAnnotation(ApiMapping.class) != null || methodParameter.getMethodAnnotation(ApiAbility.class) != null; - boolean isFirstParameter = methodParameter.getParameterIndex() == 0; - // 有注解,并且是第一个参数 - return hasAnnotation && isFirstParameter; + // 有注解 + return hasAnnotation; } @Override 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 fd145c50..20b63ffa 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 @@ -29,10 +29,10 @@ public class AlipayController { return story; } - @ApiOperation(value="获取故事信息", notes = "说明接口的详细信息,介绍,用途,注意事项等。") + @ApiOperation(value = "获取故事信息", notes = "说明接口的详细信息,介绍,用途,注意事项等。") @ApiMapping(value = "alipay.story.find") // 参数必须封装在类中 - public StoryVO getStory2(StoryParam story /* 业务参数必须放在第一位对应biz_content */, HttpServletRequest request) { + public StoryVO getStory2(StoryParam story, HttpServletRequest request) { StoryVO storyVO = new StoryVO(); storyVO.id = 1L; storyVO.name = "白雪公主"; diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/JSR303DemoController.java b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/JSR303DemoController.java index d033d601..7551cd7a 100644 --- a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/JSR303DemoController.java +++ b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/JSR303DemoController.java @@ -14,7 +14,7 @@ import javax.servlet.http.HttpServletRequest; public class JSR303DemoController { @ApiMapping(value = "goods.add") - public Object addGoods(GoodsParam param/* 业务参数必须放在第一位对应biz_content */, HttpServletRequest request) { + public Object addGoods(GoodsParam param, HttpServletRequest request) { System.out.println(request.getParameter("method")); return param; } diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/param/GoodsParam.java b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/param/GoodsParam.java index d283de2b..00eeebca 100644 --- a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/param/GoodsParam.java +++ b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/param/GoodsParam.java @@ -3,14 +3,14 @@ package com.gitee.sop.storyweb.controller.param; import lombok.Data; import org.hibernate.validator.constraints.Length; -import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotBlank; @Data public class GoodsParam { -// @NotEmpty(message = "商品名称不能为空") + @NotBlank(message = "商品名称不能为空") private String goods_name; - @NotEmpty(message = "{goods.remark.notNull}") + @NotBlank(message = "{goods.remark.notNull}") private String goods_remark; // 传参的格式:{xxx}=value1,value2...