mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 12:56:28 +08:00
5.0
This commit is contained in:
@@ -15,6 +15,5 @@
|
||||
|
||||
<modules>
|
||||
<module>sop-story</module>
|
||||
<module>sop-springmvc</module>
|
||||
</modules>
|
||||
</project>
|
||||
|
25
sop-example/sop-springmvc/.gitignore
vendored
25
sop-example/sop-springmvc/.gitignore
vendored
@@ -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,181 +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/maven-v4_0_0.xsd">
|
||||
|
||||
<parent>
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-parent</artifactId>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>sop-springmvc</artifactId>
|
||||
<name>sop-springmvc</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<properties>
|
||||
<java-version>1.8</java-version>
|
||||
<org.springframework-version>5.0.7.RELEASE</org.springframework-version>
|
||||
<org.aspectj-version>1.6.10</org.aspectj-version>
|
||||
<org.slf4j-version>1.7.25</org.slf4j-version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- sop接入依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-service-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<!-- nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-spring-context</artifactId>
|
||||
<version>0.3.3</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- sop接入依赖 end -->
|
||||
|
||||
<!-- Spring -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${org.springframework-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>${org.springframework-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hibernate.validator</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- jackson -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>2.9.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.9.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
<version>2.9.6</version>
|
||||
</dependency>
|
||||
|
||||
<!-- AspectJ -->
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
<version>${org.aspectj-version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Logging -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${org.slf4j-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>${org.slf4j-version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>${org.slf4j-version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
|
||||
<!-- swagger2 -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- @Inject -->
|
||||
<dependency>
|
||||
<groupId>javax.inject</groupId>
|
||||
<artifactId>javax.inject</artifactId>
|
||||
<version>1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Servlet -->
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>2.5</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>jsp-api</artifactId>
|
||||
<version>2.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
<version>5.1.5.RELEASE</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- 打包时跳过测试 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.18.1</version>
|
||||
<configuration>
|
||||
<skipTests>true</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>${java-version}</source>
|
||||
<target>${java-version}</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@@ -1,43 +0,0 @@
|
||||
package com.gitee.app.config;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.core.env.PropertySources;
|
||||
import org.springframework.web.context.support.StandardServletEnvironment;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
public class MyPropertySourcesPlaceholderConfigurer extends PropertySourcesPlaceholderConfigurer implements EnvironmentAware {
|
||||
|
||||
private Environment environment;
|
||||
|
||||
@Override
|
||||
public void setEnvironment(Environment environment) {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||
super.postProcessBeanFactory(beanFactory);
|
||||
if (environment instanceof StandardServletEnvironment) {
|
||||
PropertySources appliedPropertySources = this.getAppliedPropertySources();
|
||||
for (PropertySource<?> propertySource : appliedPropertySources) {
|
||||
Object source = propertySource.getSource();
|
||||
if (source instanceof Map) {
|
||||
Map map = (Map)source;
|
||||
map.forEach((key, value)-> {
|
||||
System.setProperty(key.toString(), value.toString());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,68 +0,0 @@
|
||||
package com.gitee.app.config;
|
||||
|
||||
import com.alibaba.nacos.api.annotation.NacosInjected;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.api.naming.NamingService;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.api.utils.NetUtils;
|
||||
import com.alibaba.nacos.spring.context.annotation.discovery.EnableNacosDiscovery;
|
||||
import com.gitee.sop.servercommon.configuration.SpringmvcConfiguration;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
/**
|
||||
* 使用支付宝开放平台功能
|
||||
*
|
||||
* @author tanghc
|
||||
*/
|
||||
@Slf4j
|
||||
@EnableNacosDiscovery
|
||||
public class OpenServiceConfig extends SpringmvcConfiguration {
|
||||
|
||||
|
||||
public static final String SPRING_APPLICATION_NAME = "spring.application.name";
|
||||
public static final String SERVER_CONTEXT_PATH = "server.servlet.context-path";
|
||||
public static final String SERVER_IP = "server.ip";
|
||||
public static final String SERVER_PORT = "server.port";
|
||||
public static final String METADATA_TIME_STARTUP = "server.startup-time";
|
||||
|
||||
@Value("${spring.application.name}")
|
||||
private String serviceId;
|
||||
@Value("${server.port}")
|
||||
private int port;
|
||||
@Value("${server.servlet.context-path}")
|
||||
private String contextPath;
|
||||
|
||||
@NacosInjected
|
||||
private NamingService namingService;
|
||||
|
||||
@Override
|
||||
protected void doAfter() {
|
||||
super.doAfter();
|
||||
try {
|
||||
String ip = NetUtils.localIP();
|
||||
System.setProperty(SPRING_APPLICATION_NAME, serviceId);
|
||||
System.setProperty(SERVER_IP, ip);
|
||||
System.setProperty(SERVER_PORT, String.valueOf(port));
|
||||
System.setProperty(SERVER_CONTEXT_PATH, contextPath);
|
||||
|
||||
Instance instance = this.getInstance(serviceId, ip, port, contextPath);
|
||||
namingService.registerInstance(serviceId, instance);
|
||||
log.info("注册到nacos, serviceId: {}, ip: {}, port: {}, contextPath: {}", serviceId, ip, port, contextPath);
|
||||
} catch (NacosException e) {
|
||||
log.error("注册nacos失败", e);
|
||||
throw new RuntimeException("注册nacos失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
private Instance getInstance(String serviceId, String ip, int port, String contextPath) {
|
||||
Instance instance = new Instance();
|
||||
instance.setServiceName(serviceId);
|
||||
instance.setIp(ip);
|
||||
instance.setPort(port);
|
||||
instance.getMetadata().put(METADATA_SERVER_CONTEXT_PATH, contextPath);
|
||||
instance.getMetadata().put(METADATA_TIME_STARTUP, String.valueOf(System.currentTimeMillis()));
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
package com.gitee.app.config;
|
||||
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.api.naming.NamingService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
|
||||
/**
|
||||
* 容器销毁注销nacos,配置见web.xml
|
||||
*/
|
||||
@Slf4j
|
||||
public class OpenServletContextListener implements ServletContextListener {
|
||||
|
||||
private static WebApplicationContext webApplicationContext;
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce) {
|
||||
String serviceId = System.getProperty(OpenServiceConfig.SPRING_APPLICATION_NAME);
|
||||
String ip = System.getProperty(OpenServiceConfig.SERVER_IP);
|
||||
String port = System.getProperty(OpenServiceConfig.SERVER_PORT);
|
||||
|
||||
log.info("注销nacos,serviceId:{}, ip:{}, port:{}", serviceId, ip, port);
|
||||
|
||||
NamingService namingService = webApplicationContext.getBean(NamingService.class);
|
||||
try {
|
||||
namingService.deregisterInstance(serviceId, ip, Integer.parseInt(port));
|
||||
} catch (NacosException e) {
|
||||
log.error("注销nacos服务失败,serviceId:{}, ip:{}, port:{}", serviceId, ip, port);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce) {
|
||||
webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
|
||||
}
|
||||
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
package com.gitee.app.config;
|
||||
|
||||
import com.gitee.sop.servercommon.swagger.SwaggerSupport;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
/**
|
||||
* 开启文档,本地微服务文档地址:http://localhost:2222/doc.html
|
||||
* http://ip:port/v2/api-docs
|
||||
*/
|
||||
@EnableSwagger2
|
||||
public class Swagger2 extends SwaggerSupport {
|
||||
@Override
|
||||
protected String getDocTitle() {
|
||||
return "MVC_API";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean swaggerAccessProtected() {
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,68 +0,0 @@
|
||||
package com.gitee.app.controller;
|
||||
|
||||
import com.gitee.app.model.Goods;
|
||||
import com.gitee.app.model.StoryParam;
|
||||
import com.gitee.sop.servercommon.annotation.Open;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Handles requests for the application home page.
|
||||
*/
|
||||
@Api(tags = "MVC接口")
|
||||
@Controller
|
||||
public class HomeController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
|
||||
|
||||
/**
|
||||
* Simply selects the home view to render by returning its name.
|
||||
*/
|
||||
@RequestMapping(value = "/", method = RequestMethod.GET)
|
||||
public String home(Locale locale, Model model) {
|
||||
logger.info("Welcome home! The client locale is {}.", locale);
|
||||
|
||||
Date date = new Date();
|
||||
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
|
||||
|
||||
String formattedDate = dateFormat.format(date);
|
||||
|
||||
model.addAttribute("serverTime", formattedDate );
|
||||
|
||||
return "home";
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value="获取商品", notes = "获取商品说明")
|
||||
@Open("springmvc.goods.get")
|
||||
@RequestMapping("/goods/get")
|
||||
@ResponseBody
|
||||
public Goods getGoods(Goods param) {
|
||||
Goods goods = new Goods();
|
||||
goods.setId(1L);
|
||||
goods.setGoods_name(param.getGoods_name() + " 1");
|
||||
goods.setPrice(new BigDecimal(5000));
|
||||
return goods;
|
||||
}
|
||||
|
||||
@Open("springmvc.path.same")
|
||||
@RequestMapping("iam_same_path")
|
||||
@ResponseBody
|
||||
public Object iam_same_path(StoryParam param) {
|
||||
param.setName(param.getName() + " mvc..");
|
||||
return param;
|
||||
}
|
||||
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
package com.gitee.app.model;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class Goods {
|
||||
|
||||
private Long id;
|
||||
@NotBlank(message = "goods_name不能为空")
|
||||
private String goods_name;
|
||||
private BigDecimal price;
|
||||
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
package com.gitee.app.model;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
@Data
|
||||
public class StoryParam {
|
||||
@ApiModelProperty(value = "故事ID", example = "111")
|
||||
private int id;
|
||||
|
||||
@NotBlank(message = "name不能为空")
|
||||
@Length(max = 20, message = "name长度不能超过20")
|
||||
@ApiModelProperty(value = "故事名称", required = true, example = "白雪公主", position = 3)
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "备注 (第二)", example = "xx", position = 2)
|
||||
@Length(max = 64, message = "长度不能超过64")
|
||||
private String remark;
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
spring.application.name=sop-springmvc
|
||||
server.port=2223
|
||||
server.servlet.context-path=/sop-springmvc
|
||||
|
||||
nacos.server-addr=127.0.0.1:8848
|
@@ -1,41 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
|
||||
|
||||
<!-- Appenders -->
|
||||
<appender name="console" class="org.apache.log4j.ConsoleAppender">
|
||||
<param name="Target" value="System.out" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-5p: %c - %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- Application Loggers -->
|
||||
<logger name="com.gitee">
|
||||
<level value="debug" />
|
||||
</logger>
|
||||
|
||||
<!-- 3rdparty Loggers -->
|
||||
<logger name="org.springframework.core">
|
||||
<level value="info" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework.beans">
|
||||
<level value="info" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework.context">
|
||||
<level value="info" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework.web">
|
||||
<level value="info" />
|
||||
</logger>
|
||||
|
||||
<!-- Root Logger -->
|
||||
<root>
|
||||
<priority value="warn" />
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
@@ -1,44 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/mvc
|
||||
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
|
||||
|
||||
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
|
||||
|
||||
<bean class="com.gitee.app.config.MyPropertySourcesPlaceholderConfigurer">
|
||||
<property name="locations">
|
||||
<list>
|
||||
<value>classpath:application.properties</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- 只扫描Controller类 -->
|
||||
<context:component-scan base-package="com.gitee.app" use-default-filters="false">
|
||||
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
|
||||
</context:component-scan>
|
||||
|
||||
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
|
||||
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
||||
<property name="prefix" value="/WEB-INF/views/" />
|
||||
<property name="suffix" value=".jsp" />
|
||||
</bean>
|
||||
|
||||
<mvc:annotation-driven />
|
||||
|
||||
<bean class="com.gitee.app.config.OpenServiceConfig"/>
|
||||
|
||||
<!-- swagger2 配置 -->
|
||||
<mvc:resources location="classpath:/META-INF/resources/" mapping="doc.html"/>
|
||||
<mvc:resources location="classpath:/META-INF/resources/webjars/" mapping="/webjars/**"/>
|
||||
<bean class="com.gitee.app.config.Swagger2"/>
|
||||
<!-- 接入SOP配置 end -->
|
||||
|
||||
</beans>
|
@@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<bean class="com.gitee.app.config.MyPropertySourcesPlaceholderConfigurer">
|
||||
<property name="locations">
|
||||
<list>
|
||||
<value>classpath:application.properties</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- 排除Controller类 -->
|
||||
<context:component-scan base-package="com.gitee.app">
|
||||
<context:exclude-filter expression="org.springframework.stereotype.Controller"
|
||||
type="annotation" />
|
||||
</context:component-scan>
|
||||
|
||||
</beans>
|
@@ -1,15 +0,0 @@
|
||||
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
|
||||
<%@ page session="false" pageEncoding="utf-8" %>
|
||||
<html>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<head>
|
||||
<title>Home</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>
|
||||
Hello world!
|
||||
</h1>
|
||||
|
||||
<P> The time on the server is ${serverTime}. </P>
|
||||
</body>
|
||||
</html>
|
@@ -1,61 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
|
||||
|
||||
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
|
||||
<context-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>/WEB-INF/spring/root-context.xml</param-value>
|
||||
</context-param>
|
||||
|
||||
<!-- Creates the Spring Container shared by all Servlets and Filters -->
|
||||
<listener>
|
||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<!-- SOP监听 -->
|
||||
<listener>
|
||||
<listener-class>com.gitee.app.config.OpenServletContextListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<!-- Processes application requests -->
|
||||
<servlet>
|
||||
<servlet-name>appServlet</servlet-name>
|
||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
<!-- 配置swagger-bootstrap-ui的url请求路径-->
|
||||
<servlet-mapping>
|
||||
<servlet-name>appServlet</servlet-name>
|
||||
<url-pattern>/v2/api-docs</url-pattern>
|
||||
</servlet-mapping>
|
||||
<servlet-mapping>
|
||||
<servlet-name>appServlet</servlet-name>
|
||||
<url-pattern>/swagger-resources</url-pattern>
|
||||
</servlet-mapping>
|
||||
<servlet-mapping>
|
||||
<servlet-name>appServlet</servlet-name>
|
||||
<url-pattern>/swagger-resources/configuration/ui</url-pattern>
|
||||
</servlet-mapping>
|
||||
<servlet-mapping>
|
||||
<servlet-name>appServlet</servlet-name>
|
||||
<url-pattern>/swagger-resources/configuration/security</url-pattern>
|
||||
</servlet-mapping>
|
||||
<!--此接口地址为SwaggerBootstrapUi提供的增强地址,如果不使用增强功能,可排除此配置-->
|
||||
<servlet-mapping>
|
||||
<servlet-name>appServlet</servlet-name>
|
||||
<url-pattern>/v2/api-docs-ext</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>appServlet</servlet-name>
|
||||
<url-pattern>/</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
</web-app>
|
@@ -1,41 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
|
||||
|
||||
<!-- Appenders -->
|
||||
<appender name="console" class="org.apache.log4j.ConsoleAppender">
|
||||
<param name="Target" value="System.out" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-5p: %c - %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- Application Loggers -->
|
||||
<logger name="com.gitee.app">
|
||||
<level value="info" />
|
||||
</logger>
|
||||
|
||||
<!-- 3rdparty Loggers -->
|
||||
<logger name="org.springframework.core">
|
||||
<level value="info" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework.beans">
|
||||
<level value="info" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework.context">
|
||||
<level value="info" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework.web">
|
||||
<level value="info" />
|
||||
</logger>
|
||||
|
||||
<!-- Root Logger -->
|
||||
<root>
|
||||
<priority value="info" />
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
@@ -10,6 +10,7 @@
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>sop-story</artifactId>
|
||||
<name>sop-story</name>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
@@ -18,8 +19,8 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-service-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<artifactId>sop-spring-boot-starter</artifactId>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -27,32 +28,25 @@
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 使用nacos注册中心 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 使用eureka注册中心 -->
|
||||
<!--<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>
|
||||
|
||||
<!-- swagger2 -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-boot-starter</artifactId>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>nacos-discovery-spring-boot-starter</artifactId>
|
||||
<version>0.2.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -63,7 +57,7 @@
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.4</version>
|
||||
<version>1.18.34</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@@ -1,11 +1,11 @@
|
||||
package com.gitee.sop.storyweb;
|
||||
|
||||
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
@EnableDubbo
|
||||
public class SopStoryApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
@@ -1,48 +0,0 @@
|
||||
package com.gitee.sop.storyweb;
|
||||
|
||||
import com.gitee.sop.servercommon.exception.ExceptionHolder;
|
||||
import com.gitee.sop.servercommon.exception.ServiceException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* 全局异常处理
|
||||
*
|
||||
* @author tanghc
|
||||
*/
|
||||
@ControllerAdvice
|
||||
@Slf4j
|
||||
public class StoryGlobalExceptionHandler {
|
||||
|
||||
|
||||
/**
|
||||
* 捕获手动抛出的异常
|
||||
*
|
||||
* @param request request
|
||||
* @param response response
|
||||
* @param exception 异常信息
|
||||
* @return 返回提示信息
|
||||
*/
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseBody
|
||||
public Object exceptionHandler(HttpServletRequest request, HttpServletResponse response, Exception exception) {
|
||||
// 在返回前加这一句
|
||||
ExceptionHolder.hold(request, response, exception);
|
||||
// 下面可以实现自己的全局异常处理
|
||||
return new ErrorResult(500, exception.getMessage());
|
||||
}
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public static class ErrorResult {
|
||||
private int code;
|
||||
private String msg;
|
||||
}
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
package com.gitee.sop.storyweb.config;
|
||||
|
||||
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 springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
/**
|
||||
* 开放平台功能
|
||||
* @author tanghc
|
||||
*/
|
||||
@Configuration
|
||||
public class OpenServiceConfig extends AlipayServiceConfiguration {
|
||||
|
||||
static {
|
||||
ServiceConfig.getInstance().getI18nModules().add("i18n/isp/goods_error");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 开启文档,本地微服务文档地址:http://localhost:2222/doc.html
|
||||
* http://ip:port/v2/api-docs
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public static class Swagger2 extends SwaggerSupport {
|
||||
@Override
|
||||
protected String getDocTitle() {
|
||||
return "故事API";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean swaggerAccessProtected() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,329 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.gitee.sop.servercommon.annotation.BizCode;
|
||||
import com.gitee.sop.servercommon.annotation.Open;
|
||||
import com.gitee.sop.servercommon.bean.OpenContext;
|
||||
import com.gitee.sop.servercommon.bean.ServiceContext;
|
||||
import com.gitee.sop.servercommon.exception.ServiceException;
|
||||
import com.gitee.sop.storyweb.controller.param.ArrayElementParam;
|
||||
import com.gitee.sop.storyweb.controller.param.CategoryParam;
|
||||
import com.gitee.sop.storyweb.controller.param.GoodsParam;
|
||||
import com.gitee.sop.storyweb.controller.param.LargeTextParam;
|
||||
import com.gitee.sop.storyweb.controller.param.MemberInfoGetParam;
|
||||
import com.gitee.sop.storyweb.controller.param.StoryParam;
|
||||
import com.gitee.sop.storyweb.controller.param.TypeEnum;
|
||||
import com.gitee.sop.storyweb.controller.result.CategoryResult;
|
||||
import com.gitee.sop.storyweb.controller.result.MemberInfoGetResult;
|
||||
import com.gitee.sop.storyweb.controller.result.MemberInfoGetResultMemberInfo;
|
||||
import com.gitee.sop.storyweb.controller.result.StoryResult;
|
||||
import com.gitee.sop.storyweb.controller.result.TestResult;
|
||||
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.beans.factory.annotation.Value;
|
||||
import org.springframework.util.StringUtils;
|
||||
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.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 签名验证通过后,到达这里进行具体的业务处理。
|
||||
*
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("story")
|
||||
@Slf4j
|
||||
@Api(tags = "故事接口")
|
||||
public class Example1001_BaseController {
|
||||
|
||||
@Value("${server.port}")
|
||||
private int port;
|
||||
|
||||
// http://localhost:2222/stroy/get
|
||||
// 原生的接口,可正常调用
|
||||
@RequestMapping("/get")
|
||||
public StoryResult get() {
|
||||
StoryResult result = new StoryResult();
|
||||
result.setId(1L);
|
||||
result.setName("海底小纵队(原生)");
|
||||
return result;
|
||||
}
|
||||
|
||||
// 基础用法
|
||||
@ApiOperation(value = "获取故事信息(首位)", notes = "获取故事信息的详细信息", position = -100/* position默认0,值越小越靠前 */)
|
||||
@Open(value = "story.get", bizCode = {
|
||||
// 定义业务错误码,用于文档显示
|
||||
@BizCode(code = "100001", msg = "姓名错误", solution = "填写正确的姓名"),
|
||||
@BizCode(code = "100002", msg = "备注错误", solution = "填写正确备注"),
|
||||
})
|
||||
@RequestMapping("/get/v1")
|
||||
public StoryResult get_v1(StoryParam param) {
|
||||
StoryResult story = new StoryResult();
|
||||
story.setId(1L);
|
||||
story.setName("海底小纵队(story.get1.0), " + "param:" + param + ", port:" + port);
|
||||
return story;
|
||||
}
|
||||
|
||||
// 指定版本号
|
||||
@ApiOperation(value = "获取故事信息", notes = "获取故事信息的详细信息")
|
||||
@Open(value = "story.get", version = "2.0", bizCode = {
|
||||
// 定义业务错误码,用于文档显示
|
||||
@BizCode(code = "100001", msg = "姓名错误", solution = "填写正确的姓名"),
|
||||
@BizCode(code = "100002", msg = "备注错误", solution = "填写正确备注"),
|
||||
})
|
||||
@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.system.param.get")
|
||||
@GetMapping("/get/system/param/v1")
|
||||
public StoryResult systemParam(StoryParam param) {
|
||||
StoryResult result = new StoryResult();
|
||||
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
|
||||
System.out.println(param == openContext.getBizObject());
|
||||
System.out.println("app_id:" + openContext.getAppId());
|
||||
System.out.println("token:" + openContext.getAppAuthToken());
|
||||
result.setName("系统参数:" + openContext);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Open(value = "story.system.param.get2")
|
||||
@GetMapping("/get/system/param/v2")
|
||||
public StoryResult systemParam2() {
|
||||
StoryResult result = new StoryResult();
|
||||
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
|
||||
String token = openContext.getAppAuthToken();
|
||||
result.setName(token);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Open(value = "story.system.param.get3")
|
||||
@GetMapping("/get/system/param/v3")
|
||||
public StoryResult systemParam3(HttpServletRequest request) {
|
||||
System.out.println(request.getParameter("app_id"));
|
||||
StoryResult result = new StoryResult();
|
||||
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
|
||||
String token = openContext.getAppAuthToken();
|
||||
result.setName(token);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Open("story.system.param.get4")
|
||||
@RequestMapping("/get/system/param/v4")
|
||||
public Object addGoods3(HttpServletRequest request, StoryParam param) {
|
||||
param.setRemark(request.getRequestURI());
|
||||
return param;
|
||||
}
|
||||
|
||||
@Open("story.system.param.get5")
|
||||
@RequestMapping("/get/system/param/v5")
|
||||
public Object get5(HttpServletRequest request, HttpServletResponse response, StoryParam param) {
|
||||
param.setRemark(request.getRequestURI() + ", getCharacterEncoding:" + response.getCharacterEncoding());
|
||||
return param;
|
||||
}
|
||||
|
||||
// 参数绑定,少量参数可以这样写,参数多了建议放进类里面
|
||||
@Open(value = "story.oneparam")
|
||||
@GetMapping("/oneParam/v1")
|
||||
public StoryResult oneParam(@NotBlank(message = "id不能为空") String id, @NotBlank(message = "name不能为空") String name) {
|
||||
StoryResult result = new StoryResult();
|
||||
result.setName("id:" + id + ", name:" + name);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 参数绑定
|
||||
@Open(value = "story.oneparam", version = "1.1")
|
||||
@GetMapping("/oneParam/v2")
|
||||
public StoryResult oneParamV2(Integer id) {
|
||||
StoryResult result = new StoryResult();
|
||||
result.setName("id:" + id);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 参数绑定,枚举
|
||||
@Open(value = "story.oneparam", version = "1.2")
|
||||
@GetMapping("/oneParam/v3")
|
||||
public StoryResult oneParamV2(@NotNull(message = "typeEnum不能为空") TypeEnum typeEnum) {
|
||||
StoryResult result = new StoryResult();
|
||||
result.setName("typeEnum:" + typeEnum.name());
|
||||
return result;
|
||||
}
|
||||
|
||||
// 参数绑定
|
||||
@Open(value = "story.param.bind", mergeResult = false)
|
||||
@RequestMapping("/get/param/v1")
|
||||
public StoryResult param(String id, String name) {
|
||||
StoryResult result = new StoryResult();
|
||||
result.setName("参数绑定:id:" + id + ", name:" + name);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 忽略验证
|
||||
@ApiOperation(value = "忽略签名验证", notes = "忽略签名验证")
|
||||
@Open(value = "story.get.ignore", ignoreValidate = true)
|
||||
@RequestMapping(value = "/get/ignore/v1")
|
||||
public StoryResult getStory21(@RequestBody StoryParam story) {
|
||||
StoryResult result = new StoryResult();
|
||||
result.setId((long) story.getId());
|
||||
result.setName(story.getName() + ", ignoreValidate = true");
|
||||
return result;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "接收数组", notes = "接收数组")
|
||||
@Open(value = "story.listparam")
|
||||
@PostMapping(value = "/get/listparam/v1")
|
||||
public StoryResult listparam(@RequestBody ArrayElementParam story) {
|
||||
StoryResult result = new StoryResult();
|
||||
result.setId(11L);
|
||||
result.setName(JSON.toJSONString(story));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Open(value = "story.get.large")
|
||||
@RequestMapping("/get/large/v1")
|
||||
public StoryResult getStoryLarge(LargeTextParam param) {
|
||||
StoryResult result = new StoryResult();
|
||||
int length = param.getContent().getBytes(StandardCharsets.UTF_8).length;
|
||||
result.setName("length:" + length);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 绑定复杂对象
|
||||
@Open(value = "sdt.get",version = "4.0")
|
||||
@RequestMapping("/get/v4")
|
||||
public TestResult getV4(@RequestBody TestResult testResult) {
|
||||
if(StringUtils.isEmpty(testResult.getType())) {
|
||||
throw new ServiceException("testResult.getType() 不能为null");
|
||||
}
|
||||
return testResult;
|
||||
}
|
||||
|
||||
// 获取header
|
||||
@Open(value = "test.head",version = "1.0")
|
||||
@GetMapping("/get/header/v1")
|
||||
public StoryResult header(@RequestBody StoryParam story, HttpServletRequest request) {
|
||||
HttpServletRequest servletRequest = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
StoryResult storyResult = new StoryResult();
|
||||
storyResult.setId(1L);
|
||||
storyResult.setName(story.getName()
|
||||
+ ", token1:" + request.getHeader("token")
|
||||
+ ", token2:" + servletRequest.getHeader("token"));
|
||||
return storyResult;
|
||||
}
|
||||
|
||||
// 返回数组结果
|
||||
@ApiOperation(value = "返回数组结果(第二)", notes = "返回数组结果", position = -99)
|
||||
@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;
|
||||
}
|
||||
|
||||
private static String json = "{\"flightDate\":\"2020-09-01\",\"flightNo\":\"HO1705\",\"departureAirport\":\"ZSCN\",\"arrivalAirport\":\"ZPLJ\",\"ycy\":\"11521\",\"lcy\":\"4354\",\"cr\":\"145\",\"et\":\"1\",\"ye\":\"0\",\"td\":\"0\",\"gw\":\"0\",\"ew\":\"146\",\"xl\":\"1018\",\"yj\":\"0\",\"hw\":\"635\"}";
|
||||
// 返回大数据
|
||||
@Open(value = "bigdata.get")
|
||||
@RequestMapping("/bigdata/v1")
|
||||
public Map<String, Object> bigData(StoryParam param) {
|
||||
int len = 2000;
|
||||
List<JSONObject> list = new ArrayList<>(len);
|
||||
for (int i = 0; i < len; i++) {
|
||||
list.add(JSON.parseObject(json));
|
||||
}
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("data", list);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Open(value = "member.info.get")
|
||||
@RequestMapping("/member/info/get")
|
||||
public MemberInfoGetResult memberInfoGet(MemberInfoGetParam param) {
|
||||
MemberInfoGetResult result = new MemberInfoGetResult();
|
||||
MemberInfoGetResultMemberInfo memberInfo = new MemberInfoGetResultMemberInfo();
|
||||
memberInfo.setIsVip((byte)1);
|
||||
memberInfo.setVipEndtime(new Date());
|
||||
result.setName(JSON.toJSONString(param));
|
||||
result.setId(11);
|
||||
result.setMemberInfo(memberInfo);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@@ -1,116 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
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;
|
||||
import com.gitee.sop.storyweb.controller.result.FileUploadResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.Extension;
|
||||
import io.swagger.annotations.ExtensionProperty;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 演示文件上传
|
||||
*
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("upload")
|
||||
@Api(tags = "文件上传", position = 2)
|
||||
public class Example1002_FileUploadController {
|
||||
|
||||
/**
|
||||
* 方式1:将文件写在参数中,可直接获取。好处是可以校验是否上传
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "文件上传例1", notes = "上传文件demo")
|
||||
@Open("file.upload")
|
||||
@PostMapping(value = "file1", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public FileUploadResult file1(FileUploadParam param) {
|
||||
// 获取上传的文件
|
||||
MultipartFile file1 = param.getFile1();
|
||||
MultipartFile file2 = param.getFile2();
|
||||
|
||||
FileUploadResult result = new FileUploadResult();
|
||||
FileUploadResult.FileMeta fileMeta1 = buildFileMeta(file1);
|
||||
FileUploadResult.FileMeta fileMeta2 = buildFileMeta(file2);
|
||||
|
||||
result.setRemark(param.getRemark());
|
||||
result.getFiles().add(fileMeta1);
|
||||
result.getFiles().add(fileMeta2);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 方式2:从request中获取上传文件
|
||||
*
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "文件上传例2", notes = "可上传多个文件"
|
||||
// 多文件上传、不确定文件数量上传,必须申明下面这句,否则沙盒界面不会出现上传控件
|
||||
, extensions = @Extension(properties = @ExtensionProperty(name = "multiple", value = "multiple")))
|
||||
@Open("file.upload2")
|
||||
@PostMapping(value = "file2", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public FileUploadResult file2(FileUploadParam2 param, HttpServletRequest request) {
|
||||
System.out.println(param.getRemark());
|
||||
FileUploadResult result = new FileUploadResult();
|
||||
// 获取上传的文件
|
||||
Collection<MultipartFile> uploadFiles = UploadUtil.getUploadFiles(request);
|
||||
for (MultipartFile multipartFile : uploadFiles) {
|
||||
FileUploadResult.FileMeta fileMeta = buildFileMeta(multipartFile);
|
||||
result.getFiles().add(fileMeta);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Open("file.upload3")
|
||||
@PostMapping(value = "file3", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public FileUploadResult file3(FileUploadParam2 param, HttpServletRequest request) {
|
||||
System.out.println(param.getRemark());
|
||||
FileUploadResult result = new FileUploadResult();
|
||||
// 获取上传的文件
|
||||
Collection<MultipartFile> uploadFiles = UploadUtil.getUploadFiles(request);
|
||||
Optional<MultipartFile> first = uploadFiles.stream().findFirst();
|
||||
if (first.isPresent()) {
|
||||
MultipartFile multipartFile = first.get();
|
||||
try {
|
||||
String path = System.getProperty("user.dir");
|
||||
multipartFile.transferTo(new File(path + "/img_"+System.currentTimeMillis()+".png"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private FileUploadResult.FileMeta buildFileMeta(MultipartFile multipartFile) {
|
||||
// 文件名
|
||||
String fileName = multipartFile.getOriginalFilename();
|
||||
// 文件大小
|
||||
long size = multipartFile.getSize();
|
||||
// 文件内容
|
||||
String fileContent = null;
|
||||
try {
|
||||
fileContent = IOUtils.toString(multipartFile.getInputStream(), StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new FileUploadResult.FileMeta(fileName, size, fileContent);
|
||||
}
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
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;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 演示文件下载
|
||||
*
|
||||
* @author tanghc
|
||||
*/
|
||||
@Api(tags = "文件下载", position = 3)
|
||||
@Controller
|
||||
@RequestMapping("download")
|
||||
public class Example1003_DownloadController {
|
||||
|
||||
@ApiOperation(value = "文件下载", notes = "演示文件下载")
|
||||
@Open("file.download")
|
||||
@RequestMapping(value = "file1", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE/* 这个一定要加,不然沙箱文档不起作用 */)
|
||||
public ResponseEntity<byte[]> download(StoryParam param) throws IOException {
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
// 假设下载classpath下的application.properties文件
|
||||
ClassPathResource resource = new ClassPathResource("/application.properties");
|
||||
|
||||
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||
headers.setContentDispositionFormData("attachment", resource.getFilename());
|
||||
|
||||
return ResponseEntity
|
||||
.ok()
|
||||
.headers(headers)
|
||||
.body(IOUtils.toByteArray(resource.getInputStream()));
|
||||
}
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
import com.gitee.sop.servercommon.annotation.Open;
|
||||
import com.gitee.sop.storyweb.controller.param.GoodsParam;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 演示参数验证
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
public class Example1004_JSR303Controller {
|
||||
|
||||
@Open("goods.add")
|
||||
@RequestMapping("jsr303")
|
||||
public Object addGoods(GoodsParam param, HttpServletRequest request) {
|
||||
System.out.println(request.getParameter("method"));
|
||||
return param;
|
||||
}
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* 支付宝服务端,假设签名验证通过后,到达这里进行具体的业务处理。
|
||||
* 这里演示如何接受业务参数。
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
public class Example1005_PermissionController {
|
||||
|
||||
@Open(value = "story.get.permission", permission = true)
|
||||
@RequestMapping("perm/get")
|
||||
public StoryResult getStory() {
|
||||
StoryResult story = new StoryResult();
|
||||
story.setId(1L);
|
||||
story.setName("海底小纵队(story.get.permission)");
|
||||
return story;
|
||||
}
|
||||
|
||||
}
|
@@ -1,42 +0,0 @@
|
||||
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 org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 演示如何抛出异常
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
public class Example1005_ThrowExceptionController {
|
||||
|
||||
@Open("goods.update")
|
||||
@RequestMapping("ex")
|
||||
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;
|
||||
}
|
||||
|
||||
@Open("goods.update2")
|
||||
@RequestMapping("ex2")
|
||||
public Object updateGoods2(GoodsUpdateParam param) {
|
||||
int i = 1/0;
|
||||
return param;
|
||||
}
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
import com.gitee.sop.servercommon.annotation.Open;
|
||||
import com.gitee.sop.servercommon.bean.OpenContext;
|
||||
import com.gitee.sop.servercommon.bean.ParamNames;
|
||||
import com.gitee.sop.servercommon.bean.ServiceContext;
|
||||
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 Example1007_TokenController {
|
||||
|
||||
@ApiOperation(value="传递token", notes = "传递token")
|
||||
@Open(value = "story.get.token", needToken = true/* 设置true,网关会校验token是否存在 */)
|
||||
@RequestMapping("token")
|
||||
public StoryResult token(StoryParam story, HttpServletRequest request) {
|
||||
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
|
||||
StoryResult result = new StoryResult();
|
||||
result.setName("appAuthToken:" + openContext.getAppAuthToken());
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -1,103 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
import com.gitee.sop.servercommon.util.UploadUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
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 org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 传统web开发实例
|
||||
*
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("food")
|
||||
@Api(tags = "食物接口")
|
||||
public class Example1008_RestfulController {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
// http://localhost:8081/rest/story-service/food/getFoodById?id=1 网关入口
|
||||
// http://localhost:2222/food/getFoodById/?id=12 本地入口
|
||||
@ApiOperation(value="获取食物", notes = "根据id获取食物")
|
||||
@RequestMapping(value = "getFoodById", method = RequestMethod.GET)
|
||||
public Food getFoodById(Integer id) {
|
||||
Food food = new Food();
|
||||
food.setId(id);
|
||||
food.setName("香蕉, " + environment.getProperty("server.port"));
|
||||
food.setPrice(new BigDecimal(20.00));
|
||||
return food;
|
||||
}
|
||||
|
||||
// http://localhost:8081/rest/story-service/food/getFoodByObj?id=2
|
||||
@RequestMapping(value = "getFoodByObj", method = RequestMethod.GET)
|
||||
public Food getFoodByObj(Food food) {
|
||||
return food;
|
||||
}
|
||||
|
||||
// http://localhost:8081/rest/story-service/food/saveFood
|
||||
@RequestMapping(value = "saveFood", method = RequestMethod.POST)
|
||||
public Food saveFood(@RequestBody Food food) {
|
||||
food.setId(3);
|
||||
return food;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "foodUpload", method = RequestMethod.POST)
|
||||
public Food upload(Food food, HttpServletRequest request) {
|
||||
// 获取上传的文件
|
||||
Collection<MultipartFile> uploadFiles = UploadUtil.getUploadFiles(request);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (MultipartFile multipartFile : uploadFiles) {
|
||||
sb.append(multipartFile.getOriginalFilename());
|
||||
}
|
||||
food.setId(4);
|
||||
food.setName("文件名称+" + sb.toString());
|
||||
return food;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "foodUpload3", method = RequestMethod.POST)
|
||||
public Food upload3(Food food, MultipartFile file) {
|
||||
food.setId(5);
|
||||
food.setName("文件名称+" + file.getOriginalFilename());
|
||||
return food;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "foodUpload2", method = RequestMethod.POST)
|
||||
public Food upload2(Food food, MultipartFile file) {
|
||||
food.setId(4);
|
||||
food.setName("文件名称2+" + file.getOriginalFilename());
|
||||
return food;
|
||||
}
|
||||
|
||||
// http://localhost:2222/food/get/3 本地
|
||||
// http://localhost:8081/rest/story-service/food/get/3 网关访问
|
||||
@RequestMapping("/get/{id}")
|
||||
public Food getById(@PathVariable("id") Integer id) {
|
||||
Food food = new Food();
|
||||
food.setId(id);
|
||||
food.setName("香蕉");
|
||||
food.setPrice(BigDecimal.valueOf(100));
|
||||
return food;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Food {
|
||||
private Integer id;
|
||||
private String name;
|
||||
private BigDecimal price;
|
||||
}
|
||||
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
import com.gitee.sop.servercommon.annotation.Open;
|
||||
import com.gitee.sop.storyweb.controller.param.StoryParam;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 模拟超时设置
|
||||
*
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
public class Example1009_TimeoutController {
|
||||
|
||||
@Open("goods.timeout")
|
||||
@RequestMapping("timeoutTest")
|
||||
public Object timeout(StoryParam param) {
|
||||
// 模拟耗时操作,耗时10秒
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return param;
|
||||
}
|
||||
}
|
@@ -1,22 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
import com.gitee.sop.servercommon.annotation.Open;
|
||||
import com.gitee.sop.storyweb.controller.param.StoryParam;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 模拟超时设置
|
||||
*
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
public class Example1010_SamePathController {
|
||||
|
||||
@Open("story.path.same")
|
||||
@RequestMapping("iam_same_path")
|
||||
public Object iam_same_path(StoryParam param) {
|
||||
param.setName(param.getName() + " story..");
|
||||
return param;
|
||||
}
|
||||
}
|
@@ -1,20 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller.param;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@Data
|
||||
public class ArrayElementParam {
|
||||
|
||||
@ApiModelProperty(value = "名字", required = true, example = "白雪公主", position = 1)
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "数组", required = true, dataType = "List", example = "白雪公主", position = 2)
|
||||
private List<StoryParam> list;
|
||||
|
||||
}
|
@@ -1,19 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller.param;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class CategoryParam {
|
||||
@ApiModelProperty(value = "分类名称", example = "娱乐")
|
||||
private String categoryName;
|
||||
|
||||
@ApiModelProperty(value = "创建时间", example = "2019-09-25 17:12:52")
|
||||
private Date createTime;
|
||||
|
||||
@ApiModelProperty(value = "分类故事")
|
||||
private StoryParam storyParam;
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller.param;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@Data
|
||||
public class FileUploadParam {
|
||||
private String remark;
|
||||
|
||||
// 上传文件,字段名称对应表单中的name属性值
|
||||
@NotNull(message = "请上传文件1")
|
||||
@ApiModelProperty(value = "文件1", required = true)
|
||||
private MultipartFile file1;
|
||||
|
||||
@NotNull(message = "请上传文件2")
|
||||
@ApiModelProperty(value = "文件2", required = true)
|
||||
private MultipartFile file2;
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@Data
|
||||
public class FileUploadParam2 {
|
||||
private String remark;
|
||||
|
||||
}
|
@@ -1,19 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller.param;
|
||||
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
@Data
|
||||
public class GoodsParam {
|
||||
@NotBlank(message = "商品名称不能为空")
|
||||
private String goods_name;
|
||||
|
||||
@NotBlank(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.storyweb.controller.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GoodsUpdateParam {
|
||||
private String goods_name;
|
||||
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@Data
|
||||
public class LargeTextParam {
|
||||
private String content;
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller.param;
|
||||
|
||||
/**
|
||||
* 请求参数
|
||||
*/
|
||||
public class MemberInfoGetParam {
|
||||
private String name;
|
||||
private Integer age;
|
||||
private String address;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(Integer age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller.param;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
@Data
|
||||
public class StoryParam {
|
||||
@ApiModelProperty(value = "故事ID", example = "111")
|
||||
private int id;
|
||||
|
||||
@NotBlank(message = "name不能为空")
|
||||
@Length(max = 20, message = "name长度不能超过20")
|
||||
@ApiModelProperty(value = "故事名称", required = true, example = "白雪公主", position = 3)
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "备注 (第二)", example = "xx", position = 2)
|
||||
@Length(max = 64, message = "长度不能超过64")
|
||||
private String remark;
|
||||
}
|
@@ -1,8 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller.param;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
public enum TypeEnum {
|
||||
MOBILE, COMPUTER
|
||||
}
|
@@ -1,13 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller.result;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CategoryResult {
|
||||
@ApiModelProperty(value = "分类名称", example = "娱乐")
|
||||
private String categoryName;
|
||||
|
||||
@ApiModelProperty(value = "分类故事")
|
||||
private StoryResult storyResult;
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller.result;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@Data
|
||||
public class FileUploadResult {
|
||||
|
||||
private List<FileMeta> files = new ArrayList();
|
||||
private String remark;
|
||||
|
||||
@Data
|
||||
public static class FileMeta {
|
||||
|
||||
public FileMeta(String filename, long size, String content) {
|
||||
this.filename = filename;
|
||||
this.size = size;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public FileMeta() {
|
||||
}
|
||||
|
||||
@ApiModelProperty(value = "文件名称", example = "1.txt")
|
||||
private String filename;
|
||||
@ApiModelProperty(value = "文件大小", example = "109")
|
||||
private long size;
|
||||
@ApiModelProperty(value = "文件内容", example = "啊啊啊")
|
||||
private String content;
|
||||
}
|
||||
}
|
@@ -1,39 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller.result;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
* 接口返回结果
|
||||
*/
|
||||
public class MemberInfoGetResult {
|
||||
|
||||
private Integer id;
|
||||
private String name;
|
||||
|
||||
@JsonProperty("member_info")
|
||||
private MemberInfoGetResultMemberInfo memberInfo;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public MemberInfoGetResultMemberInfo getMemberInfo() {
|
||||
return memberInfo;
|
||||
}
|
||||
|
||||
public void setMemberInfo(MemberInfoGetResultMemberInfo memberInfo) {
|
||||
this.memberInfo = memberInfo;
|
||||
}
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller.result;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class MemberInfoGetResultMemberInfo {
|
||||
@JsonProperty("is_vip")
|
||||
private Byte isVip;
|
||||
|
||||
@JsonProperty("vip_endtime")
|
||||
private Date vipEndtime;
|
||||
|
||||
public Byte getIsVip() {
|
||||
return isVip;
|
||||
}
|
||||
|
||||
public void setIsVip(Byte isVip) {
|
||||
this.isVip = isVip;
|
||||
}
|
||||
|
||||
public Date getVipEndtime() {
|
||||
return vipEndtime;
|
||||
}
|
||||
|
||||
public void setVipEndtime(Date vipEndtime) {
|
||||
this.vipEndtime = vipEndtime;
|
||||
}
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller.result;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@Data
|
||||
public class StoryResult {
|
||||
@ApiModelProperty(value = "故事ID", required = true, example = "1")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "故事名称", required = true, example = "海底小纵队")
|
||||
@Length(max = 20)
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "创建时间", example = "2019-04-14 19:02:12")
|
||||
private Date gmt_create;
|
||||
}
|
@@ -1,20 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller.result;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class TestResult {
|
||||
|
||||
@ApiModelProperty(value = "标签", example = "学习")
|
||||
private String label;
|
||||
|
||||
@ApiModelProperty(value = "类型", example = "1 超管 2 普管")
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty(value = "集合", example = "集合")
|
||||
List<TestResult> ss;
|
||||
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller.result;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@Data
|
||||
public class TreeResult {
|
||||
@ApiModelProperty(value = "id")
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "父id")
|
||||
private Integer pid;
|
||||
|
||||
@ApiModelProperty(value = "子节点")
|
||||
private List<TreeResult> children;
|
||||
}
|
@@ -1,20 +0,0 @@
|
||||
package com.gitee.sop.storyweb.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.storyweb.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;
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package com.gitee.sop.storyweb.open;
|
||||
|
||||
import com.gitee.sop.storyweb.open.req.StorySaveDTO;
|
||||
import com.gitee.sop.storyweb.open.resp.StoryResponse;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
public interface StoryService {
|
||||
|
||||
Integer save(StorySaveDTO storySaveDTO);
|
||||
|
||||
StoryResponse getById(Integer id);
|
||||
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
package com.gitee.sop.storyweb.open.impl;
|
||||
|
||||
import com.gitee.sop.springboot.starter.annotation.Open;
|
||||
import com.gitee.sop.storyweb.open.StoryService;
|
||||
import com.gitee.sop.storyweb.open.req.StorySaveDTO;
|
||||
import com.gitee.sop.storyweb.open.resp.StoryResponse;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
|
||||
/**
|
||||
* 开放接口实现
|
||||
*
|
||||
* @author 六如
|
||||
*/
|
||||
@DubboService(validation = "true")
|
||||
public class StoreyServiceImpl implements StoryService {
|
||||
|
||||
@Open("story.save")
|
||||
@Override
|
||||
public Integer save(StorySaveDTO storySaveDTO) {
|
||||
System.out.println("save storySaveDTO:" + storySaveDTO);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Open("story.get")
|
||||
@Override
|
||||
public StoryResponse getById(@NotNull(message = "id必填") Integer id) {
|
||||
StoryResponse storyResponse = new StoryResponse();
|
||||
storyResponse.setId(id);
|
||||
storyResponse.setName("乌鸦喝水");
|
||||
return storyResponse;
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package com.gitee.sop.storyweb.open.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
@Data
|
||||
public class StorySaveDTO implements Serializable {
|
||||
private static final long serialVersionUID = -1214422742659231037L;
|
||||
|
||||
@NotBlank(message = "故事名称必填")
|
||||
private String storyName;
|
||||
|
||||
@NotNull(message = "添加时间必填")
|
||||
private Date addTime;
|
||||
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package com.gitee.sop.storyweb.open.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
@Data
|
||||
public class StoryResponse implements Serializable {
|
||||
private static final long serialVersionUID = -3743413007549072654L;
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
}
|
@@ -1,9 +1,9 @@
|
||||
server.port=2222
|
||||
server.port=8082
|
||||
spring.application.name=story-service
|
||||
register.url=127.0.0.1:8848
|
||||
# \u6CE8\u518C\u4E2D\u5FC3
|
||||
spring.cloud.nacos.discovery.server-addr=${register.url}
|
||||
# nacos
|
||||
nacos.host=127.0.0.1:8848
|
||||
|
||||
# \u4E0A\u4F20\u6587\u4EF6\u6700\u5927\u503C
|
||||
spring.servlet.multipart.max-file-size=20MB
|
||||
spring.servlet.multipart.max-request-size=20MB
|
||||
dubbo.protocol.name=dubbo
|
||||
dubbo.protocol.port=-1
|
||||
dubbo.application.qos-enable=false
|
||||
dubbo.registry.address=nacos://${nacos.host}
|
||||
|
@@ -1,2 +1 @@
|
||||
spring.profiles.active=dev
|
||||
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
|
Reference in New Issue
Block a user