Эх сурвалжийг харах

代码优化&提示优化

mxd 3 жил өмнө
parent
commit
659211cce6
31 өөрчлөгдсөн 791 нэмэгдсэн , 673 устгасан
  1. 1 1
      magic-api/src/main/java/org/ssssssss/magicapi/adapter/resource/DatabaseResource.java
  2. 1 1
      magic-api/src/main/java/org/ssssssss/magicapi/adapter/resource/RedisResource.java
  3. 10 14
      magic-api/src/main/java/org/ssssssss/magicapi/config/MagicFunctionManager.java
  4. 1 1
      magic-api/src/main/java/org/ssssssss/magicapi/config/MappingHandlerMapping.java
  5. 1 1
      magic-api/src/main/java/org/ssssssss/magicapi/context/CookieContext.java
  6. 1 1
      magic-api/src/main/java/org/ssssssss/magicapi/controller/MagicDebugHandler.java
  7. 2 2
      magic-api/src/main/java/org/ssssssss/magicapi/controller/RequestHandler.java
  8. 50 49
      magic-api/src/main/java/org/ssssssss/magicapi/logging/Formatter.java
  9. 1 1
      magic-api/src/main/java/org/ssssssss/magicapi/logging/LogbackLoggerContext.java
  10. 5 3
      magic-api/src/main/java/org/ssssssss/magicapi/model/Attributes.java
  11. 5 12
      magic-api/src/main/java/org/ssssssss/magicapi/model/DataType.java
  12. 2 1
      magic-api/src/main/java/org/ssssssss/magicapi/model/RequestEntity.java
  13. 5 5
      magic-api/src/main/java/org/ssssssss/magicapi/modules/AssertModule.java
  14. 35 36
      magic-api/src/main/java/org/ssssssss/magicapi/modules/BoundSql.java
  15. 3 2
      magic-api/src/main/java/org/ssssssss/magicapi/modules/EnvModule.java
  16. 15 12
      magic-api/src/main/java/org/ssssssss/magicapi/modules/HttpModule.java
  17. 22 9
      magic-api/src/main/java/org/ssssssss/magicapi/modules/MongoCollectionExtension.java
  18. 4 4
      magic-api/src/main/java/org/ssssssss/magicapi/modules/RequestModule.java
  19. 20 12
      magic-api/src/main/java/org/ssssssss/magicapi/modules/ResponseModule.java
  20. 91 55
      magic-api/src/main/java/org/ssssssss/magicapi/modules/SQLModule.java
  21. 69 58
      magic-api/src/main/java/org/ssssssss/magicapi/modules/mybatis/ForeachSqlNode.java
  22. 18 16
      magic-api/src/main/java/org/ssssssss/magicapi/modules/mybatis/IfSqlNode.java
  23. 5 4
      magic-api/src/main/java/org/ssssssss/magicapi/modules/mybatis/SetSqlNode.java
  24. 28 25
      magic-api/src/main/java/org/ssssssss/magicapi/modules/mybatis/TextSqlNode.java
  25. 69 60
      magic-api/src/main/java/org/ssssssss/magicapi/modules/mybatis/TrimSqlNode.java
  26. 144 128
      magic-api/src/main/java/org/ssssssss/magicapi/modules/table/NamedTable.java
  27. 173 129
      magic-api/src/main/java/org/ssssssss/magicapi/modules/table/Where.java
  28. 2 1
      magic-api/src/main/java/org/ssssssss/magicapi/provider/PageProvider.java
  29. 5 23
      magic-api/src/main/java/org/ssssssss/magicapi/provider/impl/DefaultMagicAPIService.java
  30. 2 2
      magic-api/src/main/java/org/ssssssss/magicapi/provider/impl/DefaultPageProvider.java
  31. 1 5
      magic-api/src/main/java/org/ssssssss/magicapi/script/ScriptManager.java

+ 1 - 1
magic-api/src/main/java/org/ssssssss/magicapi/adapter/resource/DatabaseResource.java

