添加文档,调整结构

1.x
tanghc 6 years ago
parent 2f368ec52a
commit 36f2339522
  1. 3
      README.md
  2. 22
      doc/docs/_sidebar.md
  3. 2
      doc/docs/files/10070_easyopen支持.md
  4. 3
      pom.xml
  5. 25
      sop-book/sop-book-api/.gitignore
  6. 46
      sop-book/sop-book-api/pom.xml
  7. 12
      sop-book/sop-book-api/src/main/java/com/hhdd/book/api/domain/Book.java
  8. 14
      sop-book/sop-book-api/src/main/java/com/hhdd/book/api/service/BookService.java
  9. 25
      sop-book/sop-book-web/.gitignore
  10. 89
      sop-book/sop-book-web/pom.xml
  11. 20
      sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/SopBookApplication.java
  12. 22
      sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/config/OpenServiceConfig.java
  13. 14
      sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/consumer/StoryServiceConsumer.java
  14. 40
      sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/AlipayBookController.java
  15. 74
      sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/ApiResult.java
  16. 73
      sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/BookController.java
  17. 11
      sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/param/BookParam.java
  18. 9
      sop-book/sop-book-web/src/main/resources/application.yml
  19. 7
      sop-book/sop-book-web/src/main/resources/bootstrap.yml
  20. 17
      sop-book/sop-book-web/src/test/java/com/gitee/sop/bookweb/SopBookApplicationTests.java
  21. 2
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/EasyopenServiceConfiguration.java
  22. 7
      sop-example/pom.xml
  23. 5
      sop-example/readme.md
  24. 15
      sop-story/pom.xml
  25. 25
      sop-story/sop-story-api/.gitignore
  26. 46
      sop-story/sop-story-api/pom.xml
  27. 18
      sop-story/sop-story-api/src/main/java/com/gitee/sop/story/api/domain/Story.java
  28. 15
      sop-story/sop-story-api/src/main/java/com/gitee/sop/story/api/service/StoryService.java
  29. 25
      sop-story/sop-story-web/.gitignore
  30. 84
      sop-story/sop-story-web/pom.xml
  31. 16
      sop-story/sop-story-web/src/main/java/com/gitee/sop/bookweb/SopStoryApplication.java
  32. 31
      sop-story/sop-story-web/src/main/java/com/gitee/sop/bookweb/config/OpenServiceConfig.java
  33. 27
      sop-story/sop-story-web/src/main/java/com/gitee/sop/bookweb/controller/AlipayController.java
  34. 18
      sop-story/sop-story-web/src/main/java/com/gitee/sop/bookweb/controller/JSR303DemoController.java
  35. 46
      sop-story/sop-story-web/src/main/java/com/gitee/sop/bookweb/controller/Story2Controller.java
  36. 85
      sop-story/sop-story-web/src/main/java/com/gitee/sop/bookweb/controller/StoryController.java
  37. 21
      sop-story/sop-story-web/src/main/java/com/gitee/sop/bookweb/controller/StoryDemoController.java
  38. 33
      sop-story/sop-story-web/src/main/java/com/gitee/sop/bookweb/controller/ThrowExceptionDemoController.java
  39. 19
      sop-story/sop-story-web/src/main/java/com/gitee/sop/bookweb/controller/param/GoodsParam.java
  40. 9
      sop-story/sop-story-web/src/main/java/com/gitee/sop/bookweb/controller/param/GoodsUpdateParam.java
  41. 20
      sop-story/sop-story-web/src/main/java/com/gitee/sop/bookweb/message/GoodsErrorEnum.java
  42. 21
      sop-story/sop-story-web/src/main/java/com/gitee/sop/bookweb/message/StoryErrorEnum.java
  43. 9
      sop-story/sop-story-web/src/main/resources/application.yml
  44. 8
      sop-story/sop-story-web/src/main/resources/bootstrap.yml
  45. 10
      sop-story/sop-story-web/src/main/resources/i18n/isp/bizerror_en.properties
  46. 14
      sop-story/sop-story-web/src/main/resources/i18n/isp/bizerror_zh_CN.properties
  47. 2
      sop-story/sop-story-web/src/main/resources/i18n/isp/goods_error_en.properties
  48. 5
      sop-story/sop-story-web/src/main/resources/i18n/isp/goods_error_zh_CN.properties
  49. 17
      sop-story/sop-story-web/src/test/java/com/gitee/sop/bookweb/SopStoryApplicationTests.java

