【发布时间】:2026-01-11 06:50:03
【问题描述】:
下面是我的地图,它有两个键值对。我需要使用下面的地图来制作一个字符串。
Map<String, String> data = new LinkedHashMap<String, String>();
data.put("created_date", duration);
data.put("limit", limit);
这是我应该使用上面的地图制作的最后一个字符串。我将在下面的字符串的 where 子句中使用上面的 Map。我将在 where 子句中使用上述 Map 的键和值。
下面是我在 where 子句中使用上述 Map 后的最终字符串。
String sql = "select * from testing where created_date between " + dateMap.get(duration) + " and date(now()) ORDER BY attributes DESC limit " + Integer.parseInt(limit) + " ";
这是我尝试过的 -
private static void getValue(Map<String, String> newData) {
for(Map.Entry<String, String> entry : newData.entrySet()) {
String sql = "select * from testing where " +entry.getKey()+ " between " + dateMap.get(entry.getValue()) + " and date(now()) ORDER BY attributes DESC limit " + Integer.parseInt(limit) + " ";
}
}
但显然这是行不通的,因为它会一一迭代 Map 中的所有条目。有什么方法可以通用地使用地图生成上述字符串?
【问题讨论】:
-
一般使用地图是什么意思?您已将值与一些键值一起存储。您必须使用这些来获取与键关联的值。
-
一般我的意思是说,Map 可以有超过 2 个键值对。而且我需要同时使用地图键和值来制作 where 子句,而不仅仅是使用地图的值..