【问题标题】:how to get data from database by sending a list?如何通过发送列表从数据库中获取数据?
【发布时间】:2017-03-28 15:17:40
【问题描述】:

有人可以通过发送列表来帮助我从数据库中的表中获取数据吗? `

List<CampaignStructure> campIdList = new ArrayList<>();  try {
        JSONArray clientjson = new JSONArray(campaignids);
        Set<Long> list = new HashSet<>();
        for(int i = 0; i < clientjson.length(); i++){
            list.add(Long.parseLong(clientjson.getJSONObject(i).getString("id")));
        }
        for(Long id: list){
            CampaignStructure c = new CampaignStructure();
            c.setCampaignId(id);
            campIdList.add(c);
        }
      } catch (JSONException e) {
      }

此处campaignids 包含 id 列表(可以包含重复项)。 campIdList 包含不同的 ID。我想发送这些 id 并从数据库中获取数据。

【问题讨论】:

  • 你写过数据库相关的代码吗?

标签: java mysql database spring


【解决方案1】:

findByCampaignIdIn(List campIdList) 应该可以工作。

您可以在current documentation listing. 中找到所有 JPA 存储库关键字列表

它表明 IsIn 是等价的 - 如果您更喜欢动词以提高可读性 - 而且 JPA 还支持 NotIn 和 IsNotIn。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-07
    • 1970-01-01
    • 2019-09-14
    • 1970-01-01
    • 2020-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多