支持配置json结果code值。

This commit is contained in:
mxd
2021-05-13 08:20:44 +08:00
parent 07618aac78
commit f8ff12e67c
3 changed files with 65 additions and 0 deletions

View File

@@ -44,6 +44,7 @@ import org.ssssssss.magicapi.interceptor.DefaultAuthorizationInterceptor;
import org.ssssssss.magicapi.interceptor.RequestInterceptor;
import org.ssssssss.magicapi.interceptor.SQLInterceptor;
import org.ssssssss.magicapi.logging.LoggerManager;
import org.ssssssss.magicapi.model.Constants;
import org.ssssssss.magicapi.modules.*;
import org.ssssssss.magicapi.provider.*;
import org.ssssssss.magicapi.provider.impl.*;
@@ -456,6 +457,11 @@ public class MagicAPIAutoConfiguration implements WebMvcConfigurer {
logger.info("magic-api工作目录:{}", magicResource);
setupSpringSecurity();
AsyncCall.setThreadPoolExecutorSize(properties.getThreadPoolExecutorSize());
// 设置响应结果的code值
ResponseCodeConfig responseCodeConfig = properties.getResponseCodeConfig();
Constants.RESPONSE_CODE_SUCCESS = responseCodeConfig.getSuccess();
Constants.RESPONSE_CODE_INVALID = responseCodeConfig.getInvalid();
Constants.RESPONSE_CODE_EXCEPTION = responseCodeConfig.getException();
// 设置模块和扩展方法
setupMagicModules(resultProvider, magicModules, extensionMethods, languageProviders);
MagicConfiguration configuration = new MagicConfiguration();

View File

@@ -113,6 +113,10 @@ public class MagicAPIProperties {
@NestedConfigurationProperty
private ResourceConfig resource = new ResourceConfig();
@NestedConfigurationProperty
private ResponseCodeConfig responseCodeConfig = new ResponseCodeConfig();
public String getEditorConfig() {
return editorConfig;
}
@@ -292,4 +296,12 @@ public class MagicAPIProperties {
public void setResponse(String response) {
this.response = response;
}
public ResponseCodeConfig getResponseCodeConfig() {
return responseCodeConfig;
}
public void setResponseCodeConfig(ResponseCodeConfig responseCodeConfig) {
this.responseCodeConfig = responseCodeConfig;
}
}

View File

@@ -0,0 +1,47 @@
package org.ssssssss.magicapi.spring.boot.starter;
/**
* json结果code配置
* @since 1.1.2
*/
public class ResponseCodeConfig {
/**
* 执行成功的code值
*/
private int success = 1;
/**
* 参数验证未通过的code值
*/
private int invalid = 0;
/**
* 执行出现异常的code值
*/
private int exception = -1;
public int getSuccess() {
return success;
}
public void setSuccess(int success) {
this.success = success;
}
public int getInvalid() {
return invalid;
}
public void setInvalid(int invalid) {
this.invalid = invalid;
}
public int getException() {
return exception;
}
public void setException(int exception) {
this.exception = exception;
}
}