mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
4.0
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
<version>0.3.3</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- sop接入依赖 end -->
|
||||
|
||||
<!-- Spring -->
|
||||
|
@@ -8,7 +8,7 @@ import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.client.naming.utils.NetUtils;
|
||||
import com.alibaba.nacos.spring.context.annotation.discovery.EnableNacosDiscovery;
|
||||
import com.gitee.sop.servercommon.bean.ServiceConfig;
|
||||
import com.gitee.sop.servercommon.configuration.SpringMvcServiceConfiguration;
|
||||
import com.gitee.sop.servercommon.configuration.ServiceConfiguration;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
@@ -18,7 +18,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
*/
|
||||
@Slf4j
|
||||
@EnableNacosDiscovery(globalProperties = @NacosProperties(serverAddr = "127.0.0.1:8848"))
|
||||
public class OpenServiceConfig extends SpringMvcServiceConfiguration {
|
||||
public class OpenServiceConfig extends ServiceConfiguration {
|
||||
|
||||
|
||||
public static final String SPRING_APPLICATION_NAME = "spring.application.name";
|
||||
@@ -31,9 +31,9 @@ public class OpenServiceConfig extends SpringMvcServiceConfiguration {
|
||||
}
|
||||
|
||||
/** 对应tomcat中的contextPath */
|
||||
private String contextPath = "/sop-springmvc";
|
||||
private String serviceId = "sop-springmvc";
|
||||
private int port = 2223;
|
||||
private final String contextPath = "/sop-springmvc";
|
||||
private final String serviceId = "sop-springmvc";
|
||||
private final int port = 2223;
|
||||
|
||||
@NacosInjected
|
||||
private NamingService namingService;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package com.gitee.app.controller;
|
||||
|
||||
import com.gitee.app.model.Goods;
|
||||
import com.gitee.sop.servercommon.annotation.ApiMapping;
|
||||
import com.gitee.sop.servercommon.annotation.Open;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.slf4j.Logger;
|
||||
@@ -45,7 +45,8 @@ public class HomeController {
|
||||
|
||||
|
||||
@ApiOperation(value="获取商品", notes = "获取商品说明")
|
||||
@ApiMapping(value = "springmvc.goods.get")
|
||||
@Open("springmvc.goods.get")
|
||||
@RequestMapping("/goods/get")
|
||||
@ResponseBody
|
||||
public Goods getGoods(Goods param) {
|
||||
Goods goods = new Goods();
|
||||
|
@@ -32,7 +32,12 @@
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<!-- 注册中心end -->
|
||||
|
||||
<!-- 使用eureka注册中心 -->
|
||||
<!--<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
|
||||
</dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
|
@@ -4,10 +4,11 @@ import com.gitee.sop.servercommon.bean.ServiceConfig;
|
||||
import com.gitee.sop.servercommon.configuration.AlipayServiceConfiguration;
|
||||
import com.gitee.sop.servercommon.swagger.SwaggerSupport;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
/**
|
||||
* 使用支付宝开放平台功能
|
||||
* 开放平台功能
|
||||
* @author tanghc
|
||||
*/
|
||||
@Configuration
|
||||
@@ -38,11 +39,3 @@ public class OpenServiceConfig extends AlipayServiceConfiguration {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用淘宝开放平台功能
|
||||
* @author tanghc
|
||||
*/
|
||||
//@Configuration
|
||||
//public class OpenServiceConfig extends TaobaoServiceConfiguration {
|
||||
//
|
||||
//}
|
||||
|
@@ -1,297 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.gitee.sop.servercommon.annotation.ApiAbility;
|
||||
import com.gitee.sop.servercommon.annotation.ApiMapping;
|
||||
import com.gitee.sop.servercommon.bean.OpenContext;
|
||||
import com.gitee.sop.servercommon.bean.ServiceContext;
|
||||
import com.gitee.sop.storyweb.controller.param.CategoryParam;
|
||||
import com.gitee.sop.storyweb.controller.param.StoryParam;
|
||||
import com.gitee.sop.storyweb.controller.result.CategoryResult;
|
||||
import com.gitee.sop.storyweb.controller.result.StoryResult;
|
||||
import com.gitee.sop.storyweb.controller.result.TreeResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
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;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 支付宝服务端,假设签名验证通过后,到达这里进行具体的业务处理。
|
||||
*
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
@Slf4j
|
||||
@Api(tags = "故事接口")
|
||||
public class AlipayController {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
// http://localhost:2222/story_get
|
||||
// 原生的接口,可正常调用
|
||||
@RequestMapping("story_get")
|
||||
public StoryResult story_get() {
|
||||
StoryResult result = new StoryResult();
|
||||
result.setId(1L);
|
||||
result.setName("海底小纵队(原生)");
|
||||
return result;
|
||||
}
|
||||
|
||||
// http://localhost:2222/story.get/1.0/
|
||||
// 接口名,使用默认版本号
|
||||
@ApiMapping(value = "story.get")
|
||||
public StoryResult storyget() {
|
||||
// 获取开放平台参数
|
||||
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
|
||||
String appId = openContext.getAppId();
|
||||
StoryResult result = new StoryResult();
|
||||
result.setId(1L);
|
||||
result.setName("海底小纵队(默认版本号), app_id:" + appId);
|
||||
return result;
|
||||
}
|
||||
|
||||
// http://localhost:2222/story.get/1.1/
|
||||
// 接口名 + 版本号
|
||||
@ApiMapping(value = "story.get", version = "1.1")
|
||||
public StoryResult getStory2() {
|
||||
StoryResult result = new StoryResult();
|
||||
result.setId(1L);
|
||||
result.setName("海底小纵队1.0");
|
||||
return result;
|
||||
}
|
||||
|
||||
// http://localhost:2222/story.get/2.0/?name=111
|
||||
// 接口名 + 版本号
|
||||
// StoryParam对应biz_content内容
|
||||
@ApiMapping(value = "story.get", version = "2.0")
|
||||
public StoryResult getStory20(StoryParam param) {
|
||||
StoryResult result = new StoryResult();
|
||||
BeanUtils.copyProperties(param, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 忽略验证
|
||||
@ApiMapping(value = "story.get", version = "2.1", ignoreValidate = true)
|
||||
public StoryResult getStory21(StoryParam story) {
|
||||
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
|
||||
// 此处的param和story参数是一样的
|
||||
StoryParam param = openContext.getBizObject(StoryParam.class);
|
||||
boolean isSame = story == param;
|
||||
StoryResult result = new StoryResult();
|
||||
result.setName(story.getName() + ", story.get2.1, ignoreValidate = true, story==param:" + isSame);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 另一种方式,OpenContext泛型参数填bizObject类<br>
|
||||
* 调用openContext.getBizObject()可直接获得对象<br>
|
||||
* 此方式等价于:
|
||||
* <pre>
|
||||
* public Story getStory22(Story bizObject) {
|
||||
* OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
|
||||
* // 获取appid,更多方法查看OpenContext类
|
||||
* String appId = openContext.getAppId();
|
||||
* System.out.println(appId);
|
||||
* return bizObject;
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @param openContext
|
||||
* @return
|
||||
*/
|
||||
@ApiMapping(value = "story.get", version = "2.2")
|
||||
public StoryResult getStory22(OpenContext<StoryParam> openContext) {
|
||||
StoryParam bizObject = openContext.getBizObject();
|
||||
// 获取appid,更多方法查看OpenContext类
|
||||
String appId = openContext.getAppId();
|
||||
StoryResult result = new StoryResult();
|
||||
result.setName("appId:" + appId + ", " + bizObject.getName());
|
||||
return result;
|
||||
}
|
||||
|
||||
@ApiMapping(value = "story.get", version = "2.3")
|
||||
public StoryResult getStory23(StoryParam param, HttpServletRequest request) {
|
||||
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
|
||||
String appId = openContext.getAppId();
|
||||
System.out.println(appId);
|
||||
StoryResult story = new StoryResult();
|
||||
story.setName("appId:" + appId + ", " + param.getName() + ",ip:" + request.getLocalAddr());
|
||||
return story;
|
||||
}
|
||||
|
||||
// http://localhost:2222/getStory2
|
||||
// 遗留接口具备开放平台能力
|
||||
@ApiAbility
|
||||
@GetMapping("getStory2")
|
||||
public StoryResult getStory2_0(@RequestBody JSONObject param) {
|
||||
StoryResult story = new StoryResult();
|
||||
story.setId(1L);
|
||||
story.setName("海底小纵队(默认版本号),param:" + param);
|
||||
return story;
|
||||
}
|
||||
|
||||
// http://localhost:2222/getStory33
|
||||
// 遗留接口具备开放平台能力
|
||||
@ApiAbility
|
||||
@PostMapping("getStory33")
|
||||
public StoryResult getStory22(@RequestBody StoryParam param) {
|
||||
StoryResult story = new StoryResult();
|
||||
story.setId(1L);
|
||||
story.setName("遗留接口,param:" + param);
|
||||
return story;
|
||||
}
|
||||
|
||||
// http://localhost:2222/getStory2?version=2.1
|
||||
// 遗留接口具备开放平台能力,在原来的基础上加版本号
|
||||
@ApiAbility(version = "2.1")
|
||||
@GetMapping("getStory2")
|
||||
public StoryResult getStory2_1() {
|
||||
StoryResult story = new StoryResult();
|
||||
story.setId(1L);
|
||||
story.setName("海底小纵队2.1");
|
||||
return story;
|
||||
}
|
||||
|
||||
@ApiAbility(ignoreValidate = true)
|
||||
@GetMapping("/empinfo/get")
|
||||
@ApiOperation(value="遗留接口", notes = "遗留接口")
|
||||
public StoryResult getEmpInfo() {
|
||||
StoryResult story = new StoryResult();
|
||||
story.setId(1L);
|
||||
story.setName("遗留接口");
|
||||
return story;
|
||||
}
|
||||
|
||||
// http://localhost:2222/alipay.story.get/1.0/?name=Jim
|
||||
@ApiOperation(value="获取故事信息", notes = "获取故事信息的详细信息")
|
||||
@ApiMapping(value = "alipay.story.get")
|
||||
public StoryResult getStory(StoryParam param) {
|
||||
StoryResult story = new StoryResult();
|
||||
story.setId(1L);
|
||||
story.setName("海底小纵队(alipay.story.get1.0), port:" + environment.getProperty("server.port") + ", param:" + param);
|
||||
return story;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param param 对应biz_content中的内容,并自动JSR-303校验
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value="获取故事信息", notes = "获取故事信息的详细信息")
|
||||
@ApiMapping(value = "alipay.story.get", version = "1.2")
|
||||
public StoryResult getStory11(StoryParam param) {
|
||||
StoryResult story2 = new StoryResult();
|
||||
story2.setId(1L);
|
||||
story2.setName("海底小纵队(alipay.story.get1.2), param:" + param);
|
||||
return story2;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证字符串乱码问题
|
||||
*
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
@ApiMapping(value = "story.string.get", version = "1.0")
|
||||
public String string(StoryParam param) {
|
||||
StoryResult story2 = new StoryResult();
|
||||
story2.setId(1L);
|
||||
story2.setName("海底小纵队");
|
||||
return JSON.toJSONString(story2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数绑定
|
||||
*
|
||||
* @param story 对应biz_content中的内容,并自动JSR-303校验
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "获取故事信息", notes = "说明接口的详细信息,介绍,用途,注意事项等。")
|
||||
@ApiMapping(value = "alipay.story.find")
|
||||
public StoryResult getStory2(StoryParam story) {
|
||||
log.info("获取故事信息参数, story: {}", story);
|
||||
// 获取其它参数
|
||||
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
|
||||
String app_id = openContext.getAppId();
|
||||
StoryResult result = new StoryResult();
|
||||
result.setName("白雪公主, app_id:" + app_id);
|
||||
result.setGmt_create(new Date());
|
||||
return result;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "返回数组结果", notes = "返回数组结果")
|
||||
@ApiMapping(value = "alipay.story.find2")
|
||||
public List<StoryResult> getStory3(StoryParam story) {
|
||||
int index = 0;
|
||||
StoryResult storyVO = new StoryResult();
|
||||
storyVO.setId(1L);
|
||||
storyVO.setName("白雪公主, index:" + index++);
|
||||
storyVO.setGmt_create(new Date());
|
||||
|
||||
StoryResult storyVO2 = new StoryResult();
|
||||
storyVO2.setId(1L);
|
||||
storyVO2.setName("白雪公主, index:" + index++);
|
||||
storyVO2.setGmt_create(new Date());
|
||||
|
||||
return Arrays.asList(storyVO, storyVO2);
|
||||
}
|
||||
|
||||
@ApiAbility
|
||||
@RequestMapping("getJson")
|
||||
public Object getJson(@RequestBody JSONObject param) {
|
||||
return param;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 演示文档表格树
|
||||
*
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "获取分类信息", notes = "演示表格树")
|
||||
@ApiMapping(value = "alipay.category.get", method = RequestMethod.POST)
|
||||
public CategoryResult getCategory(CategoryParam param) {
|
||||
System.out.println(param);
|
||||
StoryResult result = new StoryResult();
|
||||
result.setId(1L);
|
||||
result.setName("白雪公主");
|
||||
result.setGmt_create(new Date());
|
||||
CategoryResult categoryResult = new CategoryResult();
|
||||
categoryResult.setCategoryName("娱乐");
|
||||
categoryResult.setStoryResult(result);
|
||||
return categoryResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 树状返回
|
||||
*
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "树状返回", notes = "树状返回")
|
||||
@ApiMapping(value = "alipay.tree.get", method = RequestMethod.POST)
|
||||
public TreeResult tree(StoryParam param) {
|
||||
return new TreeResult();
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class P {
|
||||
private String name;
|
||||
}
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
import com.gitee.sop.servercommon.annotation.ApiAbility;
|
||||
import com.gitee.sop.storyweb.controller.param.StoryParam;
|
||||
import com.gitee.sop.storyweb.controller.result.StoryResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 支付宝服务端,假设签名验证通过后,到达这里进行具体的业务处理。
|
||||
*
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
@Slf4j
|
||||
// 注解放在这里,表示类中的方法都具备接口开放能力
|
||||
@ApiAbility
|
||||
public class AlipayController2 {
|
||||
|
||||
// http://localhost:2222/getStory44
|
||||
// 遗留接口具备开放平台能力
|
||||
@PostMapping("/getStory44")
|
||||
public StoryResult getStory22(@RequestBody StoryParam param) {
|
||||
StoryResult story = new StoryResult();
|
||||
story.setId(1L);
|
||||
story.setName("遗留接口44,param:" + param);
|
||||
return story;
|
||||
}
|
||||
}
|
@@ -1,74 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.gitee.sop.servercommon.annotation.ApiMapping;
|
||||
import com.gitee.sop.servercommon.util.UploadUtil;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
public class DemoOrderController {
|
||||
|
||||
@Value("${server.port}")
|
||||
private String port;
|
||||
|
||||
@ApiMapping("member.info.get")
|
||||
public Object member(MemberInfoGetParam param, HttpServletRequest request) {
|
||||
if ("tom".equals(param.name)) {
|
||||
throw new IllegalArgumentException("name参数错误");
|
||||
}
|
||||
Collection<MultipartFile> uploadFiles = UploadUtil.getUploadFiles(request);
|
||||
for (MultipartFile uploadFile : uploadFiles) {
|
||||
try {
|
||||
System.out.println("文件名称:" + uploadFile.getOriginalFilename()
|
||||
+ " 表单名称:" + uploadFile.getName()
|
||||
+ " 文件内容:" +
|
||||
IOUtils.toString(uploadFile.getInputStream(), StandardCharsets.UTF_8));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.out.println(param);
|
||||
return JSON.parseObject("{\n" +
|
||||
" \"id\": 123,\n" +
|
||||
" \"name\": \"jim\",\n" +
|
||||
" \"member_info\": {\n" +
|
||||
" \"is_vip\": 1,\n" +
|
||||
" \"vip_endtime\": \"2020-11-11 11:11:11\"\n" +
|
||||
" }\n" +
|
||||
"}", MemberInfoGetResult.class);
|
||||
}
|
||||
|
||||
|
||||
@Data
|
||||
public static class MemberInfoGetParam {
|
||||
private String name;
|
||||
private Integer age;
|
||||
private String address;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class MemberInfoGetResult {
|
||||
private Integer id;
|
||||
private String name;
|
||||
private MemberInfoGetResultMemberInfo member_info;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class MemberInfoGetResultMemberInfo {
|
||||
private Byte is_vip;
|
||||
private String vip_endtime;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,133 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
import com.gitee.sop.servercommon.annotation.Open;
|
||||
import com.gitee.sop.storyweb.controller.param.CategoryParam;
|
||||
import com.gitee.sop.storyweb.controller.param.StoryParam;
|
||||
import com.gitee.sop.storyweb.controller.result.CategoryResult;
|
||||
import com.gitee.sop.storyweb.controller.result.StoryResult;
|
||||
import com.gitee.sop.storyweb.controller.result.TreeResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 签名验证通过后,到达这里进行具体的业务处理。
|
||||
*
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("story")
|
||||
@Slf4j
|
||||
@Api(tags = "故事接口")
|
||||
public class Example1001_BaseController {
|
||||
|
||||
// http://localhost:2222/stroy/get
|
||||
// 原生的接口,可正常调用
|
||||
@RequestMapping("/get")
|
||||
public StoryResult get() {
|
||||
StoryResult result = new StoryResult();
|
||||
result.setId(1L);
|
||||
result.setName("海底小纵队(原生)");
|
||||
return result;
|
||||
}
|
||||
|
||||
// 基础用法
|
||||
@ApiOperation(value = "获取故事信息", notes = "获取故事信息的详细信息")
|
||||
@Open("story.get")
|
||||
@RequestMapping("/get/v1")
|
||||
public StoryResult get_v1(StoryParam param) {
|
||||
StoryResult story = new StoryResult();
|
||||
story.setId(1L);
|
||||
story.setName("海底小纵队(story.get1.0), " + "param:" + param);
|
||||
return story;
|
||||
}
|
||||
|
||||
// 指定版本号
|
||||
@ApiOperation(value = "获取故事信息", notes = "获取故事信息的详细信息")
|
||||
@Open(value = "story.get", version = "2.0")
|
||||
@RequestMapping("/get/v2")
|
||||
public StoryResult get_v2(StoryParam param) {
|
||||
StoryResult story = new StoryResult();
|
||||
story.setId(1L);
|
||||
story.setName("海底小纵队(story.get2.0), " + "param:" + param);
|
||||
return story;
|
||||
}
|
||||
|
||||
// 忽略验证
|
||||
@Open(value = "story.get.ignore", ignoreValidate = true)
|
||||
@RequestMapping("/get/ignore/v1")
|
||||
public StoryResult getStory21(StoryParam story) {
|
||||
StoryResult result = new StoryResult();
|
||||
result.setName(story.getName() + ", ignoreValidate = true");
|
||||
return result;
|
||||
}
|
||||
|
||||
// 返回数组结果
|
||||
@ApiOperation(value = "返回数组结果", notes = "返回数组结果")
|
||||
@Open("story.list")
|
||||
@RequestMapping("/list/v1")
|
||||
public List<StoryResult> getStory3(StoryParam story) {
|
||||
int index = 0;
|
||||
StoryResult storyVO = new StoryResult();
|
||||
storyVO.setId(1L);
|
||||
storyVO.setName("白雪公主, index:" + index++);
|
||||
storyVO.setGmt_create(new Date());
|
||||
|
||||
StoryResult storyVO2 = new StoryResult();
|
||||
storyVO2.setId(1L);
|
||||
storyVO2.setName("白雪公主, index:" + index++);
|
||||
storyVO2.setGmt_create(new Date());
|
||||
|
||||
return Arrays.asList(storyVO, storyVO2);
|
||||
}
|
||||
|
||||
// 演示文档表格树
|
||||
@ApiOperation(value = "获取分类信息", notes = "演示表格树")
|
||||
@Open("category.get")
|
||||
@PostMapping("/category/get/v1")
|
||||
public CategoryResult getCategory(CategoryParam param) {
|
||||
System.out.println(param);
|
||||
StoryResult result = new StoryResult();
|
||||
result.setId(1L);
|
||||
result.setName("白雪公主");
|
||||
result.setGmt_create(new Date());
|
||||
CategoryResult categoryResult = new CategoryResult();
|
||||
categoryResult.setCategoryName("娱乐");
|
||||
categoryResult.setStoryResult(result);
|
||||
return categoryResult;
|
||||
}
|
||||
|
||||
// 演示文档页树状返回
|
||||
@ApiOperation(value = "树状返回", notes = "树状返回")
|
||||
@Open("story.tree.get")
|
||||
@PostMapping("/tree/v1")
|
||||
public TreeResult tree(StoryParam param) {
|
||||
int id = 0;
|
||||
TreeResult parent = new TreeResult();
|
||||
parent.setId(++id);
|
||||
parent.setName("父节点");
|
||||
parent.setPid(0);
|
||||
|
||||
TreeResult child1 = new TreeResult();
|
||||
child1.setId(++id);
|
||||
child1.setName("子节点1");
|
||||
child1.setPid(1);
|
||||
|
||||
TreeResult child2 = new TreeResult();
|
||||
child2.setId(++id);
|
||||
child2.setName("子节点2");
|
||||
child2.setPid(1);
|
||||
|
||||
parent.setChildren(Arrays.asList(child1, child2));
|
||||
|
||||
return parent;
|
||||
}
|
||||
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
import com.gitee.sop.servercommon.annotation.ApiMapping;
|
||||
import com.gitee.sop.servercommon.annotation.Open;
|
||||
import com.gitee.sop.servercommon.util.UploadUtil;
|
||||
import com.gitee.sop.storyweb.controller.param.FileUploadParam;
|
||||
import com.gitee.sop.storyweb.controller.param.FileUploadParam2;
|
||||
@@ -10,12 +10,14 @@ import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.Extension;
|
||||
import io.swagger.annotations.ExtensionProperty;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -25,8 +27,9 @@ import java.util.Optional;
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("upload")
|
||||
@Api(tags = "文件上传", position = 2)
|
||||
public class FileUploadDemoController {
|
||||
public class Example1002_FileUploadController {
|
||||
|
||||
/**
|
||||
* 方式1:将文件写在参数中,可直接获取。好处是可以校验是否上传
|
||||
@@ -34,7 +37,8 @@ public class FileUploadDemoController {
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "文件上传例1", notes = "上传文件demo")
|
||||
@ApiMapping(value = "demo.file.upload")
|
||||
@Open("file.upload")
|
||||
@RequestMapping("file1")
|
||||
public FileUploadResult file1(FileUploadParam param) {
|
||||
// 获取上传的文件
|
||||
MultipartFile file1 = param.getFile1();
|
||||
@@ -59,7 +63,8 @@ public class FileUploadDemoController {
|
||||
@ApiOperation(value = "文件上传例2", notes = "可上传多个文件"
|
||||
// 多文件上传、不确定文件数量上传,必须申明下面这句,否则沙盒界面不会出现上传控件
|
||||
, extensions = @Extension(properties = @ExtensionProperty(name = "multiple", value = "multiple")))
|
||||
@ApiMapping(value = "demo.file.upload2")
|
||||
@Open("file.upload2")
|
||||
@RequestMapping("file2")
|
||||
public FileUploadResult file2(FileUploadParam2 param, HttpServletRequest request) {
|
||||
System.out.println(param.getRemark());
|
||||
FileUploadResult result = new FileUploadResult();
|
||||
@@ -72,7 +77,8 @@ public class FileUploadDemoController {
|
||||
return result;
|
||||
}
|
||||
|
||||
@ApiMapping(value = "demo.file.upload3")
|
||||
@Open("file.upload3")
|
||||
@RequestMapping("file3")
|
||||
public FileUploadResult file3(FileUploadParam2 param, HttpServletRequest request) {
|
||||
System.out.println(param.getRemark());
|
||||
FileUploadResult result = new FileUploadResult();
|
||||
@@ -99,7 +105,7 @@ public class FileUploadDemoController {
|
||||
// 文件内容
|
||||
String fileContent = null;
|
||||
try {
|
||||
fileContent = IOUtils.toString(multipartFile.getInputStream(), "UTF-8");
|
||||
fileContent = IOUtils.toString(multipartFile.getInputStream(), StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
import com.gitee.sop.servercommon.annotation.ApiMapping;
|
||||
import com.gitee.sop.servercommon.annotation.Open;
|
||||
import com.gitee.sop.storyweb.controller.param.StoryParam;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -10,6 +10,7 @@ import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -20,10 +21,12 @@ import java.io.IOException;
|
||||
*/
|
||||
@Api(tags = "文件下载", position = 3)
|
||||
@Controller
|
||||
public class DownloadController {
|
||||
@RequestMapping("download")
|
||||
public class Example1003_DownloadController {
|
||||
|
||||
@ApiOperation(value = "文件下载", notes = "演示文件下载")
|
||||
@ApiMapping(value = "story.download", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE/* 这个一定要加,不然沙箱文档不起作用 */)
|
||||
@Open("file.download")
|
||||
@RequestMapping(value = "file1", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE/* 这个一定要加,不然沙箱文档不起作用 */)
|
||||
public ResponseEntity<byte[]> download(StoryParam param) throws IOException {
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
@@ -1,7 +1,8 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
import com.gitee.sop.servercommon.annotation.Open;
|
||||
import com.gitee.sop.storyweb.controller.param.GoodsParam;
|
||||
import com.gitee.sop.servercommon.annotation.ApiMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -11,9 +12,10 @@ import javax.servlet.http.HttpServletRequest;
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
public class JSR303DemoController {
|
||||
public class Example1004_JSR303Controller {
|
||||
|
||||
@ApiMapping(value = "goods.add")
|
||||
@Open("goods.add")
|
||||
@RequestMapping("jsr303")
|
||||
public Object addGoods(GoodsParam param, HttpServletRequest request) {
|
||||
System.out.println(request.getParameter("method"));
|
||||
return param;
|
@@ -1,7 +1,8 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
import com.gitee.sop.servercommon.annotation.ApiMapping;
|
||||
import com.gitee.sop.servercommon.annotation.Open;
|
||||
import com.gitee.sop.storyweb.controller.result.StoryResult;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
@@ -10,13 +11,14 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
public class PermissionDemoController {
|
||||
public class Example1005_PermissionController {
|
||||
|
||||
@ApiMapping(value = "permission.story.get", permission = true)
|
||||
@Open(value = "story.get.permission", permission = true)
|
||||
@RequestMapping("perm/get")
|
||||
public StoryResult getStory() {
|
||||
StoryResult story = new StoryResult();
|
||||
story.setId(1L);
|
||||
story.setName("海底小纵队(permission.story.get)");
|
||||
story.setName("海底小纵队(story.get.permission)");
|
||||
return story;
|
||||
}
|
||||
|
@@ -1,10 +1,11 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
import com.gitee.sop.servercommon.annotation.Open;
|
||||
import com.gitee.sop.servercommon.exception.ServiceException;
|
||||
import com.gitee.sop.storyweb.controller.param.GoodsUpdateParam;
|
||||
import com.gitee.sop.storyweb.message.GoodsErrorEnum;
|
||||
import com.gitee.sop.servercommon.annotation.ApiMapping;
|
||||
import com.gitee.sop.servercommon.exception.ServiceException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
@@ -12,9 +13,10 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
public class ThrowExceptionDemoController {
|
||||
public class Example1005_ThrowExceptionController {
|
||||
|
||||
@ApiMapping(value = "goods.update")
|
||||
@Open("goods.update")
|
||||
@RequestMapping("ex")
|
||||
public Object updateGoods(GoodsUpdateParam param) {
|
||||
// 方式1
|
||||
if ("iphone6".equals(param.getGoods_name())) {
|
@@ -1,28 +1,30 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
import com.gitee.sop.servercommon.annotation.ApiMapping;
|
||||
import com.gitee.sop.servercommon.bean.OpenContext;
|
||||
import com.gitee.sop.servercommon.bean.ServiceContext;
|
||||
import com.gitee.sop.servercommon.annotation.Open;
|
||||
import com.gitee.sop.servercommon.bean.ParamNames;
|
||||
import com.gitee.sop.storyweb.controller.param.StoryParam;
|
||||
import com.gitee.sop.storyweb.controller.result.StoryResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
@Slf4j
|
||||
@Api(tags = "故事接口")
|
||||
public class TokenController {
|
||||
public class Example1007_TokenController {
|
||||
|
||||
@ApiOperation(value="传递token", notes = "传递token")
|
||||
@ApiMapping(value = "story.token.get", needToken = true/* 设置true,网关会校验token是否存在 */)
|
||||
public StoryResult token(StoryParam story) {
|
||||
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
|
||||
String appAuthToken = openContext.getAppAuthToken();
|
||||
@Open(value = "story.get.token", needToken = true/* 设置true,网关会校验token是否存在 */)
|
||||
@RequestMapping("token")
|
||||
public StoryResult token(StoryParam story, HttpServletRequest request) {
|
||||
String appAuthToken = request.getParameter(ParamNames.APP_AUTH_TOKEN_NAME);
|
||||
StoryResult result = new StoryResult();
|
||||
result.setName("appAuthToken:" + appAuthToken);
|
||||
return result;
|
@@ -23,7 +23,7 @@ import java.util.Collection;
|
||||
@RestController
|
||||
@RequestMapping("food")
|
||||
@Api(tags = "食物接口")
|
||||
public class TraditionalWebappController {
|
||||
public class Example1008_RestfulController {
|
||||
|
||||
|
||||
// http://localhost:8081/rest/story-service/food/getFoodById?id=1 网关入口
|
@@ -1,41 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
import com.gitee.sop.servercommon.annotation.ApiMapping;
|
||||
import com.gitee.sop.servercommon.bean.OpenContext;
|
||||
import com.gitee.sop.servercommon.bean.ServiceContext;
|
||||
import com.gitee.sop.storyweb.controller.param.StoryParam;
|
||||
import com.gitee.sop.storyweb.controller.result.StoryResult;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
public class PostJsonController {
|
||||
|
||||
/**
|
||||
* 演示客户端使用json方式请求(application/json)
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
@ApiMapping("demo.post.json")
|
||||
public StoryResult postJson(@RequestBody StoryParam param) {
|
||||
// 获取开放平台请求参数
|
||||
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
|
||||
List<Object> params = Arrays.asList(
|
||||
openContext.getAppId(),
|
||||
openContext.getMethod(),
|
||||
openContext.getVersion()
|
||||
);
|
||||
StoryResult result = new StoryResult();
|
||||
result.setId(1L);
|
||||
result.setName("参数:" + param.getName() + ", openParams:" + StringUtils.join(params));
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@@ -1,4 +1,6 @@
|
||||
server.port=2222
|
||||
spring.application.name=story-service
|
||||
# nacos注册中心
|
||||
# 注册中心
|
||||
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
|
||||
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
|
||||
|
||||
|
Reference in New Issue
Block a user