📄 statementparser.java
字号:
package com.uiwz.db;
public class StatementParser
{
public static int STR = 1;
public static int NUM = 2;
public static int DAT = 3;
public static int SML = 1;
public static int BIG = 2;
public static int SML_EQL = 3;
public static int BIG_EQL = 4;
public static int LEFT_LK = 5;
public static int RIGHT_LK = 6;
public static int ALL_LK = 7;
public static int EQL = 8;
public static int DEFAULT_LEN = 100;
private String[] cond = new String[DEFAULT_LEN];
private int index = 0;
private boolean flag = true; //生成的条件语句前面是否要加上"and"
public StatementParser(boolean flag)
{
this.flag = flag;
}
public void addField(String fieldName, String value, int dataType, int eqlType)
{
if(fieldName == null || fieldName.equals(""))
return;
if(value == null || value.equals("") || value.equals("null"))
return;
String s = null;
if(dataType == STR)
{
if(eqlType == LEFT_LK)
s = fieldName + " LIKE '%" + value + "'";
else if(eqlType == RIGHT_LK)
s = fieldName + " LIKE '" + value + "%'";
else if(eqlType == ALL_LK)
s = fieldName + " LIKE '%" + value + "%'";
else
s = fieldName + "='" + value + "'";
}
else if(dataType == NUM)
{
if(eqlType == BIG)
s = fieldName + ">" + value;
else if(eqlType == SML)
s = fieldName + "<" + value;
else
s = fieldName + "=" + value;
}
else if(dataType == DAT)
{
if(eqlType == BIG)
s = fieldName + "='" + value + "'";
else if(eqlType == SML)
s = fieldName + "<'" + value + "'";
else if(eqlType == BIG_EQL)
s = fieldName + ">='" + value + "'";
else if(eqlType == SML_EQL)
s = fieldName + "<='" + value + "'";
}
if(s == null || s.equals(""))
return;
if(index > DEFAULT_LEN - 1)
return;
cond[index] = s;
index++;
}
public String parse()
{
String conditions = "";
if(index < 1)
return conditions;
int len = index;
for(int i=0; i<len; i++)
{
if(i == 0 && !flag)
conditions = conditions + cond[i];
else
conditions = conditions + " and " + cond[i];
}
return conditions;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -