澳门金莎娱乐网站实现String语句的执行

时间:2019-10-07 14:52来源:编程技术
dependencygroupIdorg.apache.commons/groupIdartifactIdcommons-jexl/artifactIdversion2.0/version/dependency properties spring.version4.0.5.RELEASE/spring.version jackson.version1.9.13/jackson.version /properties import org.apache.commons.jexl

<dependency><groupId>org.apache.commons</groupId><artifactId>commons-jexl</artifactId><version>2.0</version></dependency>

<properties>
<spring.version>4.0.5.RELEASE</spring.version>
<jackson.version>1.9.13</jackson.version>
</properties>

import org.apache.commons.jexl2.Expression;import org.apache.commons.jexl2.JexlContext;import org.apache.commons.jexl2.JexlEngine;import org.apache.commons.jexl2.MapContext;import java.util.HashMap;import java.util.Map;/** * A Camel Application */public class MainApp { /** * A main() so we can easily run these routing rules in our IDE */ public static Object convertToCode(String jexlExp, Map<String, Object> map) { //创建或检索引擎 JexlEngine jexl = new JexlEngine(); //创建一个表达式 Expression e = jexl.createExpression; //创建上下文并添加数据 JexlContext jc = new MapContext(); for (String key : map.keySet { jc.set(key, map.get; } //现在评估表达式,得到结果 if (null == e.evaluate { return ""; } return e.evaluate; } public static void main(String... args) throws Exception { try { Map<String, Object> map = new HashMap<String, Object>; map.put("money", 6100); String expression = "money>=2000&&money<=4000"; Object code = convertToCode(expression, map); System.out.println code); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }}

<dependencies>
<!-- junit4 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<!--代表开辟的时候引进,发布的时候不会加载此包-->
<scope>test</scope>
</dependency>

using System.Web.Script.Serialization;

<!--spring核心包-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>

 public static object EvalJscript(string str) { object Result = null; str = str.Replace("OR", "||"); str = str.Replace("AND", "&&"); if (ve == null) { ve = Microsoft.JScript.Vsa.VsaEngine.CreateEngine(); } Result = Microsoft.JScript.Eval.JScriptEvaluate; return Result; }

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.3</version>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

<!--JSTL标签类-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>

<!--mybatis核心包-->
<dependency>
<groupId>org.mybatis</groupId>
澳门金莎娱乐网站,<artifactId>mybatis</artifactId>
<version>3.2.7</version>
</dependency>

<!--mybatis/spring核心包-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.2</version>
</dependency>

<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0</version>
</dependency>

</dependencies>

<!-- 指定JDK版本 -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>

编辑:编程技术 本文来源:澳门金莎娱乐网站实现String语句的执行

关键词: