提交 9543b9f2 编写于 作者: M mxd

请求参数、`Header`支持`Date`类型

上级 c0017888
......@@ -49,6 +49,7 @@ import org.ssssssss.magicapi.exception.MagicAPIException;
import org.ssssssss.magicapi.interceptor.*;
import org.ssssssss.magicapi.logging.LoggerManager;
import org.ssssssss.magicapi.model.Constants;
import org.ssssssss.magicapi.model.DataType;
import org.ssssssss.magicapi.modules.*;
import org.ssssssss.magicapi.provider.*;
import org.ssssssss.magicapi.provider.impl.*;
......@@ -510,6 +511,7 @@ public class MagicAPIAutoConfiguration implements WebMvcConfigurer, WebSocketCon
MagicBackupService magicBackupService) throws NoSuchMethodException {
logger.info("magic-api工作目录:{}", magicResource);
AsyncCall.setThreadPoolExecutorSize(properties.getThreadPoolExecutorSize());
DataType.DATE_PATTERNS = properties.getDatePattern();
// 设置响应结果的code值
ResponseCodeConfig responseCodeConfig = properties.getResponseCodeConfig();
Constants.RESPONSE_CODE_SUCCESS = responseCodeConfig.getSuccess();
......
......@@ -114,6 +114,13 @@ public class MagicAPIProperties {
*/
private boolean showSql = true;
/**
* 请求参数日期格式
*
* @since 1.5.2
*/
private String[] datePattern = new String[]{"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyyMMddHHmmss", "yyyyMMdd"};
@NestedConfigurationProperty
private SecurityConfig securityConfig = new SecurityConfig();
......@@ -380,4 +387,11 @@ public class MagicAPIProperties {
this.showSql = showSql;
}
public String[] getDatePattern() {
return datePattern;
}
public void setDatePattern(String[] datePattern) {
this.datePattern = datePattern;
}
}
package org.ssssssss.magicapi.model;
import org.apache.commons.lang3.time.DateUtils;
import org.ssssssss.magicapi.modules.RequestModule;
import org.ssssssss.script.functions.ObjectConvertExtension;
import org.ssssssss.script.reflection.JavaInvoker;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Date;
import static org.ssssssss.script.reflection.JavaReflection.findInvoker;
......@@ -14,6 +18,7 @@ import static org.ssssssss.script.reflection.JavaReflection.findInvoker;
* @author mxd
*/
public enum DataType {
/**
* Object 类型
*/
......@@ -61,6 +66,11 @@ public enum DataType {
*/
Short(true, findInvoker(BigDecimal.class, "shortValue"), "number"),
/**
* Date类型
*/
Date(findInvoker(DataType.class, "parseDate", new Class<?>[]{String.class}), false, true, "string"),
/**
* MultipartFile 类型
*/
......@@ -82,6 +92,8 @@ public enum DataType {
private String javascriptType;
public static String[] DATE_PATTERNS;
DataType(boolean isNumber, JavaInvoker<Method> invoker, boolean needName, boolean needValue, String javascriptType) {
this.isNumber = isNumber;
this.invoker = invoker;
......@@ -122,4 +134,8 @@ public enum DataType {
public java.lang.String getJavascriptType() {
return javascriptType;
}
public static java.util.Date parseDate(String value) throws ParseException {
return DateUtils.parseDate(value, DATE_PATTERNS);
}
}
......@@ -216,6 +216,7 @@
{value: 'String', text: 'String'},
{value: 'Boolean', text: 'Boolean'},
{value: 'Integer', text: 'Integer'},
{value: 'Date', text: 'Date'},
{value: 'Double', text: 'Double'},
{value: 'Long', text: 'Long'},
{value: 'Short', text: 'Short'},
......@@ -226,6 +227,7 @@
{value: 'String', text: 'String'},
{value: 'Boolean', text: 'Boolean'},
{value: 'Integer', text: 'Integer'},
{value: 'Date', text: 'Date'},
{value: 'Double', text: 'Double'},
{value: 'Long', text: 'Long'},
{value: 'Short', text: 'Short'},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册