@ -61,8 +61,7 @@ SOP封装了开放平台大部分功能包括:签名验证、统一异常处
- sop-registry:注册中心,eureka实现 - sop-registry:注册中心,eureka实现
- sop-gateway:网关,统一访问入口,Spring Cloud Zuul实现,可切换成Spring Cloud Gateway - sop-gateway:网关,统一访问入口,Spring Cloud Zuul实现,可切换成Spring Cloud Gateway
- sop-common:公共模块,封装常用功能,包含签名校验、错误处理等功能 - sop-common:公共模块,封装常用功能,包含签名校验、错误处理等功能
- sop-story:微服务示例,story服务,同时作为Provider提供服务 - sop-example:微服务示例
- sop-book:微服务示例,book服务,也是Consumer,调用story提供的服务
- sop-test:接口调用测试用例 - sop-test:接口调用测试用例

@ -1,13 +1,13 @@
* [首页](/?t=1553566189196) * [首页](/?t=1553568114881)
* 开发文档 * 开发文档
* [快速体验](files/10010_快速体验.md?t=1553566189197) * [快速体验](files/10010_快速体验.md?t=1553568114881)
* [项目接入到SOP](files/10011_项目接入到SOP.md?t=1553566189214) * [项目接入到SOP](files/10011_项目接入到SOP.md?t=1553568114907)
* [新增接口](files/10020_新增接口.md?t=1553566189215) * [新增接口](files/10020_新增接口.md?t=1553568114907)
* [业务参数校验](files/10030_业务参数校验.md?t=1553566189215) * [业务参数校验](files/10030_业务参数校验.md?t=1553568114907)
* [错误处理](files/10040_错误处理.md?t=1553566189215) * [错误处理](files/10040_错误处理.md?t=1553568114908)
* [接口交互详解](files/10050_接口交互详解.md?t=1553566189215) * [接口交互详解](files/10050_接口交互详解.md?t=1553568114908)
* [使用SpringCloudGateway](files/10060_使用SpringCloudGateway.md?t=1553566189215) * [使用SpringCloudGateway](files/10060_使用SpringCloudGateway.md?t=1553568114908)
* [easyopen支持](files/10070_easyopen支持.md?t=1553566189215) * [easyopen支持](files/10070_easyopen支持.md?t=1553568114908)
* 原理分析 * 原理分析
* [原理分析之@ApiMapping](files/90010_原理分析之@ApiMapping.md?t=1553566189215) * [原理分析之@ApiMapping](files/90010_原理分析之@ApiMapping.md?t=1553568114909)
* [原理分析之路由存储](files/90011_原理分析之路由存储.md?t=1553566189215) * [原理分析之路由存储](files/90011_原理分析之路由存储.md?t=1553568114909)

