1.参考:
https://www.cnblogs.com/tankaixiong/p/12920667.html
2.语法
public static void main(String[] args) { SQLParser<Car> parser = SQLParser.forPojoWithAttributes(Car.class, createAttributes(Car.class)); IndexedCollection<Car> cars = new ConcurrentIndexedCollection<Car>(); cars.addAll(CarFactory.createCollectionOfCars(10)); ResultSet<Car> results = parser.retrieve(cars, "SELECT * FROM cars WHERE (" + "(manufacturer = 'Ford' OR manufacturer = 'Honda') " + "AND price <= 5000.0 " + "AND color NOT IN ('GREEN', 'WHITE')) " + "ORDER BY manufacturer DESC, price ASC"); for (Car car : results) { System.out.println(car); // Prints: Honda Accord, Ford Fusion, Ford Focus } } 3.like
select * from user where username like '%xxx%';
select * from user where username like '%xxx';
select * from user where username like 'xxx%';
4.https://blog.csdn.net/ldc5306590/article/details/53705319?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control
String sqlString="select * from tb_wf_main where trim(WF_NAME) = ' " + wfName.trim() + " ' ";
5.
package com.huawi; import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * WHERE (( name LIKE '%1%' OR name LIKE '%2%' ) AND age >= 20 ) ORDER BY manufacturer DESC, price ASC */ public class AAA { public static void main(String[] args) { String head = "WHERE ("; String end = " ) ORDER BY manufacturer DESC, price ASC"; // list ArrayList<String> sqlLists = new ArrayList<>(); List<String> strings = Arrays.asList("1", "25"); String listCenter = parseListSql(strings); sqlLists.add(listCenter); // 数值 StringBuffer stringBuffer1 = new StringBuffer(); String ageCenter = stringBuffer1.append(" AND age ").append(" >= ").append(20).toString(); sqlLists.add(ageCenter); // 字符 StringBuffer stringBuffer2 = new StringBuffer(); String StringCenter = stringBuffer2.append(" AND addr ").append(" = ").append("'" + "anhui" + "'").toString(); sqlLists.add(StringCenter); StringBuffer stringBufferFinal = new StringBuffer(); for (String s : sqlLists) { stringBufferFinal.append(s); } String finalString = head + stringBufferFinal.toString() + end; System.out.println(finalString); } public static String parseListSql(List<String> strings) { StringBuffer stringBuffer = new StringBuffer(); for (String s : strings) { stringBuffer.append("name").append(" LIKE ").append("'" + '%' + ',' + s + ',' + '%' + "'").append(" OR "); } String center = stringBuffer.append(")").toString(); center = center.substring(0, center.length() - 5); center = "( " + center + " )"; return center; } }