java - 仅当字符串中有另一个元素时,如何才能使元素出现?以及如何使键显示为值?StringSubstitutor
问题描述
我有一个 HashMap 字符串,它以列名作为键,以列值作为值。
Map<String, String> columnValue = new HashMap<>();
columnValue.put("userId", "1");
columnValue.put("orderId", "2");
columnValue.put("carId", "3");
columnValue.put("orderDate", "2021-05-21 15:23");
StringSubstitutor sub = new StringSubstitutor(columnValue);
String query = "SELECT*FROM user_order Where ${userId} = ? AND ${orderId}=? AND ${carId}=?" +
"AND ${userAddress}=? AND ${userDestination}=? AND ${orderCost}=? AND date_format(${orderDate},'%Y-%m-%d %H:%i')=?";
首先,我需要如果具有列名的键存在于 HashMap 中,它将出现在行中,而不是值中。其次,我需要确保如果列名是字符串,那么它后面会出现“and”这个词,除了最后一个元素。如何使用 Apache 的 StringSubstitutor 来做到这一点?
解决方案
推荐阅读
- google-maps - 如何在谷歌地图颤动中获取当前相机位置latlng
- android - 安卓wordpress自动fcm通知收不到
- javascript - JavaScript 动态加载脚本文件以创建一个对象,然后在该对象上运行 .init()
- wordpress - 自定义帖子类型的多个用户角色
- sql - 更改 SQL 中列的显示顺序
- next.js - Nextjs 和工作箱集成
- angular - 有什么方法可以在 Ag-Grid(Angular)中使用 API 调用中的 coldefs 字段值?
- angular - GitLab 管道因异常而失败:无法读取未定义的属性“减号”
- ruby - 有没有办法使用 RuboCop 进行增量 linting?
- c# - .NET 应用程序在错误的位置寻找运行时