@@ -60,7 +60,7 @@ public class DatabaseResource extends KeyValueResource {
 		if (value == null) {
 			String sql = String.format("select file_content from %s where file_path = ?", tableName);
 			value = template.queryForObject(sql, String.class, this.path);
-			if(value != null){
+			if (value != null) {
 				this.cachedContent.put(path, value);
 			}
 		}

+ 1 - 1
magic-api/src/main/java/org/ssssssss/magicapi/adapter/resource/RedisResource.java

@@ -51,7 +51,7 @@ public class RedisResource extends KeyValueResource {
 		String value = this.cachedContent.get(path);
 		if (value == null) {
 			value = redisTemplate.opsForValue().get(path);
-			if(value != null){
+			if (value != null) {
 				this.cachedContent.put(path, value);
 			}
 		}

+ 10 - 14
magic-api/src/main/java/org/ssssssss/magicapi/config/MagicFunctionManager.java

@@ -48,22 +48,18 @@ public class MagicFunctionManager {
 				String scriptName = groupServiceProvider.getScriptName(info.getGroupId(), info.getName(), info.getPath());
 				List<Parameter> parameters = info.getParameters();
 				return (Function<Object[], Object>) objects -> {
-					try {
-						MagicScriptContext functionContext = new MagicScriptContext(context.getRootVariables());
-						functionContext.setScriptName(scriptName);
-						if (objects != null) {
-							for (int i = 0, len = objects.length, size = parameters.size(); i < len && i < size; i++) {
-								functionContext.set(parameters.get(i).getName(), objects[i]);
-							}
+					MagicScriptContext functionContext = new MagicScriptContext(context.getRootVariables());
+					functionContext.setScriptName(scriptName);
+					if (objects != null) {
+						for (int i = 0, len = objects.length, size = parameters.size(); i < len && i < size; i++) {
+							functionContext.set(parameters.get(i).getName(), objects[i]);
 						}
-						Object value = ScriptManager.executeScript(info.getScript(), functionContext);
-						if (value instanceof ExitValue) {
-							throw new MagicExitException((ExitValue) value);
-						}
-						return value;
-					} finally {
-						MagicScriptContext.set(context);
 					}
+					Object value = ScriptManager.executeScript(info.getScript(), functionContext);
+					if (value instanceof ExitValue) {
+						throw new MagicExitException((ExitValue) value);
+					}
+					return value;
 				};
 			}
 			return null;

+ 1 - 1
magic-api/src/main/java/org/ssssssss/magicapi/config/MappingHandlerMapping.java

@@ -50,7 +50,7 @@ public class MappingHandlerMapping {
 	/**
 	 * 请求到达时处理的方法
 	 */
-	private final Method method = RequestHandler.class.getDeclaredMethod("invoke", HttpServletRequest.class, HttpServletResponse.class, Map.class,Map.class, Map.class);
+	private final Method method = RequestHandler.class.getDeclaredMethod("invoke", HttpServletRequest.class, HttpServletResponse.class, Map.class, Map.class, Map.class);
 	/**
 	 * 统一接口前缀
 	 */

+ 1 - 1
magic-api/src/main/java/org/ssssssss/magicapi/context/CookieContext.java

@@ -19,7 +19,7 @@ public class CookieContext extends HashMap<String, String> {
 
 	@Override
 	public String get(Object key) {
-		if(cookies != null){
+		if (cookies != null) {
 			for (Cookie cookie : cookies) {
 				if (cookie.getName().equalsIgnoreCase("" + key)) {
 					return cookie.getValue();

+ 1 - 1
magic-api/src/main/java/org/ssssssss/magicapi/controller/MagicDebugHandler.java

@@ -52,7 +52,7 @@ public class MagicDebugHandler {
 			context.setStepInto("1".equals(stepInto));
 			if (StringUtils.isNotBlank(breakpoints)) {
 				context.setBreakpoints(Stream.of(breakpoints.split("\\|")).map(Integer::valueOf).collect(Collectors.toList()));
-			}else {
+			} else {
 				context.setBreakpoints(Collections.emptyList());
 			}
 			try {

+ 2 - 2
magic-api/src/main/java/org/ssssssss/magicapi/controller/RequestHandler.java

@@ -60,10 +60,10 @@ public class RequestHandler extends MagicController {
 
 	private static final Logger logger = LoggerFactory.getLogger(RequestHandler.class);
 	private static final Map<String, Object> EMPTY_MAP = new HashMap<>();
-	private final ResultProvider resultProvider;
 	private static final List<String> DEFAULT_ALLOW_READ_RESPONSE_HEADERS = Arrays.asList(
 			ACCESS_CONTROL_ALLOW_CREDENTIALS, ACCESS_CONTROL_ALLOW_HEADERS, ACCESS_CONTROL_ALLOW_METHODS, ACCESS_CONTROL_ALLOW_METHODS,
 			CONTENT_TYPE, DATE, SERVER, SET_COOKIE, CONNECTION, CONTENT_LENGTH, CONTENT_ENCODING, TRANSFER_ENCODING, VARY);
+	private final ResultProvider resultProvider;
 
 	public RequestHandler(MagicConfiguration configuration) {
 		super(configuration);
@@ -203,7 +203,7 @@ public class RequestHandler extends MagicController {
 		if (CollectionUtils.isEmpty(validateParameters)) {
 			return parameters;
 		}
-		if(disabledUnknownParameter){
+		if (disabledUnknownParameter) {
 			removeUnknownKey(parameters, validateParameters);
 		}
 		for (BaseDefinition parameter : validateParameters) {

+ 50 - 49
magic-api/src/main/java/org/ssssssss/magicapi/logging/Formatter.java

@@ -25,16 +25,58 @@ public class Formatter {
 	}
 
 
-	public static Formatter create(){
+	public static Formatter create() {
 		return new Formatter();
 	}
 
-	public Formatter timestamp(long timestamp){
+	private static void leftPad(StringBuilder buf, String s, int desiredLength) {
+		int actualLen = 0;
+		if (s != null) {
+			actualLen = s.length();
+		}
+		if (actualLen < desiredLength) {
+			spacePad(buf, desiredLength - actualLen);
+		}
+		if (s != null) {
+			buf.append(s);
+		}
+	}
+
+	private static void rightPad(StringBuilder buf, String s, int desiredLength) {
+		int actualLen = 0;
+		if (s != null) {
+			actualLen = s.length();
+		}
+		if (s != null) {
+			buf.append(s);
+		}
+		if (actualLen < desiredLength) {
+			spacePad(buf, desiredLength - actualLen);
+		}
+	}
+
+	/**
+	 * Fast space padding method.
+	 */
+	private static void spacePad(StringBuilder sbuf, int length) {
+		while (length >= 32) {
+			sbuf.append(SPACES[5]);
+			length -= 32;
+		}
+
+		for (int i = 4; i >= 0; i--) {
+			if ((length & (1 << i)) != 0) {
+				sbuf.append(SPACES[i]);
+			}
+		}
+	}
+
+	public Formatter timestamp(long timestamp) {
 		buf.append(CACHING_DATE_FORMATTER.format(timestamp));
 		return this;
 	}
 
-	public Formatter space(){
+	public Formatter space() {
 		buf.append(SPACES[0]);
 		return this;
 	}
@@ -43,6 +85,7 @@ public class Formatter {
 		buf.append(value);
 		return this;
 	}
+
 	public Formatter newline() {
 		buf.append("\n");
 		return this;
@@ -65,8 +108,8 @@ public class Formatter {
 		return buf.toString();
 	}
 
-	public Formatter throwable(Throwable throwable){
-		if(throwable != null){
+	public Formatter throwable(Throwable throwable) {
+		if (throwable != null) {
 			this.newline();
 			StringWriter sw = new StringWriter(1024);
 			PrintWriter writer = new PrintWriter(sw);
@@ -78,7 +121,7 @@ public class Formatter {
 		return this;
 	}
 
-	private Formatter alignment(String value, int min, int max, boolean leftTruncate, boolean leftPad){
+	private Formatter alignment(String value, int min, int max, boolean leftTruncate, boolean leftPad) {
 		if (value == null) {
 			if (0 < min) {
 				spacePad(buf, min);
@@ -104,53 +147,11 @@ public class Formatter {
 		return this;
 	}
 
-	private static void leftPad(StringBuilder buf, String s, int desiredLength) {
-		int actualLen = 0;
-		if (s != null) {
-			actualLen = s.length();
-		}
-		if (actualLen < desiredLength) {
-			spacePad(buf, desiredLength - actualLen);
-		}
-		if (s != null) {
-			buf.append(s);
-		}
-	}
-
-	private static void rightPad(StringBuilder buf, String s, int desiredLength) {
-		int actualLen = 0;
-		if (s != null) {
-			actualLen = s.length();
-		}
-		if (s != null) {
-			buf.append(s);
-		}
-		if (actualLen < desiredLength) {
-			spacePad(buf, desiredLength - actualLen);
-		}
-	}
-
-	/**
-	 * Fast space padding method.
-	 */
-	private static void spacePad(StringBuilder sbuf, int length) {
-		while (length >= 32) {
-			sbuf.append(SPACES[5]);
-			length -= 32;
-		}
-
-		for (int i = 4; i >= 0; i--) {
-			if ((length & (1 << i)) != 0) {
-				sbuf.append(SPACES[i]);
-			}
-		}
-	}
-
 	private static class CachingDateFormatter {
 
+		final SimpleDateFormat sdf;
 		long lastTimestamp = -1;
 		String cachedStr = null;
-		final SimpleDateFormat sdf;
 
 		public CachingDateFormatter(String pattern) {
 			sdf = new SimpleDateFormat(pattern);

+ 1 - 1
magic-api/src/main/java/org/ssssssss/magicapi/logging/LogbackLoggerContext.java

@@ -42,7 +42,7 @@ public class LogbackLoggerContext implements MagicLoggerContext {
 					.value(event.getFormattedMessage())
 					.newline();
 			IThrowableProxy proxy = event.getThrowableProxy();
-			if(proxy instanceof ThrowableProxy){
+			if (proxy instanceof ThrowableProxy) {
 				formatter.throwable(((ThrowableProxy) proxy).getThrowable());
 			}
 			MagicLoggerContext.println(formatter.toString());

+ 5 - 3
magic-api/src/main/java/org/ssssssss/magicapi/model/Attributes.java

@@ -17,8 +17,9 @@ public class Attributes<T> {
 
 	/**
 	 * 设置属性
-	 * @param key	key
-	 * @param value	value
+	 *
+	 * @param key   key
+	 * @param value value
 	 */
 	@UnableCall
 	public void setAttribute(String key, T value) {
@@ -27,7 +28,8 @@ public class Attributes<T> {
 
 	/**
 	 * 获取属性
-	 * @param key	key
+	 *
+	 * @param key key
 	 */
 	@UnableCall
 	public Object getAttribute(String key) {

+ 5 - 12
magic-api/src/main/java/org/ssssssss/magicapi/model/DataType.java

@@ -2,13 +2,11 @@ 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;
 
@@ -82,18 +80,13 @@ public enum DataType {
 	MultipartFiles(findInvoker(RequestModule.class, "getFiles", new Class<?>[]{String.class}), true, false, "file");
 
 
+	public static String[] DATE_PATTERNS;
 	private boolean isNumber;
-
 	private JavaInvoker<Method> invoker;
-
 	private boolean needName;
-
 	private boolean needValue;
-
 	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;
@@ -115,6 +108,10 @@ public enum DataType {
 		this.javascriptType = javascriptType;
 	}
 
+	public static java.util.Date parseDate(String value) throws ParseException {
+		return DateUtils.parseDate(value, DATE_PATTERNS);
+	}
+
 	public boolean isNumber() {
 		return isNumber;
 	}
@@ -134,8 +131,4 @@ 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);
-	}
 }

+ 2 - 1
magic-api/src/main/java/org/ssssssss/magicapi/model/RequestEntity.java

@@ -9,7 +9,8 @@ import javax.servlet.http.HttpServletResponse;
 import java.util.*;
 import java.util.stream.Collectors;
 
-import static org.ssssssss.magicapi.model.Constants.*;
+import static org.ssssssss.magicapi.model.Constants.HEADER_REQUEST_BREAKPOINTS;
+import static org.ssssssss.magicapi.model.Constants.HEADER_REQUEST_SESSION;
 
 /**
  * 请求信息

+ 5 - 5
magic-api/src/main/java/org/ssssssss/magicapi/modules/AssertModule.java

@@ -22,7 +22,7 @@ public class AssertModule implements MagicModule {
 	 * @param message 状态说明
 	 */
 	@Comment("判断值不能为空")
-	public void notNull(@Comment("值") Object value, @Comment("判断失败时的code") int code, @Comment("判断失败时的说明") String message) {
+	public void notNull(@Comment(name = "value", value = "值") Object value, @Comment(name = "code", value = "判断失败时的code") int code, @Comment(name = "message", value = "判断失败时的说明") String message) {
 		if (value == null) {
 			throw new MagicScriptAssertException(code, message);
 		}
@@ -36,7 +36,7 @@ public class AssertModule implements MagicModule {
 	 * @param message 状态说明
 	 */
 	@Comment("判断值不能为Empty")
-	public void notEmpty(@Comment("值") String value, @Comment("判断失败时的code") int code, @Comment("判断失败时的说明") String message) {
+	public void notEmpty(@Comment(name = "value", value = "值") String value, @Comment(name = "code", value = "判断失败时的code") int code, @Comment(name = "message", value = "判断失败时的说明") String message) {
 		if (StringUtils.isEmpty(value)) {
 			throw new MagicScriptAssertException(code, message);
 		}
@@ -50,7 +50,7 @@ public class AssertModule implements MagicModule {
 	 * @param message 状态说明
 	 */
 	@Comment("判断值不能为Blank")
-	public void notBlank(@Comment("值") String value, @Comment("判断失败时的code") int code, @Comment("判断失败时的说明") String message) {
+	public void notBlank(@Comment(name = "value", value = "值") String value, @Comment(name = "code", value = "判断失败时的code") int code, @Comment(name = "message", value = "判断失败时的说明") String message) {
 		if (StringUtils.isBlank(value)) {
 			throw new MagicScriptAssertException(code, message);
 		}
@@ -64,7 +64,7 @@ public class AssertModule implements MagicModule {
 	 * @param message 状态说明
 	 */
 	@Comment("正则判断")
-	public void regx(@Comment("值") String value, String pattern, @Comment("判断失败时的code") int code, @Comment("判断失败时的说明") String message) {
+	public void regx(@Comment(name = "value", value = "值") String value, String pattern, @Comment(name = "code", value = "判断失败时的code") int code, @Comment(name = "message", value = "判断失败时的说明") String message) {
 		if (value == null || !Pattern.compile(pattern).matcher(value).matches()) {
 			throw new MagicScriptAssertException(code, message);
 		}
@@ -78,7 +78,7 @@ public class AssertModule implements MagicModule {
 	 * @param message 状态说明
 	 */
 	@Comment("判断值是否为true")
-	public void isTrue(@Comment("值") boolean value, @Comment("判断失败时的code") int code, @Comment("判断失败时的说明") String message) {
+	public void isTrue(@Comment(name = "value", value = "值") boolean value, @Comment(name = "code", value = "判断失败时的code") int code, @Comment(name = "message", value = "判断失败时的说明") String message) {
 		if (!value) {
 			throw new MagicScriptAssertException(code, message);
 		}

+ 35 - 36
magic-api/src/main/java/org/ssssssss/magicapi/modules/BoundSql.java

@@ -1,7 +1,6 @@
 package org.ssssssss.magicapi.modules;
 
 import org.ssssssss.magicapi.context.RequestContext;
-import org.ssssssss.magicapi.exception.MagicAPIException;
 import org.ssssssss.magicapi.interceptor.SQLInterceptor;
 import org.ssssssss.magicapi.modules.mybatis.MybatisParser;
 import org.ssssssss.magicapi.modules.mybatis.SqlNode;
@@ -9,16 +8,8 @@ import org.ssssssss.script.MagicScriptContext;
 import org.ssssssss.script.functions.StreamExtension;
 import org.ssssssss.script.parsing.GenericTokenParser;
 import org.ssssssss.script.parsing.ast.literal.BooleanLiteral;
-import org.ssssssss.script.runtime.Variables;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.xml.sax.SAXException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
+import org.ssssssss.script.runtime.RuntimeContext;
+
 import java.util.*;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.function.Supplier;
@@ -43,7 +34,7 @@ public class BoundSql {
 
 	private static final Pattern REPLACE_MULTI_WHITE_LINE = Pattern.compile("(\r?\n(\\s*\r?\n)+)");
 
-	private static final List<String> MYBATIS_TAGS = Arrays.asList("</where>","</if>", "</trim>", "</set>" ,"</foreach>");
+	private static final List<String> MYBATIS_TAGS = Arrays.asList("</where>", "</if>", "</trim>", "</set>", "</foreach>");
 
 	private String sqlOrXml;
 
@@ -55,45 +46,56 @@ public class BoundSql {
 
 	private Map<String, Object> bindParameters;
 
-	public BoundSql(String sqlOrXml, List<Object> parameters, SQLModule sqlModule) {
+	private RuntimeContext runtimeContext;
+
+	public BoundSql(RuntimeContext runtimeContext, String sqlOrXml, List<Object> parameters, SQLModule sqlModule) {
 		this.sqlOrXml = sqlOrXml;
 		this.parameters = parameters;
 		this.sqlModule = sqlModule;
+		this.runtimeContext = runtimeContext;
 	}
 
-	public BoundSql(String sqlOrXml, Map<String,Object> parameters, SQLModule sqlModule) {
+	public BoundSql(RuntimeContext runtimeContext, String sqlOrXml, Map<String, Object> parameters, SQLModule sqlModule) {
 		this.sqlOrXml = sqlOrXml;
 		this.bindParameters = parameters;
 		this.sqlModule = sqlModule;
+		this.runtimeContext = runtimeContext;
 		this.init();
 	}
 
-	private BoundSql(String sqlOrXml) {
+	private BoundSql(RuntimeContext runtimeContext, String sqlOrXml) {
 		this.sqlOrXml = sqlOrXml;
+		this.runtimeContext = runtimeContext;
 		this.init();
 	}
 
-	private void init(){
+	BoundSql(RuntimeContext runtimeContext, String sql, SQLModule sqlModule) {
+		this(runtimeContext, sql);
+		this.sqlModule = sqlModule;
+	}
+
+	private BoundSql() {
+
+	}
+
+	private void init() {
 		Map<String, Object> varMap = new HashMap<>();
-		MagicScriptContext context = MagicScriptContext.get();
-		if(this.bindParameters != null){
+		if (this.bindParameters != null) {
 			varMap.putAll(this.bindParameters);
-		}else{
-			Variables variables = Variables.get();
-			if(variables != null){
-				varMap.putAll(variables.getVariables(context));
-			}
+		} else {
+			varMap.putAll(runtimeContext.getVarMap());
 		}
-		if(MYBATIS_TAGS.stream().anyMatch(it -> this.sqlOrXml.contains(it))){
+		if (MYBATIS_TAGS.stream().anyMatch(it -> this.sqlOrXml.contains(it))) {
 			SqlNode sqlNode = MybatisParser.parse(this.sqlOrXml);
 			this.sqlOrXml = sqlNode.getSql(varMap);
 			this.parameters = sqlNode.getParameters();
-		}else{
-			normal(context, varMap);
+		} else {
+			normal(runtimeContext, varMap);
 		}
 	}
 
-	private void normal(MagicScriptContext context, Map<String, Object> varMap){
+	private void normal(RuntimeContext runtimeContext, Map<String, Object> varMap) {
+		MagicScriptContext context = runtimeContext.getScriptContext();
 		// 处理?{}参数
 		this.sqlOrXml = IF_TOKEN_PARSER.parse(this.sqlOrXml.trim(), text -> {
 			AtomicBoolean ifTrue = new AtomicBoolean(false);
@@ -125,15 +127,6 @@ public class BoundSql {
 		this.sqlOrXml = this.sqlOrXml == null ? null : REPLACE_MULTI_WHITE_LINE.matcher(this.sqlOrXml.trim()).replaceAll("\r\n");
 	}
 
-	BoundSql(String sql, SQLModule sqlModule) {
-		this(sql);
-		this.sqlModule = sqlModule;
-	}
-
-	private BoundSql() {
-
-	}
-
 	public SQLModule getSqlModule() {
 		return sqlModule;
 	}
@@ -145,6 +138,7 @@ public class BoundSql {
 		boundSql.sqlOrXml = newSqlOrXml;
 		boundSql.excludeColumns = this.excludeColumns;
 		boundSql.sqlModule = this.sqlModule;
+		boundSql.runtimeContext = this.runtimeContext;
 		return boundSql;
 	}
 
@@ -191,6 +185,11 @@ public class BoundSql {
 		this.parameters = parameters;
 	}
 
+
+	public RuntimeContext getRuntimeContext() {
+		return runtimeContext;
+	}
+
 	/**
 	 * 获取缓存值
 	 */

+ 3 - 2
magic-api/src/main/java/org/ssssssss/magicapi/modules/EnvModule.java

@@ -23,12 +23,13 @@ public class EnvModule implements MagicModule {
 	}
 
 	@Comment("获取配置")
-	public String get(@Comment("配置项") String key) {
+	public String get(@Comment(name = "key", value = "配置项") String key) {
 		return environment.getProperty(key);
 	}
 
 	@Comment("获取配置")
-	public String get(@Comment("配置项") String key, @Comment("未配置时的默认值") String defaultValue) {
+	public String get(@Comment(name = "key", value = "配置项") String key,
+					  @Comment(name = "defaultValue", value = "未配置时的默认值") String defaultValue) {
 		return environment.getProperty(key, defaultValue);
 	}
 }

+ 15 - 12
magic-api/src/main/java/org/ssssssss/magicapi/modules/HttpModule.java

@@ -47,12 +47,13 @@ public class HttpModule implements MagicModule {
 	}
 
 	@Comment("创建连接")
-	public HttpModule connect(@Comment("目标URL") String url) {
+	public HttpModule connect(@Comment(name = "url", value = "目标URL") String url) {
 		return new HttpModule(template, url);
 	}
 
 	@Comment("设置URL参数")
-	public HttpModule param(@Comment("参数名") String key, @Comment("参数值") Object... values) {
+	public HttpModule param(@Comment(name = "key", value = "参数名") String key,
+							@Comment(name = "values", value = "参数值") Object... values) {
 		if (values != null) {
 			for (Object value : values) {
 				this.params.add(key, value);
@@ -62,13 +63,14 @@ public class HttpModule implements MagicModule {
 	}
 
 	@Comment("批量设置URL参数")
-	public HttpModule param(@Comment("参数值") Map<String, Object> values) {
+	public HttpModule param(@Comment(name = "values", value = "参数值") Map<String, Object> values) {
 		values.forEach((key, value) -> param(key, Objects.toString(value, "")));
 		return this;
 	}
 
 	@Comment("设置form参数")
-	public HttpModule data(@Comment("参数名") String key, @Comment("参数值") Object... values) {
+	public HttpModule data(@Comment(name = "key", value = "参数名") String key,
+						   @Comment(name = "values", value = "参数值") Object... values) {
 		if (values != null) {
 			for (Object value : values) {
 				this.data.add(key, value);
@@ -78,19 +80,20 @@ public class HttpModule implements MagicModule {
 	}
 
 	@Comment("批量设置form参数")
-	public HttpModule data(@Comment("参数值") Map<String, Object> values) {
+	public HttpModule data(@Comment(name = "values", value = "参数值") Map<String, Object> values) {
 		values.forEach((key, value) -> data(key, Objects.toString(value, "")));
 		return this;
 	}
 
 	@Comment("设置header")
-	public HttpModule header(@Comment("header名") String key, @Comment("header值") String value) {
+	public HttpModule header(@Comment(name = "key", value = "header名") String key,
+							 @Comment(name = "value", value = "header值") String value) {
 		httpHeaders.add(key, value);
 		return this;
 	}
 
 	@Comment("批量设置header")
-	public HttpModule header(@Comment("header值") Map<String, Object> values) {
+	public HttpModule header(@Comment(name = "values", value = "header值") Map<String, Object> values) {
 		values.entrySet()
 				.stream()
 				.filter(it -> it.getValue() != null)
@@ -99,31 +102,31 @@ public class HttpModule implements MagicModule {
 	}
 
 	@Comment("设置请求方法,默认GET")
-	public HttpModule method(@Comment("请求方法") HttpMethod method) {
+	public HttpModule method(@Comment(name = "method", value = "请求方法") HttpMethod method) {
 		this.method = method;
 		return this;
 	}
 
 	@Comment("设置`RequestBody`")
-	public HttpModule body(@Comment("`RequestBody`") Object requestBody) {
+	public HttpModule body(@Comment(name = "requestBody", value = "`RequestBody`") Object requestBody) {
 		this.requestBody = requestBody;
 		this.contentType(MediaType.APPLICATION_JSON);
 		return this;
 	}
 
 	@Comment("自定义`HttpEntity`")
-	public HttpModule entity(@Comment("`HttpEntity`") HttpEntity<Object> entity) {
+	public HttpModule entity(@Comment(name = "entity", value = "`HttpEntity`") HttpEntity<Object> entity) {
 		this.entity = entity;
 		return this;
 	}
 
 	@Comment("设置`ContentType`")
-	public HttpModule contentType(@Comment("Content-Type值") String contentType) {
+	public HttpModule contentType(@Comment(name = "contentType", value = "Content-Type值") String contentType) {
 		return contentType(MediaType.parseMediaType(contentType));
 	}
 
 	@Comment("设置`ContentType`")
-	public HttpModule contentType(@Comment("Content-Type值") MediaType mediaType) {
+	public HttpModule contentType(@Comment(name = "mediaType", value = "Content-Type值") MediaType mediaType) {
 		this.httpHeaders.setContentType(mediaType);
 		return this;
 	}

+ 22 - 9
magic-api/src/main/java/org/ssssssss/magicapi/modules/MongoCollectionExtension.java

@@ -19,32 +19,42 @@ import java.util.stream.Collectors;
 public class MongoCollectionExtension {
 
 	@Comment("执行批量插入操作")
-	public void insert(MongoCollection<Document> collection, @Comment("要插入的集合") List<Map<String, Object>> maps) {
+	public void insert(MongoCollection<Document> collection,
+					   @Comment(name = "maps", value = "要插入的集合") List<Map<String, Object>> maps) {
 		collection.insertMany(maps.stream().map(Document::new).collect(Collectors.toList()));
 	}
 
 	@Comment("执行单条插入操作")
-	public void insert(MongoCollection<Document> collection, @Comment("执行插入数据") Map<String, Object> map) {
+	public void insert(MongoCollection<Document> collection,
+					   @Comment(name = "map", value = "执行插入数据") Map<String, Object> map) {
 		insert(collection, Collections.singletonList(map));
 	}
 
 	@Comment("执行查询操作")
-	public FindIterable<Document> find(MongoCollection<Document> collection, @Comment("查询条件") Map<String, Object> query) {
+	public FindIterable<Document> find(MongoCollection<Document> collection,
+									   @Comment(name = "query", value = "查询条件") Map<String, Object> query) {
 		return collection.find(new Document(query));
 	}
 
 	@Comment("修改操作,返回修改数量")
-	public long update(MongoCollection<Document> collection, @Comment("查询条件") Map<String, Object> query, @Comment("修改值") Map<String, Object> update) {
+	public long update(MongoCollection<Document> collection,
+					   @Comment(name = "query", value = "查询条件") Map<String, Object> query,
+					   @Comment(name = "update", value = "修改值") Map<String, Object> update) {
 		return collection.updateOne(new Document(query), new Document(update)).getModifiedCount();
 	}
 
 	@Comment("批量修改,返回修改数量")
-	public long updateMany(MongoCollection<Document> collection, @Comment("修改条件") Map<String, Object> query, @Comment("修改值") Map<String, Object> update) {
+	public long updateMany(MongoCollection<Document> collection,
+						   @Comment(name = "query", value = "修改条件") Map<String, Object> query,
+						   @Comment(name = "update", value = "修改值") Map<String, Object> update) {
 		return collection.updateMany(new Document(query), new Document(update)).getModifiedCount();
 	}
 
 	@Comment("批量修改,返回修改数量")
-	public long updateMany(MongoCollection<Document> collection, @Comment("查询条件") Map<String, Object> query, @Comment("修改值") Map<String, Object> update, Map<String, Object> filters) {
+	public long updateMany(MongoCollection<Document> collection,
+						   @Comment(name = "query", value = "查询条件") Map<String, Object> query,
+						   @Comment(name = "update", value = "修改值") Map<String, Object> update,
+						   @Comment(name = "filters", value = "过滤条件") Map<String, Object> filters) {
 		UpdateOptions updateOptions = new UpdateOptions();
 		if (filters != null && !filters.isEmpty()) {
 			Object upsert = filters.get("upsert");
@@ -64,17 +74,20 @@ public class MongoCollectionExtension {
 	}
 
 	@Comment("查询数量")
-	public long count(MongoCollection<Document> collection, @Comment("查询") Map<String, Object> query) {
+	public long count(MongoCollection<Document> collection,
+					  @Comment(name = "query", value = "查询") Map<String, Object> query) {
 		return collection.countDocuments(new Document(query));
 	}
 
 	@Comment("批量删除,返回删除条数")
-	public long remove(MongoCollection<Document> collection, @Comment("删除条件") Map<String, Object> query) {
+	public long remove(MongoCollection<Document> collection,
+					   @Comment(name = "query", value = "删除条件") Map<String, Object> query) {
 		return collection.deleteMany(new Document(query)).getDeletedCount();
 	}
 
 	@Comment("删除一条,返回删除条数")
-	public long removeOne(MongoCollection<Document> collection, @Comment("删除条件") Map<String, Object> query) {
+	public long removeOne(MongoCollection<Document> collection,
+						  @Comment(name = "query", value = "删除条件") Map<String, Object> query) {
 		return collection.deleteOne(new Document(query)).getDeletedCount();
 	}
 }

+ 4 - 4
magic-api/src/main/java/org/ssssssss/magicapi/modules/RequestModule.java

@@ -31,7 +31,7 @@ public class RequestModule {
 	 * @param name 参数名
 	 */
 	@Comment("获取文件")
-	public static MultipartFile getFile(@Comment("参数名") String name) {
+	public static MultipartFile getFile(@Comment(name = "name", value = "参数名") String name) {
 		MultipartRequest request = getMultipartHttpServletRequest();
 		if (request == null) {
 			return null;
@@ -46,7 +46,7 @@ public class RequestModule {
 	 * @param name 参数名
 	 */
 	@Comment("获取多个文件")
-	public static List<MultipartFile> getFiles(@Comment("参数名") String name) {
+	public static List<MultipartFile> getFiles(@Comment(name = "name", value = "参数名") String name) {
 		MultipartRequest request = getMultipartHttpServletRequest();
 		if (request == null) {
 			return null;
@@ -75,7 +75,7 @@ public class RequestModule {
 	 * @param name 参数名
 	 */
 	@Comment("根据请求参数名获取值")
-	public List<String> getValues(@Comment("参数名") String name) {
+	public List<String> getValues(@Comment(name = "name", value = "参数名") String name) {
 		HttpServletRequest request = get();
 		if (request != null) {
 			String[] values = request.getParameterValues(name);
@@ -90,7 +90,7 @@ public class RequestModule {
 	 * @param name 参数名
 	 */
 	@Comment("根据header名获取值")
-	public List<String> getHeaders(@Comment("header名") String name) {
+	public List<String> getHeaders(@Comment(name = "name", value = "header名") String name) {
 		HttpServletRequest request = get();
 		if (request != null) {
 			Enumeration<String> headers = request.getHeaders(name);

+ 20 - 12
magic-api/src/main/java/org/ssssssss/magicapi/modules/ResponseModule.java

@@ -41,7 +41,8 @@ public class ResponseModule {
 	 * @param filename 文件名
 	 */
 	@Comment("文件下载")
-	public static ResponseEntity<?> download(@Comment("文件内容,如`byte[]`") Object value, @Comment("文件名") String filename) throws UnsupportedEncodingException {
+	public static ResponseEntity<?> download(@Comment(name = "value", value = "文件内容,如`byte[]`") Object value,
+											 @Comment(name = "filename", value = "文件名") String filename) throws UnsupportedEncodingException {
 		return ResponseEntity.ok().contentType(MediaType.APPLICATION_OCTET_STREAM)
 				.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + URLEncoder.encode(filename, "UTF-8"))
 				.body(value);
@@ -54,7 +55,8 @@ public class ResponseModule {
 	 * @param values 数据内容
 	 */
 	@Comment("返回自定义分页结果")
-	public Object page(@Comment("总条数") long total, @Comment("当前结果集") List<Map<String, Object>> values) {
+	public Object page(@Comment(name = "total", value = "总条数") long total,
+					   @Comment(name = "values", value = "当前结果集") List<Map<String, Object>> values) {
 		return resultProvider.buildPageResult(RequestContext.getRequestEntity(), null, total, values);
 	}
 
@@ -64,7 +66,7 @@ public class ResponseModule {
 	 * @param value json内容
 	 */
 	@Comment("自定义返回json内容")
-	public ResponseEntity<Object> json(@Comment("返回对象") Object value) {
+	public ResponseEntity<Object> json(@Comment(name = "value", value = "返回对象") Object value) {
 		return ResponseEntity.ok(value);
 	}
 
@@ -72,7 +74,8 @@ public class ResponseModule {
 	 * 添加Header
 	 */
 	@Comment("添加response header")
-	public ResponseModule addHeader(@Comment("header名") String key, @Comment("header值") String value) {
+	public ResponseModule addHeader(@Comment(name = "key", value = "header名") String key,
+									@Comment(name = "value", value = "header值") String value) {
 		if (StringUtils.isNotBlank(key)) {
 			HttpServletResponse response = getResponse();
 			if (response != null) {
@@ -86,7 +89,8 @@ public class ResponseModule {
 	 * 设置header
 	 */
 	@Comment("设置response header")
-	public ResponseModule setHeader(@Comment("header名") String key, @Comment("header值") String value) {
+	public ResponseModule setHeader(@Comment(name = "key", value = "header名") String key,
+									@Comment(name = "value", value = "header值") String value) {
 		if (StringUtils.isNotBlank(key)) {
 			HttpServletResponse response = getResponse();
 			if (response != null) {
@@ -100,7 +104,8 @@ public class ResponseModule {
 	 * 添加cookie
 	 */
 	@Comment("添加Cookie")
-	public ResponseModule addCookie(@Comment("cookie名") String name, @Comment("cookie值") String value) {
+	public ResponseModule addCookie(@Comment(name = "name", value = "cookie名") String name,
+									@Comment(name = "value", value = "cookie值") String value) {
 		if (StringUtils.isNotBlank(name)) {
 			addCookie(new Cookie(name, value));
 		}
@@ -111,7 +116,8 @@ public class ResponseModule {
 	 * 批量添加cookie
 	 */
 	@Comment("批量添加Cookie")
-	public ResponseModule addCookies(@Comment("Cookies") Map<String, String> cookies, @Comment("Cookie选项,如`path`、`httpOnly`、`domain`、`maxAge`") Map<String, Object> options) {
+	public ResponseModule addCookies(@Comment(name = "cookies", value = "Cookies") Map<String, String> cookies,
+									 @Comment(name = "options", value = "Cookie选项,如`path`、`httpOnly`、`domain`、`maxAge`") Map<String, Object> options) {
 		if (cookies != null) {
 			for (Map.Entry<String, String> entry : cookies.entrySet()) {
 				addCookie(entry.getKey(), entry.getValue(), options);
@@ -124,7 +130,7 @@ public class ResponseModule {
 	 * 批量添加cookie
 	 */
 	@Comment("批量添加Cookie")
-	public ResponseModule addCookies(@Comment("Cookies") Map<String, String> cookies) {
+	public ResponseModule addCookies(@Comment(name = "cookies", value = "Cookies") Map<String, String> cookies) {
 		return addCookies(cookies, null);
 
 	}
@@ -144,8 +150,9 @@ public class ResponseModule {
 	 * 添加cookie
 	 */
 	@Comment("添加Cookie")
-	public ResponseModule addCookie(@Comment("Cookie名") String name, @Comment("Cookie值") String value,
-									@Comment("Cookie选项,如`path`、`httpOnly`、`domain`、`maxAge`") Map<String, Object> options) {
+	public ResponseModule addCookie(@Comment(name = "name", value = "Cookie名") String name,
+									@Comment(name = "value", value = "Cookie值") String value,
+									@Comment(name = "options", value = "Cookie选项,如`path`、`httpOnly`、`domain`、`maxAge`") Map<String, Object> options) {
 		if (StringUtils.isNotBlank(name)) {
 			Cookie cookie = new Cookie(name, value);
 			if (options != null) {
@@ -181,7 +188,7 @@ public class ResponseModule {
 	 * 添加cookie
 	 */
 	@Comment("添加Cookie")
-	public ResponseModule addCookie(@Comment("Cookie对象") Cookie cookie) {
+	public ResponseModule addCookie(@Comment(name = "cookie", value = "Cookie对象") Cookie cookie) {
 		if (cookie != null) {
 			HttpServletResponse response = getResponse();
 			if (response != null) {
@@ -206,7 +213,8 @@ public class ResponseModule {
 	 * @param mime  图片类型,image/png,image/jpeg,image/gif
 	 */
 	@Comment("输出图片")
-	public ResponseEntity image(@Comment("图片内容,如`byte[]`") Object value, @Comment("图片类型,如`image/png`、`image/jpeg`、`image/gif`") String mime) {
+	public ResponseEntity image(@Comment(name = "value", value = "图片内容,如`byte[]`") Object value,
+								@Comment(name = "mime", value = "图片类型,如`image/png`、`image/jpeg`、`image/gif`") String mime) {
 		return ResponseEntity.ok().header(HttpHeaders.CONTENT_TYPE, mime).body(value);
 	}
 

+ 91 - 55
magic-api/src/main/java/org/ssssssss/magicapi/modules/SQLModule.java

@@ -1,8 +1,6 @@
 package org.ssssssss.magicapi.modules;
 
 import org.apache.commons.lang3.StringUtils;
-import org.springframework.dao.DataRetrievalFailureException;
-import org.springframework.dao.InvalidDataAccessApiUsageException;
 import org.springframework.jdbc.core.ArgumentPreparedStatementSetter;
 import org.springframework.jdbc.core.RowMapper;
 import org.springframework.jdbc.core.SqlParameterValue;
@@ -23,11 +21,11 @@ import org.ssssssss.magicapi.modules.table.NamedTable;
 import org.ssssssss.magicapi.provider.PageProvider;
 import org.ssssssss.magicapi.provider.ResultProvider;
 import org.ssssssss.magicapi.script.ScriptManager;
-import org.ssssssss.script.MagicScriptContext;
 import org.ssssssss.script.annotation.Comment;
 import org.ssssssss.script.annotation.UnableCall;
 import org.ssssssss.script.parsing.ast.statement.ClassConverter;
 import org.ssssssss.script.reflection.JavaReflection;
+import org.ssssssss.script.runtime.RuntimeContext;
 
 import java.lang.reflect.Field;
 import java.sql.*;
@@ -212,7 +210,7 @@ public class SQLModule extends HashMap<String, SQLModule> implements MagicModule
 	 * @param function 回调函数
 	 */
 	@Comment("开启事务,并在回调中处理")
-	public Object transaction(@Comment("回调函数,如:()=>{....}") Function<?, ?> function) {
+	public Object transaction(@Comment(name = "function", value = "回调函数,如:()=>{....}") Function<?, ?> function) {
 		// 创建事务
 		Transaction transaction = transaction();
 		try {
@@ -240,7 +238,7 @@ public class SQLModule extends HashMap<String, SQLModule> implements MagicModule
 	 * @param ttl       过期时间
 	 */
 	@Comment("使用缓存")
-	public SQLModule cache(@Comment("缓存名") String cacheName, @Comment("过期时间") long ttl) {
+	public SQLModule cache(@Comment(name = "cacheName", value = "缓存名") String cacheName, @Comment(name = "ttl", value = "过期时间") long ttl) {
 		if (cacheName == null) {
 			return this;
 		}
@@ -256,7 +254,7 @@ public class SQLModule extends HashMap<String, SQLModule> implements MagicModule
 	 * @param cacheName 缓冲名
 	 */
 	@Comment("使用缓存,过期时间采用默认配置")
-	public SQLModule cache(@Comment("缓存名") String cacheName) {
+	public SQLModule cache(@Comment(name = "cacheName", value = "缓存名") String cacheName) {
 		return cache(cacheName, 0);
 	}
 
@@ -312,16 +310,19 @@ public class SQLModule extends HashMap<String, SQLModule> implements MagicModule
 	 * 查询List
 	 */
 	@Comment("查询SQL,返回List类型结果")
-	public List<Map<String, Object>> select(@Comment("`SQL`语句或`xml`") String sqlOrXml) {
-		return select(sqlOrXml, null);
+	public List<Map<String, Object>> select(RuntimeContext runtimeContext,
+											@Comment(name = "sqlOrXml", value = "`SQL`语句或`xml`") String sqlOrXml) {
+		return select(runtimeContext, sqlOrXml, null);
 	}
 
 	/**
 	 * 查询List,并传入变量信息
 	 */
 	@Comment("查询SQL,并传入变量信息,返回List类型结果")
-	public List<Map<String, Object>> select(@Comment("`SQL`语句或`xml`") String sqlOrXml, @Comment("变量信息") Map<String, Object> params) {
-		return select(new BoundSql(sqlOrXml, params, this));
+	public List<Map<String, Object>> select(RuntimeContext runtimeContext,
+											@Comment(name = "sqlOrXml", value = "`SQL`语句或`xml`") String sqlOrXml,
+											@Comment(name = "params", value = "变量信息") Map<String, Object> params) {
+		return select(new BoundSql(runtimeContext, sqlOrXml, params, this));
 	}
 
 	@UnableCall
@@ -348,16 +349,19 @@ public class SQLModule extends HashMap<String, SQLModule> implements MagicModule
 	 * 执行update
 	 */
 	@Comment("执行update操作,返回受影响行数")
-	public int update(@Comment("`SQL`语句或`xml`") String sqlOrXml) {
-		return update(sqlOrXml, null);
+	public int update(RuntimeContext runtimeContext,
+					  @Comment(name = "sqlOrXml", value = "`SQL`语句或`xml`") String sqlOrXml) {
+		return update(runtimeContext, sqlOrXml, null);
 	}
 
 	/**
 	 * 执行update,并传入变量信息
 	 */
 	@Comment("执行update操作,并传入变量信息,返回受影响行数")
-	public int update(@Comment("`SQL`语句或`xml`") String sqlOrXml, @Comment("变量信息") Map<String, Object> params) {
-		return update(new BoundSql(sqlOrXml, params, this));
+	public int update(RuntimeContext runtimeContext,
+					  @Comment(name = "sqlOrXml", value = "`SQL`语句或`xml`") String sqlOrXml,
+					  @Comment(name = "params", value = "变量信息") Map<String, Object> params) {
+		return update(new BoundSql(runtimeContext, sqlOrXml, params, this));
 	}
 
 	@UnableCall
@@ -375,17 +379,20 @@ public class SQLModule extends HashMap<String, SQLModule> implements MagicModule
 	 * 插入并返回主键
 	 */
 	@Comment("执行insert操作,返回插入主键")
-	public Object insert(@Comment("`SQL`语句或`xml`") String sqlOrXml) {
-		return insert(sqlOrXml, (Map<String, Object>) null);
+	public Object insert(RuntimeContext runtimeContext,
+						 @Comment(name = "sqlOrXml", value = "`SQL`语句或`xml`") String sqlOrXml) {
+		return insert(runtimeContext, sqlOrXml, (Map<String, Object>) null);
 	}
 
 	/**
 	 * 插入并返回主键,并传入变量信息
 	 */
 	@Comment("执行insert操作,并传入变量信息,返回插入主键")
-	public Object insert(@Comment("`SQL`语句或`xml`") String sqlOrXml, @Comment("变量信息")Map<String, Object> params) {
+	public Object insert(RuntimeContext runtimeContext,
+						 @Comment(name = "sqlOrXml", value = "`SQL`语句或`xml`") String sqlOrXml,
+						 @Comment(name = "params", value = "变量信息") Map<String, Object> params) {
 		MagicKeyHolder magicKeyHolder = new MagicKeyHolder();
-		insert(new BoundSql(sqlOrXml, params,this), magicKeyHolder);
+		insert(new BoundSql(runtimeContext, sqlOrXml, params, this), magicKeyHolder);
 		return magicKeyHolder.getObjectKey();
 	}
 
@@ -393,16 +400,21 @@ public class SQLModule extends HashMap<String, SQLModule> implements MagicModule
 	 * 插入并返回主键
 	 */
 	@Comment("执行insert操作,返回插入主键")
-	public Object insert(@Comment("`SQL`语句或`xml`") String sqlOrXml, @Comment("主键列") String primary) {
-		return insert(sqlOrXml, primary, null);
+	public Object insert(RuntimeContext runtimeContext,
+						 @Comment(name = "sqlOrXml", value = "`SQL`语句或`xml`") String sqlOrXml,
+						 @Comment(name = "primary", value = "主键列") String primary) {
+		return insert(runtimeContext, sqlOrXml, primary, null);
 	}
 
 	/**
 	 * 插入并返回主键
 	 */
 	@Comment("执行insert操作,并传入主键和变量信息,返回插入主键")
-	public Object insert(@Comment("`SQL`语句或`xml`") String sqlOrXml, @Comment("主键列") String primary, @Comment("变量信息")Map<String, Object> params) {
-		return insert(new BoundSql(sqlOrXml, params, this), primary);
+	public Object insert(RuntimeContext runtimeContext,
+						 @Comment(name = "sqlOrXml", value = "`SQL`语句或`xml`") String sqlOrXml,
+						 @Comment(name = "primary", value = "主键列") String primary,
+						 @Comment(name = "params", value = "变量信息") Map<String, Object> params) {
+		return insert(new BoundSql(runtimeContext, sqlOrXml, params, this), primary);
 	}
 
 	void insert(BoundSql boundSql, MagicKeyHolder keyHolder) {
@@ -422,7 +434,7 @@ public class SQLModule extends HashMap<String, SQLModule> implements MagicModule
 	 * 插入并返回主键
 	 */
 	@Comment("批量执行insert操作,返回插入主键数组")
-	public int[] batchInsert(@Comment("`SQL`语句") String sql, @Comment("参数") List<Object[]> list) {
+	public int[] batchInsert(@Comment(name = "sql", value = "`SQL`语句") String sql, @Comment(name = "list", value = "参数") List<Object[]> list) {
 		assertDatasourceNotNull();
 		return dataSourceNode.getJdbcTemplate().batchUpdate(sql, list);
 	}
@@ -431,7 +443,7 @@ public class SQLModule extends HashMap<String, SQLModule> implements MagicModule
 	 * 插入并返回主键
 	 */
 	@Comment("批量执行insert操作,返回插入主键数组")
-	public int[] batchInsert(@Comment("`SQL`语句") String[] sqls) {
+	public int[] batchInsert(@Comment(name = "sqls", value = "`SQL`语句") String[] sqls) {
 		assertDatasourceNotNull();
 		return dataSourceNode.getJdbcTemplate().batchUpdate(sqls);
 	}
@@ -447,38 +459,48 @@ public class SQLModule extends HashMap<String, SQLModule> implements MagicModule
 	 * 分页查询
 	 */
 	@Comment("执行分页查询,分页条件自动获取")
-	public Object page(@Comment("`SQL`语句或`xml`") String sqlOrXml, @Comment("变量信息")Map<String, Object> params) {
-		return page(new BoundSql(sqlOrXml, params, this));
+	public Object page(RuntimeContext runtimeContext,
+					   @Comment(name = "sqlOrXml", value = "`SQL`语句或`xml`") String sqlOrXml,
+					   @Comment(name = "params", value = "变量信息") Map<String, Object> params) {
+		return page(new BoundSql(runtimeContext, sqlOrXml, params, this));
 	}
 
 	/**
 	 * 分页查询,并传入变量信息
 	 */
 	@Comment("执行分页查询,并传入变量信息,分页条件自动获取")
-	public Object page(@Comment("`SQL`语句或`xml`") String sqlOrXml) {
-		return page(sqlOrXml, (Map<String, Object>) null);
+	public Object page(RuntimeContext runtimeContext,
+					   @Comment(name = "sqlOrXml", value = "`SQL`语句或`xml`") String sqlOrXml) {
+		return page(runtimeContext, sqlOrXml, (Map<String, Object>) null);
 	}
 
 	/**
 	 * 分页查询(手动传入limit和offset参数)
 	 */
 	@Comment("执行分页查询,分页条件手动传入")
-	public Object page(@Comment("`SQL`语句或`xml`") String sqlOrXml, @Comment("限制条数") long limit, @Comment("跳过条数") long offset) {
-		return page(sqlOrXml, limit, offset, null);
+	public Object page(RuntimeContext runtimeContext,
+					   @Comment(name = "sqlOrXml", value = "`SQL`语句或`xml`") String sqlOrXml,
+					   @Comment(name = "limit", value = "限制条数") long limit,
+					   @Comment(name = "limit", value = "跳过条数") long offset) {
+		return page(runtimeContext, sqlOrXml, limit, offset, null);
 	}
 
 	/**
 	 * 分页查询(手动传入limit和offset参数)
 	 */
 	@Comment("执行分页查询,并传入变量信息,分页条件手动传入")
-	public Object page(@Comment("`SQL`语句或`xml`") String sqlOrXml, @Comment("限制条数") long limit, @Comment("跳过条数") long offset, @Comment("变量信息")Map<String, Object> params) {
-		BoundSql boundSql = new BoundSql(sqlOrXml, params, this);
+	public Object page(RuntimeContext runtimeContext,
+					   @Comment(name = "sqlOrXml", value = "`SQL`语句或`xml`") String sqlOrXml,
+					   @Comment(name = "limit", value = "限制条数") long limit,
+					   @Comment(name = "offset", value = "跳过条数") long offset,
+					   @Comment(name = "params", value = "变量信息") Map<String, Object> params) {
+		BoundSql boundSql = new BoundSql(runtimeContext, sqlOrXml, params, this);
 		return page(boundSql, new Page(limit, offset));
 	}
 
 	@UnableCall
 	public Object page(BoundSql boundSql) {
-		Page page = pageProvider.getPage(MagicScriptContext.get());
+		Page page = pageProvider.getPage(boundSql.getRuntimeContext());
 		return page(boundSql, page);
 	}
 
@@ -491,25 +513,30 @@ public class SQLModule extends HashMap<String, SQLModule> implements MagicModule
 	 * 分页查询(手动传入分页SQL语句)
 	 */
 	@Comment("执行分页查询,分页`SQL`语句手动传入")
-	public Object page(@Comment("count语句") String countSqlOrXml, @Comment("查询语句") String sqlOrXml){
-		return page(countSqlOrXml, sqlOrXml, null);
+	public Object page(RuntimeContext runtimeContext,
+					   @Comment(name = "countSqlOrXml", value = "count语句") String countSqlOrXml,
+					   @Comment(name = "sqlOrXml", value = "查询语句") String sqlOrXml) {
+		return page(runtimeContext, countSqlOrXml, sqlOrXml, null);
 	}
 
 	/**
 	 * 分页查询(手动传入分页SQL语句)
 	 */
 	@Comment("执行分页查询,并传入变量信息,分页`SQL`countSqlOrXml")
-	public Object page(@Comment("count语句")String countSqlOrXml, @Comment("查询语句")String sqlOrXml, @Comment("变量信息") Map<String, Object> params){
-		int count = selectInt(new BoundSql(countSqlOrXml, params, this));
-		Page page = pageProvider.getPage(MagicScriptContext.get());
-		BoundSql boundSql = new BoundSql(sqlOrXml, params, this);
+	public Object page(RuntimeContext runtimeContext,
+					   @Comment(name = "countSqlOrXml", value = "count语句") String countSqlOrXml,
+					   @Comment(name = "sqlOrXml", value = "查询语句") String sqlOrXml,
+					   @Comment(name = "params", value = "变量信息") Map<String, Object> params) {
+		int count = selectInt(new BoundSql(runtimeContext, countSqlOrXml, params, this));
+		Page page = pageProvider.getPage(runtimeContext);
+		BoundSql boundSql = new BoundSql(runtimeContext, sqlOrXml, params, this);
 		return page(count, boundSql, page, null);
 	}
 
 	private Object page(int count, BoundSql boundSql, Page page, Dialect dialect) {
 		List<Map<String, Object>> list = null;
-		if(count > 0){
-			if(dialect == null){
+		if (count > 0) {
+			if (dialect == null) {
 				dialect = dataSourceNode.getDialect(dialectAdapter);
 			}
 			BoundSql pageBoundSql = buildPageBoundSql(dialect, boundSql, page.getOffset(), page.getLimit());
@@ -532,16 +559,19 @@ public class SQLModule extends HashMap<String, SQLModule> implements MagicModule
 	 * 查询int值
 	 */
 	@Comment("查询int值,适合单行单列int的结果")
-	public Integer selectInt(@Comment("`SQL`语句或`xml`") String sqlOrXml) {
-		return selectInt(sqlOrXml, null);
+	public Integer selectInt(RuntimeContext runtimeContext,
+							 @Comment(name = "sqlOrXml", value = "`SQL`语句或`xml`") String sqlOrXml) {
+		return selectInt(runtimeContext, sqlOrXml, null);
 	}
 
 	/**
 	 * 查询int值
 	 */
 	@Comment("查询int值,并传入变量信息,适合单行单列int的结果")
-	public Integer selectInt(@Comment("`SQL`语句或`xml`") String sqlOrXml, @Comment("变量信息") Map<String, Object> params) {
-		return selectInt(new BoundSql(sqlOrXml, params, this));
+	public Integer selectInt(RuntimeContext runtimeContext,
+							 @Comment(name = "sqlOrXml", value = "`SQL`语句或`xml`") String sqlOrXml,
+							 @Comment(name = "params", value = "变量信息") Map<String, Object> params) {
+		return selectInt(new BoundSql(runtimeContext, sqlOrXml, params, this));
 	}
 
 	@UnableCall
@@ -554,16 +584,19 @@ public class SQLModule extends HashMap<String, SQLModule> implements MagicModule
 	 * 查询Map
 	 */
 	@Comment("查询单条结果,查不到返回null")
-	public Map<String, Object> selectOne(@Comment("`SQL`语句或`xml`") String sqlOrXml) {
-		return selectOne(sqlOrXml, null);
+	public Map<String, Object> selectOne(RuntimeContext runtimeContext,
+										 @Comment(name = "sqlOrXml", value = "`SQL`语句或`xml`") String sqlOrXml) {
+		return selectOne(runtimeContext, sqlOrXml, null);
 	}
 
 	/**
 	 * 查询Map,并传入变量信息
 	 */
 	@Comment("查询单条结果,并传入变量信息,查不到返回null")
-	public Map<String, Object> selectOne(@Comment("`SQL`语句或`xml`") String sqlOrXml, @Comment("变量信息") Map<String, Object> params) {
-		return selectOne(new BoundSql(sqlOrXml, params, this));
+	public Map<String, Object> selectOne(RuntimeContext runtimeContext,
+										 @Comment(name = "sqlOrXml", value = "`SQL`语句或`xml`") String sqlOrXml,
+										 @Comment(name = "params", value = "变量信息") Map<String, Object> params) {
+		return selectOne(new BoundSql(runtimeContext, sqlOrXml, params, this));
 	}
 
 	@UnableCall
@@ -582,22 +615,25 @@ public class SQLModule extends HashMap<String, SQLModule> implements MagicModule
 	 * 查询单行单列的值
 	 */
 	@Comment("查询单行单列的值")
-	public Object selectValue(@Comment("`SQL`语句或`xml`") String sqlOrXml) {
-		return selectValue(sqlOrXml, null);
+	public Object selectValue(RuntimeContext runtimeContext,
+							  @Comment(name = "sqlOrXml", value = "`SQL`语句或`xml`") String sqlOrXml) {
+		return selectValue(runtimeContext, sqlOrXml, null);
 	}
 
 	/**
 	 * 查询单行单列的值,并传入变量信息
 	 */
 	@Comment("查询单行单列的值,并传入变量信息")
-	public Object selectValue(@Comment("`SQL`语句或`xml`") String sqlOrXml, @Comment("变量信息")Map<String, Object> params) {
+	public Object selectValue(RuntimeContext runtimeContext,
+							  @Comment(name = "sqlOrXml", value = "`SQL`语句或`xml`") String sqlOrXml,
+							  @Comment(name = "params", value = "变量信息") Map<String, Object> params) {
 		assertDatasourceNotNull();
-		BoundSql boundSql = new BoundSql(sqlOrXml, params, this);
+		BoundSql boundSql = new BoundSql(runtimeContext, sqlOrXml, params, this);
 		return boundSql.getCacheValue(this.sqlInterceptors, () -> dataSourceNode.getJdbcTemplate().query(boundSql.getSql(), new SingleRowResultSetExtractor<>(Object.class), boundSql.getParameters()));
 	}
 
 	@Comment("指定table,进行单表操作")
-	public NamedTable table(String tableName) {
+	public NamedTable table(@Comment(name = "tableName", value = "表名") String tableName) {
 		return new NamedTable(tableName, this, rowMapColumnMapper, namedTableInterceptors);
 	}
 
@@ -641,7 +677,7 @@ public class SQLModule extends HashMap<String, SQLModule> implements MagicModule
 			}
 			Iterator<Object> keyIterator = keyList.get(0).values().iterator();
 			Object key = keyIterator.hasNext() ? keyIterator.next() : null;
-			if(key != null && "oracle.sql.ROWID".equals(key.getClass().getName())){
+			if (key != null && "oracle.sql.ROWID".equals(key.getClass().getName())) {
 				return ScriptManager.executeExpression("row.stringValue()", Collections.singletonMap("row", key));
 			}
 			return key;

+ 69 - 58
magic-api/src/main/java/org/ssssssss/magicapi/modules/mybatis/ForeachSqlNode.java

@@ -10,72 +10,83 @@ import java.util.Map;
 
 /**
  * 对应XML中 <foreach>
+ *
  * @author jmxd
  * @version : 2020-05-18
  */
 public class ForeachSqlNode extends SqlNode {
-    /** 数据集合,支持Collection、数组 */
-    private String collection;
-    /** item 变量名 */
-    private String item;
-    /** 拼接起始SQL */
-    private String open;
-    /** 拼接结束SQL */
-    private String close;
-    /** 分隔符 */
-    private String separator;
+	/**
+	 * 数据集合,支持Collection、数组
+	 */
+	private String collection;
+	/**
+	 * item 变量名
+	 */
+	private String item;
+	/**
+	 * 拼接起始SQL
+	 */
+	private String open;
+	/**
+	 * 拼接结束SQL
+	 */
+	private String close;
+	/**
+	 * 分隔符
+	 */
+	private String separator;
 
-    public void setCollection(String collection) {
-        this.collection = collection;
-    }
+	public void setCollection(String collection) {
+		this.collection = collection;
+	}
 
-    public void setItem(String item) {
-        this.item = item;
-    }
+	public void setItem(String item) {
+		this.item = item;
+	}
 
-    public void setOpen(String open) {
-        this.open = open;
-    }
+	public void setOpen(String open) {
+		this.open = open;
+	}
 
-    public void setClose(String close) {
-        this.close = close;
-    }
+	public void setClose(String close) {
+		this.close = close;
+	}
 
-    public void setSeparator(String separator) {
-        this.separator = separator;
-    }
+	public void setSeparator(String separator) {
+		this.separator = separator;
+	}
 
-    @Override
-    public String getSql(Map<String, Object> paramMap, List<Object> parameters) {
-        // 提取集合
-        Object value = ScriptManager.executeExpression(this.collection, paramMap);
-        // 如果集合为空,则过滤该节点
-        if (value == null) {
-            return "";
-        }
-        // 开始拼接SQL,
-        String sql = StringUtils.defaultString(this.open);
-        // 如果集合是Collection对象或其子类,则转成数组
-        if (value instanceof Collection) {
-            value = ((Collection) value).toArray();
-        }
-        // 判断不是数组,则过滤子节点并返回
-        if (!value.getClass().isArray()) {
-            return "";
-        }
-        // 获取数组长度
-        int len = Array.getLength(value);
-        for (int i = 0; i < len; i++) {
-            // 存入item对象
-            paramMap.put(this.item, Array.get(value, i));
-            // 拼接子节点
-            sql += executeChildren(paramMap, parameters);
-            // 拼接分隔符
-            if (i + 1 < len) {
-                sql += StringUtils.defaultString(this.separator);
-            }
-        }
-        // 拼接结束SQL
-        return sql + StringUtils.defaultString(this.close);
-    }
+	@Override
+	public String getSql(Map<String, Object> paramMap, List<Object> parameters) {
+		// 提取集合
+		Object value = ScriptManager.executeExpression(this.collection, paramMap);
+		// 如果集合为空,则过滤该节点
+		if (value == null) {
+			return "";
+		}
+		// 开始拼接SQL,
+		String sql = StringUtils.defaultString(this.open);
+		// 如果集合是Collection对象或其子类,则转成数组
+		if (value instanceof Collection) {
+			value = ((Collection) value).toArray();
+		}
+		// 判断不是数组,则过滤子节点并返回
+		if (!value.getClass().isArray()) {
+			return "";
+		}
+		// 获取数组长度
+		int len = Array.getLength(value);
+		for (int i = 0; i < len; i++) {
+			// 存入item对象
+			paramMap.put(this.item, Array.get(value, i));
+			// 拼接子节点
+			sql += executeChildren(paramMap, parameters);
+			// 拼接分隔符
+			if (i + 1 < len) {
+				sql += StringUtils.defaultString(this.separator);
+			}
+		}
+		// 拼接结束SQL
+		return sql + StringUtils.defaultString(this.close);
+	}
 }

+ 18 - 16
magic-api/src/main/java/org/ssssssss/magicapi/modules/mybatis/IfSqlNode.java

@@ -5,29 +5,31 @@ import org.ssssssss.script.parsing.ast.literal.BooleanLiteral;
 
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 
 /**
  * 对应XML中 <if>
+ *
  * @author jmxd
  * @version : 2020-05-18
  */
 public class IfSqlNode extends SqlNode {
-    /** 判断表达式 */
-    private String test;
+	/**
+	 * 判断表达式
+	 */
+	private String test;
 
-    public IfSqlNode(String test) {
-        this.test = test;
-    }
+	public IfSqlNode(String test) {
+		this.test = test;
+	}
 
-    @Override
-    public String getSql(Map<String, Object> paramMap, List<Object> parameters) {
-        // 执行表达式
-        Object value = ScriptManager.executeExpression(test, paramMap);
-        // 判断表达式返回结果是否是true,如果不是则过滤子节点
-        if (BooleanLiteral.isTrue(value)) {
-            return executeChildren(paramMap, parameters);
-        }
-        return "";
-    }
+	@Override
+	public String getSql(Map<String, Object> paramMap, List<Object> parameters) {
+		// 执行表达式
+		Object value = ScriptManager.executeExpression(test, paramMap);
+		// 判断表达式返回结果是否是true,如果不是则过滤子节点
+		if (BooleanLiteral.isTrue(value)) {
+			return executeChildren(paramMap, parameters);
+		}
+		return "";
+	}
 }

+ 5 - 4
magic-api/src/main/java/org/ssssssss/magicapi/modules/mybatis/SetSqlNode.java

@@ -2,12 +2,13 @@ package org.ssssssss.magicapi.modules.mybatis;
 
 /**
  * 对应XML中 <set>
+ *
  * @author zhangxu
  * @version : 2020-12-05
  */
 public class SetSqlNode extends TrimSqlNode {
-    public SetSqlNode() {
-        this.prefix = "SET";
-        this.suffixOverrides = ",";
-    }
+	public SetSqlNode() {
+		this.prefix = "SET";
+		this.suffixOverrides = ",";
+	}
 }

+ 28 - 25
magic-api/src/main/java/org/ssssssss/magicapi/modules/mybatis/TextSqlNode.java

@@ -9,35 +9,38 @@ import java.util.Objects;
 
 /**
  * 普通SQL节点
+ *
  * @author jmxd
  * @version : 2020-05-18
  */
 public class TextSqlNode extends SqlNode {
-    /** SQL */
-    private String text;
+	/**
+	 * SQL
+	 */
+	private String text;
 
-    public TextSqlNode(String text) {
-        this.text = text;
-    }
+	public TextSqlNode(String text) {
+		this.text = text;
+	}
 
-    @Override
-    public String getSql(Map<String, Object> paramMap, List<Object> parameters) {
-        String sql = text;
-        if (StringUtils.isNotBlank(text)) {
-            // 提取#{}表达式
-            List<String> expressions = extractParameter(expressionRegx, text);
-            for (String expression : expressions) {
-                // 执行表达式
-                Object val = ScriptManager.executeExpression(expression, paramMap);
-                parameters.add(val);
-                sql = sql.replaceFirst(expressionRegx.pattern(), "?");
-            }
-            expressions = extractParameter(replaceRegx, text);
-            for (String expression : expressions) {
-                Object val = ScriptManager.executeExpression(expression, paramMap);
-                sql = sql.replaceFirst(replaceRegx.pattern(), Objects.toString(val, ""));
-            }
-        }
-        return sql + executeChildren(paramMap, parameters).trim();
-    }
+	@Override
+	public String getSql(Map<String, Object> paramMap, List<Object> parameters) {
+		String sql = text;
+		if (StringUtils.isNotBlank(text)) {
+			// 提取#{}表达式
+			List<String> expressions = extractParameter(expressionRegx, text);
+			for (String expression : expressions) {
+				// 执行表达式
+				Object val = ScriptManager.executeExpression(expression, paramMap);
+				parameters.add(val);
+				sql = sql.replaceFirst(expressionRegx.pattern(), "?");
+			}
+			expressions = extractParameter(replaceRegx, text);
+			for (String expression : expressions) {
+				Object val = ScriptManager.executeExpression(expression, paramMap);
+				sql = sql.replaceFirst(replaceRegx.pattern(), Objects.toString(val, ""));
+			}
+		}
+		return sql + executeChildren(paramMap, parameters).trim();
+	}
 }

+ 69 - 60
magic-api/src/main/java/org/ssssssss/magicapi/modules/mybatis/TrimSqlNode.java

@@ -7,74 +7,83 @@ import java.util.Map;
 
 /**
  * 对应XML中 <trim>,注意prefixOverrides和suffixOverrides大小写敏感
+ *
  * @author zhangxu
  * @version : 2020-12-05
  */
 public class TrimSqlNode extends SqlNode {
-    /** 前缀  prefix*/
-    protected String prefix;
-    /** 后缀  suffix*/
-    protected String suffix;
-    /** 前缀 prefixOverrides */
-    protected String prefixOverrides;
-    /** 后缀 suffixOverrides */
-    protected String suffixOverrides;
+	/**
+	 * 前缀  prefix
+	 */
+	protected String prefix;
+	/**
+	 * 后缀  suffix
+	 */
+	protected String suffix;
+	/**
+	 * 前缀 prefixOverrides
+	 */
+	protected String prefixOverrides;
+	/**
+	 * 后缀 suffixOverrides
+	 */
+	protected String suffixOverrides;
 
-    public void setPrefix(String prefix) {
-        this.prefix = prefix;
-    }
+	public static void main(String[] args) {
+		String sql = "11111?,";
+		System.out.println(sql.substring(0, sql.lastIndexOf(",")));
+	}
 
-    public void setSuffix(String suffix) {
-        this.suffix = suffix;
-    }
+	public void setPrefix(String prefix) {
+		this.prefix = prefix;
+	}
 
-    public void setSuffixOverrides(String suffixOverrides) {
-        this.suffixOverrides = suffixOverrides == null ? null : suffixOverrides.toUpperCase();
-    }
+	public void setSuffix(String suffix) {
+		this.suffix = suffix;
+	}
 
-    public void setPrefixOverrides(String prefixOverrides) {
-        this.prefixOverrides = prefixOverrides == null ? null : prefixOverrides.toUpperCase();
-    }
+	public void setSuffixOverrides(String suffixOverrides) {
+		this.suffixOverrides = suffixOverrides == null ? null : suffixOverrides.toUpperCase();
+	}
 
-    @Override
-    public String getSql(Map<String, Object> paramMap, List<Object> parameters) {
-        StringBuilder sqlBuffer = new StringBuilder();
-        String childrenSql = executeChildren(paramMap, parameters).trim();
-        // 如果子节点不为null,则转成数组
-        if (StringUtils.isNotEmpty(childrenSql)) {
-            String upperSql = childrenSql.toUpperCase();
-            // 开始拼接SQL,
-            sqlBuffer.append(StringUtils.defaultString(this.prefix)).append(" ");
-            //去掉prefixOverrides
-            if (StringUtils.isNotEmpty(this.prefixOverrides)) {
-                String[] overrideArray = this.prefixOverrides.split("\\|");
-                for (String override : overrideArray) {
-                    if (upperSql.startsWith(override)) {
-                        childrenSql = childrenSql.substring(upperSql.indexOf(override) + override.length()).trim();
-                        upperSql = childrenSql.toUpperCase();
-                        break;
-                    }
-                }
-            }
-            //去掉suffixOverrides
-            if (StringUtils.isNotBlank(this.suffixOverrides)) {
-                String[] overrideArray = this.suffixOverrides.split("\\|");
-                for (String override : overrideArray) {
-                    if (upperSql.endsWith(override)) {
-                        childrenSql = childrenSql.substring(0, upperSql.lastIndexOf(override));
-                        break;
-                    }
-                }
-            }
-            sqlBuffer.append(childrenSql);
-            // 拼接结束SQL
-            sqlBuffer.append(" ").append(StringUtils.defaultString(this.suffix));
-        }
-        return sqlBuffer.toString();
-    }
+	public void setPrefixOverrides(String prefixOverrides) {
+		this.prefixOverrides = prefixOverrides == null ? null : prefixOverrides.toUpperCase();
+	}
 
-    public static void main(String[] args) {
-        String sql = "11111?,";
-        System.out.println(sql.substring(0, sql.lastIndexOf(",")));
-    }
+	@Override
+	public String getSql(Map<String, Object> paramMap, List<Object> parameters) {
+		StringBuilder sqlBuffer = new StringBuilder();
+		String childrenSql = executeChildren(paramMap, parameters).trim();
+		// 如果子节点不为null,则转成数组
+		if (StringUtils.isNotEmpty(childrenSql)) {
+			String upperSql = childrenSql.toUpperCase();
+			// 开始拼接SQL,
+			sqlBuffer.append(StringUtils.defaultString(this.prefix)).append(" ");
+			//去掉prefixOverrides
+			if (StringUtils.isNotEmpty(this.prefixOverrides)) {
+				String[] overrideArray = this.prefixOverrides.split("\\|");
+				for (String override : overrideArray) {
+					if (upperSql.startsWith(override)) {
+						childrenSql = childrenSql.substring(upperSql.indexOf(override) + override.length()).trim();
+						upperSql = childrenSql.toUpperCase();
+						break;
+					}
+				}
+			}
+			//去掉suffixOverrides
+			if (StringUtils.isNotBlank(this.suffixOverrides)) {
+				String[] overrideArray = this.suffixOverrides.split("\\|");
+				for (String override : overrideArray) {
+					if (upperSql.endsWith(override)) {
+						childrenSql = childrenSql.substring(0, upperSql.lastIndexOf(override));
+						break;
+					}
+				}
+			}
+			sqlBuffer.append(childrenSql);
+			// 拼接结束SQL
+			sqlBuffer.append(" ").append(StringUtils.defaultString(this.suffix));
+		}
+		return sqlBuffer.toString();
+	}
 }

+ 144 - 128
magic-api/src/main/java/org/ssssssss/magicapi/modules/table/NamedTable.java

@@ -12,6 +12,7 @@ import org.ssssssss.magicapi.modules.BoundSql;
 import org.ssssssss.magicapi.modules.SQLModule;
 import org.ssssssss.script.annotation.Comment;
 import org.ssssssss.script.annotation.UnableCall;
+import org.ssssssss.script.runtime.RuntimeContext;
 
 import java.io.Serializable;
 import java.util.*;
@@ -120,20 +121,22 @@ public class NamedTable extends Attributes<Object> {
 	}
 
 	@Comment("设置主键名,update时使用")
-	public NamedTable primary(String primary) {
+	public NamedTable primary(@Comment(name = "primary", value = "主键列") String primary) {
 		this.primary = rowMapColumnMapper.apply(primary);
 		return this;
 	}
 
 	@Comment("设置主键名,并设置默认主键值(主要用于insert)")
-	public NamedTable primary(String primary, Serializable defaultPrimaryValue) {
+	public NamedTable primary(@Comment(name = "primary", value = "主键列") String primary,
+							  @Comment(name = "defaultPrimaryValue", value = "默认值") Serializable defaultPrimaryValue) {
 		this.primary = rowMapColumnMapper.apply(primary);
 		this.defaultPrimaryValue = defaultPrimaryValue;
 		return this;
 	}
 
 	@Comment("设置主键名,并设置默认主键值(主要用于insert)")
-	public NamedTable primary(String primary, Supplier<Object> defaultPrimaryValue) {
+	public NamedTable primary(@Comment(name = "primary", value = "主键列") String primary,
+							  @Comment(name = "defaultPrimaryValue", value = "默认值") Supplier<Object> defaultPrimaryValue) {
 		this.primary = rowMapColumnMapper.apply(primary);
 		this.defaultPrimaryValue = defaultPrimaryValue;
 		return this;
@@ -145,90 +148,92 @@ public class NamedTable extends Attributes<Object> {
 	}
 
 	@Comment("设置单列的值")
-	public NamedTable column(@Comment("列名") String key, @Comment("值") Object value) {
-		this.columns.put(rowMapColumnMapper.apply(key), value);
+	public NamedTable column(@Comment(name = "property", value = "列名") String property,
+							 @Comment(name = "value", value = "值") Object value) {
+		this.columns.put(rowMapColumnMapper.apply(property), value);
 		return this;
 	}
 
 	@Comment("设置查询的列,如`columns('a','b','c')`")
-	public NamedTable columns(@Comment("各项列") String... columns) {
-		if (columns != null) {
-			for (String column : columns) {
-				column(column);
+	public NamedTable columns(@Comment(name = "properties", value = "各项列") String... properties) {
+		if (properties != null) {
+			for (String property : properties) {
+				column(property);
 			}
 		}
 		return this;
 	}
 
 	@Comment("设置要排除的列")
-	public NamedTable exclude(String column) {
-		if (column != null) {
-			excludeColumns.add(rowMapColumnMapper.apply(column));
+	public NamedTable exclude(@Comment(name = "property", value = "排除的列") String property) {
+		if (property != null) {
+			excludeColumns.add(rowMapColumnMapper.apply(property));
 		}
 		return this;
 	}
 
 	@Comment("设置要排除的列")
-	public NamedTable excludes(String... columns) {
+	public NamedTable excludes(@Comment(name = "properties", value = "排除的列") String... properties) {
 		if (columns != null) {
-			excludeColumns.addAll(Arrays.stream(columns).map(rowMapColumnMapper).collect(Collectors.toList()));
+			excludeColumns.addAll(Arrays.stream(properties).map(rowMapColumnMapper).collect(Collectors.toList()));
 		}
 		return this;
 	}
 
 	@Comment("设置要排除的列")
-	public NamedTable excludes(List<String> columns) {
+	public NamedTable excludes(@Comment(name = "properties", value = "排除的列") List<String> properties) {
 		if (columns != null) {
-			excludeColumns.addAll(columns.stream().map(rowMapColumnMapper).collect(Collectors.toList()));
+			excludeColumns.addAll(properties.stream().map(rowMapColumnMapper).collect(Collectors.toList()));
 		}
 		return this;
 	}
 
 	@Comment("设置查询的列,如`columns(['a','b','c'])`")
-	public NamedTable columns(Collection<String> columns) {
-		if (columns != null) {
-			columns.stream().filter(StringUtils::isNotBlank).map(rowMapColumnMapper).forEach(this.fields::add);
+	public NamedTable columns(@Comment(name = "properties", value = "查询的列") Collection<String> properties) {
+		if (properties != null) {
+			properties.stream().filter(StringUtils::isNotBlank).map(rowMapColumnMapper).forEach(this.fields::add);
 		}
 		return this;
 	}
 
 	@Comment("设置查询的列,如`column('a')`")
-	public NamedTable column(String column) {
-		if (StringUtils.isNotBlank(column)) {
-			this.fields.add(this.rowMapColumnMapper.apply(column));
+	public NamedTable column(@Comment(name = "property", value = "查询的列") String property) {
+		if (StringUtils.isNotBlank(property)) {
+			this.fields.add(this.rowMapColumnMapper.apply(property));
 		}
 		return this;
 	}
 
 	@Comment("拼接`order by xxx asc/desc`")
-	public NamedTable orderBy(@Comment("要排序的列") String column, @Comment("`asc`或`desc`") String sort) {
-		this.orders.add(rowMapColumnMapper.apply(column) + " " + sort);
+	public NamedTable orderBy(@Comment(name = "property", value = "要排序的列") String property,
+							  @Comment(name = "sort", value = "`asc`或`desc`") String sort) {
+		this.orders.add(rowMapColumnMapper.apply(property) + " " + sort);
 		return this;
 	}
 
 	@Comment("拼接`order by xxx asc`")
-	public NamedTable orderBy(@Comment("要排序的列") String column) {
-		return orderBy(column, "asc");
+	public NamedTable orderBy(@Comment(name = "property", value = "要排序的列") String property) {
+		return orderBy(property, "asc");
 	}
 
 	@Comment("拼接`order by xxx desc`")
-	public NamedTable orderByDesc(@Comment("要排序的列") String column) {
-		return orderBy(column, "desc");
+	public NamedTable orderByDesc(@Comment(name = "property", value = "要排序的列") String property) {
+		return orderBy(property, "desc");
 	}
 
 	@Comment("拼接`group by`")
-	public NamedTable groupBy(@Comment("要分组的列") String... columns) {
-		this.groups.addAll(Arrays.stream(columns).map(rowMapColumnMapper).collect(Collectors.toList()));
+	public NamedTable groupBy(@Comment(name = "properties", value = "要分组的列") String... properties) {
+		this.groups.addAll(Arrays.stream(properties).map(rowMapColumnMapper).collect(Collectors.toList()));
 		return this;
 	}
 
 	@Comment("执行插入,返回主键")
-	public Object insert() {
-		return insert(null);
+	public Object insert(RuntimeContext runtimeContext) {
+		return insert(runtimeContext, null);
 	}
 
 	@Comment("执行插入,返回主键")
-	public Object insert(@Comment("各项列和值") Map<String, Object> data) {
+	public Object insert(RuntimeContext runtimeContext, @Comment(name = "data", value = "各项列和值") Map<String, Object> data) {
 		if (data != null) {
 			data.forEach((key, value) -> this.columns.put(rowMapColumnMapper.apply(key), value));
 		}
@@ -252,16 +257,16 @@ public class NamedTable extends Attributes<Object> {
 		builder.append(") values (");
 		builder.append(StringUtils.join(Collections.nCopies(entries.size(), "?"), ","));
 		builder.append(")");
-		return sqlModule.insert(new BoundSql(builder.toString(), entries.stream().map(Map.Entry::getValue).collect(Collectors.toList()), sqlModule), this.primary);
+		return sqlModule.insert(new BoundSql(runtimeContext, builder.toString(), entries.stream().map(Map.Entry::getValue).collect(Collectors.toList()), sqlModule), this.primary);
 	}
 
 	@Comment("执行delete语句")
-	public int delete() {
+	public int delete(RuntimeContext runtimeContext) {
 		preHandle(SqlMode.DELETE);
 		if (useLogic) {
 			Map<String, Object> dataMap = new HashMap<>();
 			dataMap.put(logicDeleteColumn, logicDeleteValue);
-			return update(dataMap);
+			return update(runtimeContext, dataMap);
 		}
 		if (where.isEmpty()) {
 			throw new MagicAPIException("delete语句不能没有条件");
@@ -270,16 +275,18 @@ public class NamedTable extends Attributes<Object> {
 		builder.append("delete from ");
 		builder.append(tableName);
 		builder.append(where.getSql());
-		return sqlModule.update(new BoundSql(builder.toString(), where.getParams(), sqlModule));
+		return sqlModule.update(new BoundSql(runtimeContext, builder.toString(), where.getParams(), sqlModule));
 	}
 
 	@Comment("保存到表中,当主键有值时则修改,否则插入")
-	public Object save() {
-		return this.save(null, false);
+	public Object save(RuntimeContext runtimeContext) {
+		return this.save(runtimeContext, null, false);
 	}
 
 	@Comment("保存到表中,当主键有值时则修改,否则插入")
-	public Object save(@Comment("各项列和值") Map<String, Object> data, @Comment("是否根据id查询有没有数据") boolean beforeQuery) {
+	public Object save(RuntimeContext runtimeContext,
+					   @Comment(name = "data", value = "各项列和值") Map<String, Object> data,
+					   @Comment(name = "beforeQuery", value = "是否根据id查询有没有数据") boolean beforeQuery) {
 		if (StringUtils.isBlank(this.primary)) {
 			throw new MagicAPIException("请设置主键");
 		}
@@ -291,64 +298,70 @@ public class NamedTable extends Attributes<Object> {
 			if (StringUtils.isNotBlank(primaryValue)) {
 				List<Object> params = new ArrayList<>();
 				params.add(primaryValue);
-				Integer count = sqlModule.selectInt(new BoundSql("select count(*) count from " + this.tableName + " where " + this.primary + " = ?", params, sqlModule));
+				Integer count = sqlModule.selectInt(new BoundSql(runtimeContext, "select count(*) count from " + this.tableName + " where " + this.primary + " = ?", params, sqlModule));
 				if (count == 0) {
-					return insert(data);
+					return insert(runtimeContext, data);
 				}
-				return update(data);
+				return update(runtimeContext, data);
 			} else {
-				return insert(data);
+				return insert(runtimeContext, data);
 			}
 		}
 
 		if (StringUtils.isNotBlank(primaryValue)) {
-			return update(data);
+			return update(runtimeContext, data);
 		}
-		return insert(data);
+		return insert(runtimeContext, data);
 	}
 
 	@Comment("保存到表中,当主键有值时则修改,否则插入")
-	public Object save(boolean beforeQuery) {
-		return this.save(null, beforeQuery);
+	public Object save(RuntimeContext runtimeContext,
+					   @Comment(name = "beforeQuery", value = "是否根据id查询有没有数据") boolean beforeQuery) {
+		return this.save(runtimeContext, null, beforeQuery);
 	}
 
 	@Comment("保存到表中,当主键有值时则修改,否则插入")
-	public Object save(@Comment("各项列和值") Map<String, Object> data) {
-		return this.save(data, false);
+	public Object save(RuntimeContext runtimeContext,
+					   @Comment(name = "data", value = "各项列和值") Map<String, Object> data) {
+		return this.save(runtimeContext, data, false);
 	}
 
 
 	@Comment("执行`select`查询")
-	public List<Map<String, Object>> select() {
+	public List<Map<String, Object>> select(RuntimeContext runtimeContext) {
 		preHandle(SqlMode.SELECT);
-		return sqlModule.select(buildSelect());
+		return sqlModule.select(buildSelect(runtimeContext));
 	}
 
 	@Comment("执行`selectOne`查询")
-	public Map<String, Object> selectOne() {
+	public Map<String, Object> selectOne(RuntimeContext runtimeContext) {
 		preHandle(SqlMode.SELECT_ONE);
-		return sqlModule.selectOne(buildSelect());
+		return sqlModule.selectOne(buildSelect(runtimeContext));
 	}
 
 	@Comment("执行分页查询")
-	public Object page() {
+	public Object page(RuntimeContext runtimeContext) {
 		preHandle(SqlMode.PAGE);
-		return sqlModule.page(buildSelect());
+		return sqlModule.page(buildSelect(runtimeContext));
 	}
 
 	@Comment("执行分页查询,分页条件手动传入")
-	public Object page(@Comment("限制条数") long limit, @Comment("跳过条数") long offset) {
+	public Object page(RuntimeContext runtimeContext,
+					   @Comment(name = "limit", value = "限制条数") long limit,
+					   @Comment(name = "offset", value = "跳过条数") long offset) {
 		preHandle(SqlMode.PAGE);
-		return sqlModule.page(buildSelect(), new Page(limit, offset));
+		return sqlModule.page(buildSelect(runtimeContext), new Page(limit, offset));
 	}
 
 	@Comment("执行update语句")
-	public int update() {
-		return update(null);
+	public int update(RuntimeContext runtimeContext) {
+		return update(runtimeContext, null);
 	}
 
 	@Comment("执行update语句")
-	public int update(@Comment("各项列和值") Map<String, Object> data, @Comment("是否更新空值字段") boolean isUpdateBlank) {
+	public int update(RuntimeContext runtimeContext,
+					  @Comment(name = "data", value = "各项列和值") Map<String, Object> data,
+					  @Comment(name = "isUpdateBlank", value = "是否更新空值字段") boolean isUpdateBlank) {
 		if (null != data) {
 			data.forEach((key, value) -> this.columns.put(rowMapColumnMapper.apply(key), value));
 		}
@@ -384,26 +397,27 @@ public class NamedTable extends Attributes<Object> {
 		} else {
 			throw new MagicAPIException("主键值不能为空");
 		}
-		return sqlModule.update(new BoundSql(builder.toString(), params, sqlModule));
+		return sqlModule.update(new BoundSql(runtimeContext, builder.toString(), params, sqlModule));
 	}
 
 	@Comment("执行update语句")
-	public int update(@Comment("各项列和值") Map<String, Object> data) {
-		return update(data, this.withBlank);
+	public int update(RuntimeContext runtimeContext,
+					  @Comment(name = "data", value = "各项列和值") Map<String, Object> data) {
+		return update(runtimeContext, data, this.withBlank);
 	}
 
 	@Comment("查询条数")
-	public int count() {
+	public int count(RuntimeContext runtimeContext) {
 		preHandle(SqlMode.COUNT);
 		StringBuilder builder = new StringBuilder();
 		builder.append("select count(1) from ").append(tableName);
 		List<Object> params = buildWhere(builder);
-		return sqlModule.selectInt(new BoundSql(builder.toString(), params, sqlModule));
+		return sqlModule.selectInt(new BoundSql(runtimeContext, builder.toString(), params, sqlModule));
 	}
 
 	@Comment("判断是否存在")
-	public boolean exists() {
-		return count() > 0;
+	public boolean exists(RuntimeContext runtimeContext) {
+		return count(runtimeContext) > 0;
 	}
 
 	private Collection<Map.Entry<String, Object>> filterNotBlanks() {
@@ -420,13 +434,13 @@ public class NamedTable extends Attributes<Object> {
 				.collect(Collectors.toList());
 	}
 
-	private void preHandle(SqlMode sqlMode){
-		if(this.namedTableInterceptors != null){
+	private void preHandle(SqlMode sqlMode) {
+		if (this.namedTableInterceptors != null) {
 			this.namedTableInterceptors.forEach(interceptor -> interceptor.preHandle(sqlMode, this));
 		}
 	}
 
-	private BoundSql buildSelect() {
+	private BoundSql buildSelect(RuntimeContext runtimeContext) {
 		StringBuilder builder = new StringBuilder();
 		builder.append("select ");
 		List<String> fields = this.fields.stream()
@@ -447,7 +461,7 @@ public class NamedTable extends Attributes<Object> {
 			builder.append(" group by ");
 			builder.append(String.join(",", groups));
 		}
-		BoundSql boundSql = new BoundSql(builder.toString(), params, sqlModule);
+		BoundSql boundSql = new BoundSql(runtimeContext, builder.toString(), params, sqlModule);
 		boundSql.setExcludeColumns(excludeColumns);
 		return boundSql;
 	}
@@ -471,6 +485,7 @@ public class NamedTable extends Attributes<Object> {
 
 	/**
 	 * 获取查询的表名
+	 *
 	 * @return 表名
 	 */
 	@UnableCall
@@ -479,8 +494,17 @@ public class NamedTable extends Attributes<Object> {
 	}
 
 	/**
-	 * 获取SQL模块
+	 * 设置表名
 	 *
+	 * @param tableName 表名
+	 */
+	@UnableCall
+	public void setTableName(String tableName) {
+		this.tableName = tableName;
+	}
+
+	/**
+	 * 获取SQL模块
 	 */
 	@UnableCall
 	public SQLModule getSqlModule() {
@@ -520,133 +544,125 @@ public class NamedTable extends Attributes<Object> {
 	}
 
 	/**
-	 * 获取设置的fields
-	 */
-	@UnableCall
-	public List<String> getFields() {
-		return fields;
-	}
-
-	/**
-	 * 获取设置的group
+	 * 设置columns
 	 */
 	@UnableCall
-	public List<String> getGroups() {
-		return groups;
+	public void setColumns(Map<String, Object> columns) {
+		this.columns = columns;
 	}
 
 	/**
-	 * 获取设置的order
+	 * 获取设置的fields
 	 */
 	@UnableCall
-	public List<String> getOrders() {
-		return orders;
+	public List<String> getFields() {
+		return fields;
 	}
 
 	/**
-	 * 获取设置的排除的列
+	 * 设置 fields
 	 */
 	@UnableCall
-	public Set<String> getExcludeColumns() {
-		return excludeColumns;
+	public void setFields(List<String> fields) {
+		this.fields = fields;
 	}
 
 	/**
-	 * 主键默认值
-	 * @return
+	 * 获取设置的group
 	 */
 	@UnableCall
-	public Object getDefaultPrimaryValue() {
-		return defaultPrimaryValue;
+	public List<String> getGroups() {
+		return groups;
 	}
 
 	/**
-	 * 是否设逻辑了逻辑删除
+	 * 设置 group
 	 */
 	@UnableCall
-	public boolean isUseLogic() {
-		return useLogic;
+	public void setGroups(List<String> groups) {
+		this.groups = groups;
 	}
 
 	/**
-	 * 获取是否不过滤空参数
+	 * 获取设置的order
 	 */
 	@UnableCall
-	public boolean isWithBlank() {
-		return withBlank;
+	public List<String> getOrders() {
+		return orders;
 	}
 
 	/**
-	 * 获取where
+	 * 设置 order
 	 */
 	@UnableCall
-	public Where getWhere() {
-		return where;
+	public void setOrders(List<String> orders) {
+		this.orders = orders;
 	}
 
 	/**
-	 * 设置表名
-	 * @param tableName 表名
+	 * 获取设置的排除的列
 	 */
 	@UnableCall
-	public void setTableName(String tableName) {
-		this.tableName = tableName;
+	public Set<String> getExcludeColumns() {
+		return excludeColumns;
 	}
 
 	/**
-	 * 设置columns
+	 * 设置排除的列
 	 */
 	@UnableCall
-	public void setColumns(Map<String, Object> columns) {
-		this.columns = columns;
+	public void setExcludeColumns(Set<String> excludeColumns) {
+		this.excludeColumns = excludeColumns;
 	}
 
 	/**
-	 * 设置 fields
+	 * 主键默认值
+	 *
+	 * @return
 	 */
 	@UnableCall
-	public void setFields(List<String> fields) {
-		this.fields = fields;
+	public Object getDefaultPrimaryValue() {
+		return defaultPrimaryValue;
 	}
 
 	/**
-	 * 设置 group
+	 * 是否设逻辑了逻辑删除
 	 */
 	@UnableCall
-	public void setGroups(List<String> groups) {
-		this.groups = groups;
+	public boolean isUseLogic() {
+		return useLogic;
 	}
 
 	/**
-	 * 设置 order
+	 * 设置是否使用逻辑删除
 	 */
 	@UnableCall
-	public void setOrders(List<String> orders) {
-		this.orders = orders;
+	public void setUseLogic(boolean useLogic) {
+		this.useLogic = useLogic;
 	}
 
 	/**
-	 * 设置排除的列
+	 * 获取是否不过滤空参数
 	 */
 	@UnableCall
-	public void setExcludeColumns(Set<String> excludeColumns) {
-		this.excludeColumns = excludeColumns;
+	public boolean isWithBlank() {
+		return withBlank;
 	}
 
 	/**
-	 * 设置是否使用逻辑删除
+	 * 设置是否不过滤空参数
 	 */
 	@UnableCall
-	public void setUseLogic(boolean useLogic) {
-		this.useLogic = useLogic;
+	public void setWithBlank(boolean withBlank) {
+		this.withBlank = withBlank;
 	}
 
 	/**
-	 * 设置是否不过滤空参数
+	 * 获取where
 	 */
 	@UnableCall
-	public void setWithBlank(boolean withBlank) {
-		this.withBlank = withBlank;
+	public Where getWhere() {
+		return where;
 	}
 
 	/**

+ 173 - 129
magic-api/src/main/java/org/ssssssss/magicapi/modules/table/Where.java

@@ -3,6 +3,7 @@ package org.ssssssss.magicapi.modules.table;
 import org.apache.commons.lang3.StringUtils;
 import org.ssssssss.script.annotation.Comment;
 import org.ssssssss.script.functions.StreamExtension;
+import org.ssssssss.script.runtime.RuntimeContext;
 
 import java.util.*;
 import java.util.function.Function;
@@ -46,58 +47,6 @@ public class Where {
 		return where;
 	}
 
-	void appendAnd() {
-		remove();
-		tokens.add("and");
-	}
-
-	void appendOr() {
-		remove();
-		tokens.add("or");
-	}
-
-	List<Object> getParams() {
-		return params;
-	}
-
-	void remove() {
-		int size = tokens.size();
-		while (size > 0) {
-			String token = tokens.get(size - 1);
-			if ("and".equalsIgnoreCase(token) || "or".equalsIgnoreCase(token)) {
-				tokens.remove(size - 1);
-				size--;
-			} else {
-				break;
-			}
-		}
-		while (size > 0) {
-			String token = tokens.get(0);
-			if ("and".equalsIgnoreCase(token) || "or".equalsIgnoreCase(token)) {
-				tokens.remove(0);
-				size--;
-			} else {
-				break;
-			}
-		}
-	}
-
-	boolean isEmpty() {
-		return tokens.isEmpty();
-	}
-
-	void append(String value) {
-		tokens.add(value);
-	}
-
-	String getSql() {
-		remove();
-		if (isEmpty()) {
-			return "";
-		}
-		return (needWhere ? " where " : "") + String.join(" ", tokens);
-	}
-
 	@Comment("过滤`null`的参数")
 	public Where notNull() {
 		return notNull(true);
@@ -120,20 +69,16 @@ public class Where {
 		return this;
 	}
 
-	boolean filterNullAndBlank(Object value) {
-		if (notNull && value == null) {
-			return false;
-		}
-		return !notBlank || !StringUtils.isEmpty(Objects.toString(value, ""));
-	}
-
 	@Comment("等于`=`,如:`eq('name', '老王') ---> name = '老王'`")
-	public Where eq(@Comment("数据库中的列名") String column, @Comment("值") Object value) {
+	public Where eq(@Comment(name = "column", value = "数据库中的列名") String column,
+					@Comment(name = "value", value = "值") Object value) {
 		return eq(true, column, value);
 	}
 
 	@Comment("等于`=`,如:`eq('name', '老王') ---> name = '老王'`")
-	public Where eq(@Comment("判断表达式,当为true时拼接条件") boolean condition, @Comment("数据库中的列名") String column, @Comment("值") Object value) {
+	public Where eq(@Comment(name = "condition", value = "判断表达式,当为true时拼接条件") boolean condition,
+					@Comment(name = "column", value = "数据库中的列名") String column,
+					@Comment(name = "value", value = "值") Object value) {
 		if (condition && filterNullAndBlank(value)) {
 			tokens.add(namedTable.rowMapColumnMapper.apply(column));
 			if (value == null) {
@@ -148,12 +93,15 @@ public class Where {
 	}
 
 	@Comment("不等于`<>`,如:`ne('name', '老王') ---> name <> '老王'`")
-	public Where ne(@Comment("数据库中的列名") String column, @Comment("值") Object value) {
+	public Where ne(@Comment(name = "column", value = "数据库中的列名") String column,
+					@Comment(name = "value", value = "值") Object value) {
 		return ne(true, column, value);
 	}
 
 	@Comment("不等于`<>`,如:`ne('name', '老王') ---> name <> '老王'`")
-	public Where ne(@Comment("判断表达式,当为true时拼接条件") boolean condition, @Comment("数据库中的列名") String column, @Comment("值") Object value) {
+	public Where ne(@Comment(name = "condition", value = "判断表达式,当为true时拼接条件") boolean condition,
+					@Comment(name = "column", value = "数据库中的列名") String column,
+					@Comment(name = "value", value = "值") Object value) {
 		if (condition && filterNullAndBlank(value)) {
 			append(namedTable.rowMapColumnMapper.apply(column));
 			if (value == null) {
@@ -167,63 +115,68 @@ public class Where {
 		return this;
 	}
 
-	private Where append(boolean append, String column, String condition, Object value) {
-		if (append && filterNullAndBlank(value)) {
-			append(namedTable.rowMapColumnMapper.apply(column));
-			append(condition);
-			appendAnd();
-			params.add(value);
-		}
-		return this;
-	}
-
 	@Comment("小于`<`,如:`lt('age', 18) ---> age < 18")
-	public Where lt(@Comment("数据库中的列名") String column, @Comment("值") Object value) {
+	public Where lt(@Comment(name = "column", value = "数据库中的列名") String column,
+					@Comment(name = "value", value = "值") Object value) {
 		return lt(true, column, value);
 	}
 
 	@Comment("小于`<`,如:`lt('age', 18) ---> age < 18")
-	public Where lt(@Comment("判断表达式,当为true时拼接条件") boolean condition, @Comment("数据库中的列名") String column, @Comment("值") Object value) {
+	public Where lt(@Comment(name = "condition", value = "判断表达式,当为true时拼接条件") boolean condition,
+					@Comment(name = "column", value = "数据库中的列名") String column,
+					@Comment(name = "value", value = "值") Object value) {
 		return append(condition, column, " < ?", value);
 	}
 
 	@Comment("小于等于`<=`,如:`lte('age', 18) ---> age <= 18")
-	public Where lte(@Comment("数据库中的列名") String column, @Comment("值") Object value) {
+	public Where lte(@Comment(name = "column", value = "数据库中的列名") String column,
+					 @Comment(name = "value", value = "值") Object value) {
 		return lte(true, column, value);
 	}
 
 	@Comment("小于等于`<=`,如:`lte('age', 18) ---> age <= 18")
-	public Where lte(@Comment("判断表达式,当为true时拼接条件") boolean condition, @Comment("数据库中的列名") String column, @Comment("值") Object value) {
+	public Where lte(@Comment(name = "condition", value = "判断表达式,当为true时拼接条件") boolean condition,
+					 @Comment(name = "column", value = "数据库中的列名") String column,
+					 @Comment(name = "value", value = "值") Object value) {
 		return append(condition, column, " <= ?", value);
 	}
 
 	@Comment("大于`>`,如:`get('age', 18) ---> age > 18")
-	public Where gt(@Comment("数据库中的列名") String column, @Comment("值") Object value) {
+	public Where gt(@Comment(name = "column", value = "数据库中的列名") String column,
+					@Comment(name = "value", value = "值") Object value) {
 		return gt(true, column, value);
 	}
 
 	@Comment("大于`>`,如:`get('age', 18) ---> age > 18")
-	public Where gt(@Comment("判断表达式,当为true时拼接条件") boolean condition, @Comment("数据库中的列名") String column, @Comment("值") Object value) {
+	public Where gt(@Comment(name = "condition", value = "判断表达式,当为true时拼接条件") boolean condition,
+					@Comment(name = "column", value = "数据库中的列名") String column,
+					@Comment(name = "value", value = "值") Object value) {
 		return append(condition, column, " > ?", value);
 	}
 
 	@Comment("大于等于`>=`,如:`get('age', 18) ---> age >= 18")
-	public Where gte(@Comment("数据库中的列名") String column, @Comment("值") Object value) {
+	public Where gte(@Comment(name = "column", value = "数据库中的列名") String column,
+					 @Comment(name = "value", value = "值") Object value) {
 		return gte(true, column, value);
 	}
 
 	@Comment("大于等于`>=`,如:`get('age', 18) ---> age >= 18")
-	public Where gte(@Comment("判断表达式,当为true时拼接条件") boolean condition, @Comment("数据库中的列名") String column, @Comment("值") Object value) {
+	public Where gte(@Comment(name = "condition", value = "判断表达式,当为true时拼接条件") boolean condition,
+					 @Comment(name = "column", value = "数据库中的列名") String column,
+					 @Comment(name = "value", value = "值") Object value) {
 		return append(condition, column, " >= ?", value);
 	}
 
 	@Comment("`in`,如:`in('age', [1,2,3]) ---> age in (1,2,3)")
-	public Where in(@Comment("数据库中的列名") String column, @Comment("值") Object value) {
+	public Where in(@Comment(name = "column", value = "数据库中的列名") String column,
+					@Comment(name = "value", value = "值") Object value) {
 		return in(true, column, value);
 	}
 
 	@Comment("`in`,如:`in('age', [1,2,3]) ---> age in (1,2,3)")
-	public Where in(@Comment("判断表达式,当为true时拼接条件") boolean condition, @Comment("数据库中的列名") String column, @Comment("值") Object value) {
+	public Where in(@Comment(name = "condition", value = "判断表达式,当为true时拼接条件") boolean condition,
+					@Comment(name = "column", value = "数据库中的列名") String column,
+					@Comment(name = "value", value = "值") Object value) {
 		if (condition && value != null) {
 			List<Object> objects = StreamExtension.arrayLikeToList(value);
 			if (objects.size() > 0) {
@@ -239,12 +192,15 @@ public class Where {
 	}
 
 	@Comment("`not in`,如:`notIn('age', [1,2,3]) ---> age not in (1,2,3)")
-	public Where notIn(@Comment("数据库中的列名") String column, @Comment("值") Object value) {
+	public Where notIn(@Comment(name = "column", value = "数据库中的列名") String column,
+					   @Comment(name = "value", value = "值") Object value) {
 		return notIn(true, column, value);
 	}
 
 	@Comment("`not in`,如:`notIn('age', [1,2,3]) ---> age not in (1,2,3)")
-	public Where notIn(@Comment("判断表达式,当为true时拼接条件") boolean condition, @Comment("数据库中的列名") String column, @Comment("值") Object value) {
+	public Where notIn(@Comment(name = "condition", value = "判断表达式,当为true时拼接条件") boolean condition,
+					   @Comment(name = "column", value = "数据库中的列名") String column,
+					   @Comment(name = "value", value = "值") Object value) {
 		if (condition && value != null) {
 			List<Object> objects = StreamExtension.arrayLikeToList(value);
 			if (objects.size() > 0) {
@@ -260,32 +216,39 @@ public class Where {
 	}
 
 	@Comment("`like`,如:`like('name', '%王%') ---> name like '%王%'")
-	public Where like(@Comment("数据库中的列名") String column, @Comment("值") Object value) {
+	public Where like(@Comment(name = "column", value = "数据库中的列名") String column,
+					  @Comment(name = "value", value = "值") Object value) {
 		return like(true, column, value);
 	}
 
 	@Comment("`like`,如:`like('name', '%王%') ---> name like '%王%'")
-	public Where like(@Comment("判断表达式,当为true时拼接条件") boolean condition, @Comment("数据库中的列名") String column, @Comment("值") Object value) {
+	public Where like(@Comment(name = "condition", value = "判断表达式,当为true时拼接条件") boolean condition,
+					  @Comment(name = "column", value = "数据库中的列名") String column,
+					  @Comment(name = "value", value = "值") Object value) {
 		return append(condition, column, "like ?", value);
 	}
 
 	@Comment("`not like`,如:`notLike('name', '%王%') ---> name not like '%王%'")
-	public Where notLike(@Comment("数据库中的列名") String column, @Comment("值") Object value) {
+	public Where notLike(@Comment(name = "column", value = "数据库中的列名") String column,
+						 @Comment(name = "value", value = "值") Object value) {
 		return notLike(true, column, value);
 	}
 
 	@Comment("`not like` ,如:`notLike('name', '%王%') ---> name not like '%王%'")
-	public Where notLike(@Comment("判断表达式,当为true时拼接条件") boolean condition, @Comment("数据库中的列名") String column, @Comment("值") Object value) {
+	public Where notLike(@Comment(name = "condition", value = "判断表达式,当为true时拼接条件") boolean condition,
+						 @Comment(name = "column", value = "数据库中的列名") String column,
+						 @Comment(name = "value", value = "值") Object value) {
 		return append(condition, column, "not like ?", value);
 	}
 
 	@Comment("`is null`,如:`isNull('name') ---> name is null")
-	public Where isNull(@Comment("数据库中的列名") String column) {
+	public Where isNull(@Comment(name = "column", value = "数据库中的列名") String column) {
 		return isNull(true, column);
 	}
 
 	@Comment("`is null`,如:`isNull('name') ---> name is null")
-	public Where isNull(@Comment("判断表达式,当为true时拼接条件") boolean condition, @Comment("数据库中的列名") String column) {
+	public Where isNull(@Comment(name = "condition", value = "判断表达式,当为true时拼接条件") boolean condition,
+						@Comment(name = "column", value = "数据库中的列名") String column) {
 		if (condition) {
 			append(namedTable.rowMapColumnMapper.apply(column));
 			append("is null");
@@ -295,12 +258,13 @@ public class Where {
 	}
 
 	@Comment("`is not null`,如:`isNotNull('name') ---> name is not null")
-	public Where isNotNull(@Comment("数据库中的列名") String column) {
+	public Where isNotNull(@Comment(name = "column", value = "数据库中的列名") String column) {
 		return isNotNull(true, column);
 	}
 
 	@Comment("`is not null`,如:`isNotNull('name') ---> name is not null")
-	public Where isNotNull(@Comment("判断表达式,当为true时拼接条件") boolean condition, @Comment("数据库中的列名") String column) {
+	public Where isNotNull(@Comment(name = "condition", value = "判断表达式,当为true时拼接条件") boolean condition,
+						   @Comment(name = "column", value = "数据库中的列名") String column) {
 		if (condition) {
 			append(namedTable.rowMapColumnMapper.apply(column));
 			append("is not null");
@@ -327,7 +291,7 @@ public class Where {
 	}
 
 	@Comment("`and`嵌套,如and(it => it.eq('name','李白').ne('status','正常') --> and (name = '李白' and status <> '正常')")
-	public Where and(@Comment("判断表达式,当为true时拼接条件") boolean condition, Function<Object[], Where> function) {
+	public Where and(@Comment(name = "condition", value = "判断表达式,当为true时拼接条件") boolean condition, Function<Object[], Where> function) {
 		if (condition) {
 			Where expr = function.apply(new Object[]{new Where(this.namedTable, false)});
 			this.params.addAll(expr.params);
@@ -340,18 +304,19 @@ public class Where {
 	}
 
 	@Comment("拼接`order by xxx asc/desc`")
-	public Where orderBy(@Comment("要排序的列") String column, @Comment("`asc`或`desc`") String sort) {
+	public Where orderBy(@Comment(name = "column", value = "要排序的列") String column,
+						 @Comment(name = "sort", value = "`asc`或`desc`") String sort) {
 		this.namedTable.orderBy(column, sort);
 		return this;
 	}
 
 	@Comment("拼接`order by xxx asc`")
-	public Where orderBy(@Comment("要排序的列") String column) {
+	public Where orderBy(@Comment(name = "column", value = "要排序的列") String column) {
 		return orderBy(column, "asc");
 	}
 
 	@Comment("拼接`order by xxx desc`")
-	public Where orderByDesc(@Comment("要排序的列") String column) {
+	public Where orderByDesc(@Comment(name = "column", value = "要排序的列") String column) {
 		return orderBy(column, "desc");
 	}
 
@@ -362,82 +327,161 @@ public class Where {
 	}
 
 	@Comment("保存到表中,当主键有值时则修改,否则插入")
-	public Object save() {
-		return namedTable.save();
+	public Object save(RuntimeContext runtimeContext) {
+		return namedTable.save(runtimeContext);
 	}
 
 	@Comment("保存到表中,当主键有值时则修改,否则插入")
-	public Object save(@Comment("是否根据id查询有没有数据") boolean beforeQuery) {
-		return namedTable.save(beforeQuery);
+	public Object save(RuntimeContext runtimeContext,
+					   @Comment(name = "beforeQuery", value = "是否根据id查询有没有数据") boolean beforeQuery) {
+		return namedTable.save(runtimeContext, beforeQuery);
 	}
 
 	@Comment("保存到表中,当主键有值时则修改,否则插入")
-	public Object save(@Comment("各项列和值") Map<String, Object> data) {
-		return namedTable.save(data);
+	public Object save(RuntimeContext runtimeContext,
+					   @Comment(name = "data", value = "各项列和值") Map<String, Object> data) {
+		return namedTable.save(runtimeContext, data);
 	}
 
 	@Comment("保存到表中,当主键有值时则修改,否则插入")
-	public Object save(@Comment("各项列和值") Map<String, Object> data, @Comment("是否根据id查询有没有数据") boolean beforeQuery) {
-		return namedTable.save(data, beforeQuery);
+	public Object save(RuntimeContext runtimeContext,
+					   @Comment(name = "data", value = "各项列和值") Map<String, Object> data,
+					   @Comment(name = "beforeQuery", value = "是否根据id查询有没有数据") boolean beforeQuery) {
+		return namedTable.save(runtimeContext, data, beforeQuery);
 	}
 
 	@Comment("执行插入语句,返回主键")
-	public Object insert() {
-		return namedTable.insert();
+	public Object insert(RuntimeContext runtimeContext) {
+		return namedTable.insert(runtimeContext);
 	}
 
 	@Comment("执行插入语句,返回主键")
-	public Object insert(@Comment("各项列和值") Map<String, Object> data) {
-		return namedTable.insert(data);
+	public Object insert(RuntimeContext runtimeContext,
+						 @Comment(name = "data", value = "各项列和值") Map<String, Object> data) {
+		return namedTable.insert(runtimeContext, data);
 	}
 
 	@Comment("执行update语句")
-	public int update() {
-		return namedTable.update();
+	public int update(RuntimeContext runtimeContext) {
+		return namedTable.update(runtimeContext);
 	}
 
 	@Comment("执行delete语句")
-	public int delete() {
-		return namedTable.delete();
+	public int delete(RuntimeContext runtimeContext) {
+		return namedTable.delete(runtimeContext);
 	}
 
 	@Comment("执行update语句")
-	public int update(@Comment("各项列和值") Map<String, Object> data) {
-		return namedTable.update(data);
+	public int update(RuntimeContext runtimeContext,
+					  @Comment(name = "data", value = "各项列和值") Map<String, Object> data) {
+		return namedTable.update(runtimeContext, data);
 	}
 
 	@Comment("执行update语句")
-	public int update(@Comment("各项列和值") Map<String, Object> data, @Comment("是否更新空值字段") boolean isUpdateBlank) {
-		return namedTable.update(data, isUpdateBlank);
+	public int update(RuntimeContext runtimeContext,
+					  @Comment(name = "data", value = "各项列和值") Map<String, Object> data,
+					  @Comment(name = "isUpdateBlank", value = "是否更新空值字段") boolean isUpdateBlank) {
+		return namedTable.update(runtimeContext, data, isUpdateBlank);
 	}
 
 	@Comment("执行分页查询")
-	public Object page() {
-		return namedTable.page();
+	public Object page(RuntimeContext runtimeContext) {
+		return namedTable.page(runtimeContext);
 	}
 
 	@Comment("执行分页查询,分页条件手动传入")
-	public Object page(@Comment("限制条数") long limit, @Comment("跳过条数") long offset) {
-		return namedTable.page(limit, offset);
+	public Object page(RuntimeContext runtimeContext,
+					   @Comment(name = "limit", value = "限制条数") long limit,
+					   @Comment(name = "offset", value = "跳过条数") long offset) {
+		return namedTable.page(runtimeContext, limit, offset);
 	}
 
 	@Comment("执行select查询")
-	public List<Map<String, Object>> select() {
-		return namedTable.select();
+	public List<Map<String, Object>> select(RuntimeContext runtimeContext) {
+		return namedTable.select(runtimeContext);
 	}
 
 	@Comment("执行selectOne查询")
-	public Map<String, Object> selectOne() {
-		return namedTable.selectOne();
+	public Map<String, Object> selectOne(RuntimeContext runtimeContext) {
+		return namedTable.selectOne(runtimeContext);
 	}
 
 	@Comment("查询条数")
-	public int count() {
-		return namedTable.count();
+	public int count(RuntimeContext runtimeContext) {
+		return namedTable.count(runtimeContext);
 	}
 
 	@Comment("查询是否存在")
-	public boolean exists() {
-		return namedTable.exists();
+	public boolean exists(RuntimeContext runtimeContext) {
+		return namedTable.exists(runtimeContext);
+	}
+
+	void appendAnd() {
+		remove();
+		tokens.add("and");
+	}
+
+	void appendOr() {
+		remove();
+		tokens.add("or");
+	}
+
+	List<Object> getParams() {
+		return params;
+	}
+
+	void remove() {
+		int size = tokens.size();
+		while (size > 0) {
+			String token = tokens.get(size - 1);
+			if ("and".equalsIgnoreCase(token) || "or".equalsIgnoreCase(token)) {
+				tokens.remove(size - 1);
+				size--;
+			} else {
+				break;
+			}
+		}
+		while (size > 0) {
+			String token = tokens.get(0);
+			if ("and".equalsIgnoreCase(token) || "or".equalsIgnoreCase(token)) {
+				tokens.remove(0);
+				size--;
+			} else {
+				break;
+			}
+		}
+	}
+
+	boolean isEmpty() {
+		return tokens.isEmpty();
+	}
+
+	void append(String value) {
+		tokens.add(value);
+	}
+
+	String getSql() {
+		remove();
+		if (isEmpty()) {
+			return "";
+		}
+		return (needWhere ? " where " : "") + String.join(" ", tokens);
+	}
+
+	boolean filterNullAndBlank(Object value) {
+		if (notNull && value == null) {
+			return false;
+		}
+		return !notBlank || !StringUtils.isEmpty(Objects.toString(value, ""));
+	}
+
+	private Where append(boolean append, String column, String condition, Object value) {
+		if (append && filterNullAndBlank(value)) {
+			append(namedTable.rowMapColumnMapper.apply(column));
+			append(condition);
+			appendAnd();
+			params.add(value);
+		}
+		return this;
 	}
 }

+ 2 - 1
magic-api/src/main/java/org/ssssssss/magicapi/provider/PageProvider.java

@@ -2,6 +2,7 @@ package org.ssssssss.magicapi.provider;
 
 import org.ssssssss.magicapi.model.Page;
 import org.ssssssss.script.MagicScriptContext;
+import org.ssssssss.script.runtime.RuntimeContext;
 
 /**
  * 分页对象提取接口
@@ -16,5 +17,5 @@ public interface PageProvider {
 	 * @param context 脚本上下文
 	 * @return 返回分页对象
 	 */
-	public Page getPage(MagicScriptContext context);
+	public Page getPage(RuntimeContext context);
 }

+ 5 - 23
magic-api/src/main/java/org/ssssssss/magicapi/provider/impl/DefaultMagicAPIService.java

@@ -38,15 +38,12 @@ import org.ssssssss.magicapi.utils.JsonUtils;
 import org.ssssssss.magicapi.utils.PathUtils;
 import org.ssssssss.magicapi.utils.SignUtils;
 import org.ssssssss.script.MagicResourceLoader;
-import org.ssssssss.script.MagicScript;
 import org.ssssssss.script.MagicScriptContext;
 import org.ssssssss.script.exception.MagicExitException;
 import org.ssssssss.script.functions.ObjectConvertExtension;
 import org.ssssssss.script.runtime.ExitValue;
 import org.ssssssss.script.runtime.function.MagicScriptLambdaFunction;
 
-import javax.script.ScriptContext;
-import javax.script.SimpleScriptContext;
 import javax.sql.DataSource;
 import java.io.*;
 import java.sql.Connection;
@@ -127,15 +124,11 @@ public class DefaultMagicAPIService implements MagicAPIService, JsonCodeConstant
 						varMap.putAll(variables.getVariables(context));
 						newContext.setScriptName(groupServiceProvider.getScriptName(info.getGroupId(), info.getName(), info.getPath()));
 						newContext.putMapIntoContext(varMap);
-						try {
-							Object value = ScriptManager.executeScript(info.getScript(), newContext);
-							if (value instanceof ExitValue) {
-								throw new MagicExitException((ExitValue) value);
-							}
-							return value;
-						} finally {
-							MagicScriptContext.set(context);
+						Object value = ScriptManager.executeScript(info.getScript(), newContext);
+						if (value instanceof ExitValue) {
+							throw new MagicExitException((ExitValue) value);
 						}
+						return value;
 					};
 				}
 			}
@@ -144,21 +137,10 @@ public class DefaultMagicAPIService implements MagicAPIService, JsonCodeConstant
 	}
 
 	private Object execute(ApiInfo info, Map<String, Object> context) {
-
-		// 获取原上下文
-		final MagicScriptContext magicScriptContext = MagicScriptContext.get();
-
 		MagicScriptContext scriptContext = new MagicScriptContext();
 		scriptContext.setScriptName(groupServiceProvider.getScriptName(info.getGroupId(), info.getName(), info.getPath()));
 		scriptContext.putMapIntoContext(context);
-		final Object evalVal;
-		try {
-			evalVal = ScriptManager.executeScript(info.getScript(), scriptContext);
-		} finally {
-			// 恢复原接口上下文,修复当前调完其它接口后原接口上下文丢失的问题
-			MagicScriptContext.set(magicScriptContext);
-		}
-		return evalVal;
+		return ScriptManager.executeScript(info.getScript(), scriptContext);
 	}
 
 	@Override

+ 2 - 2
magic-api/src/main/java/org/ssssssss/magicapi/provider/impl/DefaultPageProvider.java

@@ -3,7 +3,7 @@ package org.ssssssss.magicapi.provider.impl;
 import org.apache.commons.lang3.math.NumberUtils;
 import org.ssssssss.magicapi.model.Page;
 import org.ssssssss.magicapi.provider.PageProvider;
-import org.ssssssss.script.MagicScriptContext;
+import org.ssssssss.script.runtime.RuntimeContext;
 
 import java.util.Objects;
 
@@ -45,7 +45,7 @@ public class DefaultPageProvider implements PageProvider {
 
 
 	@Override
-	public Page getPage(MagicScriptContext context) {
+	public Page getPage(RuntimeContext context) {
 		// 改为从脚本中获取
 		long page = NumberUtils.toLong(Objects.toString(context.eval(this.pageName), null), this.defaultPage);
 		long pageSize = NumberUtils.toLong(Objects.toString(context.eval(this.pageSize), null), this.defaultPageSize);

+ 1 - 5
magic-api/src/main/java/org/ssssssss/magicapi/script/ScriptManager.java

@@ -36,10 +36,6 @@ public class ScriptManager {
 	 * 执行脚本
 	 */
 	public static Object executeExpression(String script, Map<String, Object> paramMap) {
-		MagicScriptContext context = MagicScriptContext.get();
-		if(context == null){
-			return executeExpression(script, new MagicScriptContext(paramMap));
-		}
-		return context.eval(script, paramMap);
+		return executeExpression(script, new MagicScriptContext(paramMap));
 	}
 }