@ -61,3 +61,5 @@ public class ZuulConfig extends EasyopenZuulConfiguration {
配置完毕,重启网关服务,可运行测试用例`EasyopenClientPostTest.java`验证 配置完毕,重启网关服务,可运行测试用例`EasyopenClientPostTest.java`验证
**注:** 配置完成后easyopen签名校验将会关闭,改用网关端来校验;网关对easyopen返回的结果不进行处理,直接返回服务端的结果。 **注:** 配置完成后easyopen签名校验将会关闭,改用网关端来校验;网关对easyopen返回的结果不进行处理,直接返回服务端的结果。
完整配置可查看sop-example/sop-easyopen项目

@ -13,11 +13,10 @@
<modules> <modules>
<module>doc</module> <module>doc</module>
<module>sop-common</module> <module>sop-common</module>
<module>sop-example</module>
<module>sop-admin</module> <module>sop-admin</module>
<module>sop-registry</module> <module>sop-registry</module>
<module>sop-gateway</module> <module>sop-gateway</module>
<module>sop-story</module>
<module>sop-book</module>
<module>sop-test</module> <module>sop-test</module>
</modules> </modules>
</project> </project>

@ -1,25 +0,0 @@
/target/
!.mvn/wrapper/maven-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
/build/

@ -1,46 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-book-api</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>

@ -1,12 +0,0 @@
package com.gitee.book.api.domain;
import lombok.Data;
/**
* @author tanghc
*/
@Data
public class Book {
private int id;
private String name;
}

@ -1,14 +0,0 @@
package com.hhdd.book.api.service;
import com.gitee.book.api.domain.Book;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author tanghc
*/
@RequestMapping("/book")
public interface BookService {
@RequestMapping("/getBook")
Book getBook(@RequestParam("id") int id);
}

@ -1,25 +0,0 @@
/target/
!.mvn/wrapper/maven-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
/build/

@ -1,89 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-book-web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sop-story</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-book-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-story-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>compile</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
</project>

@ -1,20 +0,0 @@
package com.gitee.sop.bookweb;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
// 允许调用其他服务
@EnableFeignClients
// 服务注册
@EnableDiscoveryClient
@SpringBootApplication
public class SopBookApplication {
public static void main(String[] args) {
SpringApplication.run(SopBookApplication.class, args);
}
}

@ -1,22 +0,0 @@
package com.gitee.sop.bookweb.config;
import com.gitee.sop.servercommon.configuration.AlipayServiceConfiguration;
import org.springframework.context.annotation.Configuration;
/**
* 使用支付宝开放平台功能
* @author tanghc
*/
@Configuration
public class OpenServiceConfig extends AlipayServiceConfiguration {
}
/**
* 使用淘宝开放平台功能
* @author tanghc
*/
//@Configuration
//public class OpenServiceConfig extends TaobaoServiceConfiguration {
//
//}

@ -1,14 +0,0 @@
package com.gitee.sop.bookweb.consumer;
import com.gitee.sop.story.api.service.StoryService;
import org.springframework.cloud.openfeign.FeignClient;
/**
* 调用story服务
*
* @author tanghc
*/
// value对应的spring.application.name
@FeignClient("story-service")
public interface StoryServiceConsumer extends StoryService {
}

@ -1,40 +0,0 @@
package com.gitee.sop.bookweb.controller;
import com.gitee.sop.bookweb.consumer.StoryServiceConsumer;
import com.gitee.sop.servercommon.annotation.ApiMapping;
import com.gitee.sop.story.api.domain.Story;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays;
/**
* 支付宝服务端假设签名验证通过后到达这里进行具体的业务处理
* 这里演示如何接受业务参数
* @author tanghc
*/
@RestController
public class AlipayBookController {
@Autowired
StoryServiceConsumer storyServiceConsumer;
@ApiMapping(value = "alipay.book.get")
public Story getBook() {
Story story = new Story();
story.setId(1);
story.setName("白雪公主(alipay.book.get)");
return story;
}
// 调用story服务
@ApiMapping(value = "alipay.book.story.get")
public Object getBook2() {
Story story = new Story();
story.setId(1);
story.setName("白雪公主(alipay.book.story.get)");
Story story2 = storyServiceConsumer.getStory(1);
return Arrays.asList(story, story2);
}
}

@ -1,74 +0,0 @@
package com.gitee.sop.bookweb.controller;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.Data;
/**
* 默认的结果封装类.
* <pre>
*
* xml返回结果:
* <response>
* <code>50</code>
* <msg>Remote service error</msg>
* <sub_code>isv.invalid-parameter</sub_code>
* <sub_msg>非法参数</sub_msg>
* </response>
* 成功情况
* <response>
* <code>0</code>
* <msg>成功消息</msg>
* <data>
* ...返回内容
* </data>
* </response>
*
* json返回格式
* {
* "code":"50",
* "msg":"Remote service error",
* "sub_code":"isv.invalid-parameter",
* "sub_msg":"非法参数"
* }
* 成功情况
* {
* "code":"0",
* "msg":"成功消息内容。。。",
* "data":{
* ...返回内容
* }
* }
* </pre>
* <p>
* 字段说明
* code:网关异常码 <br>
* msg:网关异常信息 <br>
* sub_code:业务异常码 <br>
* sub_msg:业务异常信息 <br>
*
* @author tanghc
*/
@XStreamAlias("response")
@Data
public class ApiResult {
/**
* 网关异常信息
*/
private String msg;
/**
* 业务异常码
*/
private String sub_msg;
/**
* 业务异常信息
*/
private String sub_code;
/**
* 返回结果
*/
private Object data;
}

@ -1,73 +0,0 @@
package com.gitee.sop.bookweb.controller;
import com.gitee.book.api.domain.Book;
import com.gitee.sop.bookweb.consumer.StoryServiceConsumer;
import com.gitee.sop.bookweb.param.BookParam;
import com.gitee.sop.story.api.domain.Story;
import com.hhdd.book.api.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays;
/**
* book服务
*
* @author tanghc
*/
@RestController
public class BookController implements BookService {
@Autowired
StoryServiceConsumer storyServiceConsumer;
@Override
public Book getBook(int id) {
Book book = new Book();
book.setId(id);
book.setName("汪汪队");
return book;
}
@RequestMapping("listBookAndStory")
public Object listBookAndStory(int id) {
Book book = new Book();
book.setId(id);
book.setName("汪汪队");
// 调用story服务
Story story = storyServiceConsumer.getStory(id);
return Arrays.asList(book, story);
}
@RequestMapping("getBook2")
public Object getBookError(int id) {
if (id == 0) {
throw new RuntimeException("id不能为空");
}
Book book = new Book();
book.setId(id);
book.setName("汪汪队");
return Arrays.asList(book);
}
@RequestMapping("getBook3")
public Object getBook3(@RequestBody BookParam param) {
if (param.getId() == 0) {
throw new RuntimeException("id不能为空");
}
Book book = new Book();
book.setId(param.getId());
book.setName("小马宝莉");
ApiResult apiResult = new ApiResult();
apiResult.setData(book);
return apiResult;
}
}

@ -1,11 +0,0 @@
package com.gitee.sop.bookweb.param;
import lombok.Data;
/**
* @author tanghc
*/
@Data
public class BookParam {
private int id;
}

@ -1,9 +0,0 @@
server:
port: 3333
eureka:
port: 1111
host: localhost
client:
serviceUrl:
defaultZone: http://${eureka.host}:${eureka.port}/eureka/

@ -1,7 +0,0 @@
spring:
application:
name: book-service
cloud:
zookeeper:
connect-string: localhost:2181

@ -1,17 +0,0 @@
package com.gitee.sop.bookweb;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SopBookApplicationTests {
@Test
public void contextLoads() {
}
}

@ -27,7 +27,7 @@ import java.util.function.Consumer;
public class EasyopenServiceConfiguration extends BaseServiceConfiguration { public class EasyopenServiceConfiguration extends BaseServiceConfiguration {
static { static {
ApiContext.getApiConfig().setIgnoreValidate(false); ApiContext.getApiConfig().setIgnoreValidate(true);
} }
@Override @Override

@ -4,12 +4,13 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-book-parent</artifactId> <artifactId>sop-example</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>
<module>sop-book-api</module> <module>sop-story</module>
<module>sop-book-web</module> <module>sop-book</module>
<module>sop-easyopen</module>
</modules> </modules>
</project> </project>

@ -0,0 +1,5 @@
# 服务示例
- sop-story:微服务示例,story服务,同时作为Provider提供服务
- sop-book:微服务示例,book服务,也是Consumer,调用story提供的服务
- sop-easyopen:整合easyopen示例

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gitee.sop-story</groupId>
<artifactId>sop-story-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>sop-story-api</module>
<module>sop-story-web</module>
</modules>
</project>

@ -1,25 +0,0 @@
/target/
!.mvn/wrapper/maven-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
/build/

@ -1,46 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-story-api</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>

@ -1,18 +0,0 @@
package com.gitee.sop.story.api.domain;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
/**
* @author tanghc
*/
@Data
public class Story {
private int id;
@NotBlank(message = "name不能为空")
@Length(max = 20, message = "name长度不能超过20")
private String name;
}

@ -1,15 +0,0 @@
package com.gitee.sop.story.api.service;
import com.gitee.sop.story.api.domain.Story;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author tanghc
*/
@RequestMapping("/story")
public interface StoryService {
@RequestMapping("/getStory")
Story getStory(@RequestParam("id")/* 必须指定@RequestParam,且value不能少 */
int id);
}

@ -1,25 +0,0 @@
/target/
!.mvn/wrapper/maven-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
/build/

@ -1,84 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-story-web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sop-story</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-story-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
</project>

@ -1,16 +0,0 @@
package com.gitee.sop.bookweb;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@EnableDiscoveryClient
@SpringBootApplication
public class SopStoryApplication {
public static void main(String[] args) {
SpringApplication.run(SopStoryApplication.class, args);
}
}

@ -1,31 +0,0 @@
package com.gitee.sop.bookweb.config;
import com.gitee.sop.servercommon.bean.ServiceConfig;
import com.gitee.sop.servercommon.configuration.AlipayServiceConfiguration;
import com.gitee.sop.servercommon.configuration.TaobaoServiceConfiguration;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
/**
* 使用支付宝开放平台功能
* @author tanghc
*/
@Configuration
public class OpenServiceConfig extends AlipayServiceConfiguration {
static {
ServiceConfig.getInstance().getI18nModules().add("i18n/isp/goods_error");
}
}
/**
* 使用淘宝开放平台功能
* @author tanghc
*/
//@Configuration
//public class OpenServiceConfig extends TaobaoServiceConfiguration {
//
//}

@ -1,27 +0,0 @@
package com.gitee.sop.bookweb.controller;
import com.gitee.sop.servercommon.annotation.ApiMapping;
import com.gitee.sop.story.api.domain.Story;
import org.springframework.web.bind.annotation.RestController;
/**
* 支付宝服务端假设签名验证通过后到达这里进行具体的业务处理
* 这里演示如何接受业务参数
* @author tanghc
*/
@RestController
public class AlipayController {
@ApiMapping(value = "alipay.story.get")
public Story getStory() {
Story story = new Story();
story.setId(1);
story.setName("海底小纵队(alipay.story.get)");
return story;
}
@ApiMapping(value = "alipay.story.get", version = "1.2")
public Story getStory11(Story story) {
return story;
}
}

@ -1,18 +0,0 @@
package com.gitee.sop.bookweb.controller;
import com.gitee.sop.bookweb.controller.param.GoodsParam;
import com.gitee.sop.servercommon.annotation.ApiMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 演示参数验证
* @author tanghc
*/
@RestController
public class JSR303DemoController {
@ApiMapping(value = "goods.add")
public Object addGoods(GoodsParam param) {
return param;
}
}

@ -1,46 +0,0 @@
package com.gitee.sop.bookweb.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 org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author tanghc
*/
@ApiAbility // 放在这里,下面所有的接口都具备接口提供能力
@RestController
@RequestMapping("story2")
public class Story2Controller{
@RequestMapping("getStory4")
public Story getStory4() {
Story story = new Story();
story.setId(1);
story.setName("海底小纵队(getStory4)");
return story;
}
// 优先使用方法上@ApiAbility
@ApiAbility(version = "1.4")
@RequestMapping("getStory4")
public Story storyget() {
Story story = new Story();
story.setId(1);
story.setName("海底小纵队(1.4)");
return story;
}
// 优先使用@ApiMapping
@ApiMapping(value = "story.get2")
public Story getStory2() {
Story story = new Story();
story.setId(1);
story.setName("海底小纵队story.get2");
return story;
}
}

@ -1,85 +0,0 @@
package com.gitee.sop.bookweb.controller;
import com.gitee.sop.servercommon.annotation.ApiMapping;
import com.gitee.sop.servercommon.annotation.ApiAbility;
import com.gitee.sop.story.api.domain.Story;
import com.gitee.sop.story.api.service.StoryService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author tanghc
*/
@RestController
public class StoryController implements StoryService {
// 提供给Feign的服务
@Override
public Story getStory(int id) {
Story story = new Story();
story.setId(id);
story.setName("海底小纵队(Feign)");
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
@RequestMapping("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;
}
}

@ -1,21 +0,0 @@
package com.gitee.sop.bookweb.controller;
import com.gitee.sop.servercommon.annotation.ApiMapping;
import com.gitee.sop.story.api.domain.Story;
import org.springframework.web.bind.annotation.RestController;
/**
* @author tanghc
*/
@RestController
public class StoryDemoController {
@ApiMapping(value = "story.demo.get")
public Story getStory() {
Story story = new Story();
story.setId(1);
story.setName("白雪公主");
return story;
}
}

@ -1,33 +0,0 @@
package com.gitee.sop.bookweb.controller;
import com.gitee.sop.bookweb.controller.param.GoodsUpdateParam;
import com.gitee.sop.bookweb.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.RestController;
/**
* 演示如何抛出异常
* @author tanghc
*/
@RestController
public class ThrowExceptionDemoController {
@ApiMapping(value = "goods.update")
public Object updateGoods(GoodsUpdateParam param) {
// 方式1
if ("iphone6".equals(param.getGoods_name())) {
throw new ServiceException("不能更新iphone6");
}
// 方式2,国际化
if (StringUtils.isEmpty(param.getGoods_name())) {
throw GoodsErrorEnum.NO_GOODS_NAME.getErrorMeta().getException();
}
// 方式3,国际化传参
if (param.getGoods_name().length() <= 3) {
throw GoodsErrorEnum.LESS_GOODS_NAME_LEN.getErrorMeta().getException(3);
}
return param;
}
}

@ -1,19 +0,0 @@
package com.gitee.sop.bookweb.controller.param;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotEmpty;
@Data
public class GoodsParam {
// @NotEmpty(message = "商品名称不能为空")
private String goods_name;
@NotEmpty(message = "{goods.remark.notNull}")
private String goods_remark;
// 传参的格式:{xxx}=value1,value2...
@Length(min = 3, max = 20, message = "{goods.comment.length}=3,20")
private String goods_comment;
}

@ -1,9 +0,0 @@
package com.gitee.sop.bookweb.controller.param;
import lombok.Data;
@Data
public class GoodsUpdateParam {
private String goods_name;
}

@ -1,20 +0,0 @@
package com.gitee.sop.bookweb.message;
import com.gitee.sop.servercommon.message.ServiceErrorMeta;
public enum GoodsErrorEnum {
/** 参数错误 */
NO_GOODS_NAME("100"),
/** 参数长度太短 */
LESS_GOODS_NAME_LEN("101"),
;
private ServiceErrorMeta errorMeta;
GoodsErrorEnum(String subCode) {
this.errorMeta = new ServiceErrorMeta("isp.goods_error_", subCode);
}
public ServiceErrorMeta getErrorMeta() {
return errorMeta;
}
}

@ -1,21 +0,0 @@
package com.gitee.sop.bookweb.message;
import com.gitee.sop.servercommon.message.ServiceErrorMeta;
/**
* @author tanghc
*/
public enum StoryErrorEnum {
/** 参数错误 */
param_error("isv.invalid-parameter"),
;
private ServiceErrorMeta errorMeta;
StoryErrorEnum(String subCode) {
this.errorMeta = new ServiceErrorMeta("isp.error_", subCode);
}
public ServiceErrorMeta getErrorMeta() {
return errorMeta;
}
}

@ -1,9 +0,0 @@
server:
port: 2222
eureka:
port: 1111
host: localhost
client:
serviceUrl:
defaultZone: http://${eureka.host}:${eureka.port}/eureka/

@ -1,8 +0,0 @@
spring:
application:
name: story-service
description: story服务
cloud:
zookeeper:
connect-string: localhost:2181

@ -1,10 +0,0 @@
# 错误配置
# 系统配置
isp.error_isv.common-error=The system is busy.
isp.error_isv.invalid-parameter=Invalid parameter, {0}
# ==== 参数配置 ====
goods.remark.notNull=The goods_remark can not be null
goods.comment.length=The goods_comment length must >= {0} and <= {1}

@ -1,14 +0,0 @@
# 错误配置
# 系统繁忙
isp.error_isv.common-error=\u7cfb\u7edf\u7e41\u5fd9
# 参数无效
isp.error_isv.invalid-parameter=\u53c2\u6570\u65e0\u6548, {0}
# ==== 参数配置 ====
# 商品备注不能为空
goods.remark.notNull=\u5546\u54c1\u5907\u6ce8\u4e0d\u80fd\u4e3a\u7a7a
# 商品评论长度必须在{0}和{1}之间
goods.comment.length=\u5546\u54c1\u8bc4\u8bba\u957f\u5ea6\u5fc5\u987b\u5728{0}\u548c{1}\u4e4b\u95f4

@ -1,2 +0,0 @@
isp.goods_error_100=the goods_name can NOT be null
isp.goods_error_101=the goods_name must bigger than {0}

@ -1,5 +0,0 @@
# 商品名字不能为空
isp.goods_error_100=\u5546\u54C1\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A
# 商品名称太短,不能小于{0}个字
isp.goods_error_101=\u5546\u54C1\u540D\u79F0\u592A\u77ED\uFF0C\u4E0D\u80FD\u5C0F\u4E8E{0}\u4E2A\u5B57

@ -1,17 +0,0 @@
package com.gitee.sop.bookweb;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SopStoryApplicationTests {
@Test
public void contextLoads() {
}
}
Loading…
Cancel
Save