find_in_set在DataSet中的应用

最后更新:2024-09-09 05:30:00 | 状态:未完成
类似于mysql中的 FIND_IN_SET但适用类型更多,
A,B,C字符串或[A,C,D]数组或集合 或Map都适用,如果是map则检测key
public void findInSet() {
	DataSet set = new DataSet();
	for(int i=0; i<10; i++){
		DataRow row = set.add();
		row.put("ID", i);
		row.put("KEY", "A"+i+",A"+i*2);
	}
	List<String> keys = new ArrayList<>();
	keys.add("A1");
	keys.add("A2");
	keys.add("A3");
	DataRow row = set.add();
	row.put("ID", "11");
	row.put("KEY", keys);

	row = set.add();
	row.put("ID", "12");
	row.put("KEY", new String[]{"A1","A2"});

	Map<String, String> maps = new HashMap<>();
	row = set.add();
	row.put("ID", "13");
	maps.put("A1", "1");
	maps.put("A2", "2");
	row.put("KEY", maps);
	//A1,A2
	//A2,A4
	//A3,A6
	//有一个存在即可 findInSetOr = findInSet
	//[{"ID":1,"KEY":"A1,A2"},{"ID":2,"KEY":"A2,A4"},{"ID":"11","KEY":["A1","A2","A3"]},{"ID":"12","KEY":["A1","A2"]},{"ID":"13","KEY":{"A1":"1","A2":"2"}}]
	DataSet filter = set.select.findInSetOr("KEY", "A1", "A2");
	System.out.println(filter);

	//A1 A2都存在才返回
	//[{"ID":1,"KEY":"A1,A2"},{"ID":"11","KEY":["A1","A2","A3"]},{"ID":"12","KEY":["A1","A2"]},{"ID":"13","KEY":{"A1":"1","A2":"2"}}]
	filter = set.select.findInSetAnd("KEY", "A1", "A2");
	System.out.println(filter);

	//忽略大小写
	//[{"ID":1,"KEY":"A1,A2"},{"ID":"11","KEY":["A1","A2","A3"]},{"ID":"12","KEY":["A1","A2"]},{"ID":"13","KEY":{"A1":"1","A2":"2"}}]
	set.select.setIgnoreCase(true);
	filter = set.select.findInSetAnd("KEY", "a1", "a2");
	System.out.println(filter);

}
首页 最近更新 搜索 提交 回复