gpt4 book ai didi

grails - 如何按给定日期/编号顺序保存addTo?

转载 作者:行者123 更新时间:2023-12-02 14:50:14 24 4
gpt4 key购买 nike

我需要一些有关API的帮助,当我在网络上时,订单保存正确,但是在API上时,一切都会出错:

def test = parseJSON.sort { a, b -> a.ID <=> b.ID } //or dateTime, will print the same
//order when I print each of them
[IDWeb:0, conductivity:0, ReportId:2, dissolvedOxygen:0, levelWater:1, ID:1, ph:0, redoxPotential:0, temperature:0]
[IDWeb:0, conductivity:0, ReportId:2, dissolvedOxygen:0, levelWater:0, ID:2, ph:0, redoxPotential:0, temperature:0]
[IDWeb:0, conductivity:0, ReportId:2, dissolvedOxygen:0, levelWater:0, ID:3, ph:0, redoxPotential:0, temperature:0]
[IDWeb:0, conductivity:0, ReportId:2, dissolvedOxygen:0, levelWater:4, ID:4, ph:0, redoxPotential:0, temperature:0]

test.each{
def sample = new SampleWater()
sample.levelWater = it.levelWater
sample.conductivity = it.conductivity
sample.dissolvedOxygen = it.dissolvedOxygen
sample.redoxPotential = it.redoxPotential
sample.ph = it.ph
sample.temperature = it.temperature
water.addToSamples(sample)
}
return water

我的问题是 addTo没有按顺序保存。我该如何解决?

最佳答案

确保已在List域类中将样本类型定义为Water,以便我们可以维护插入顺序:

class Water {

static hasMany = [samples: Sample]

List<Sample> samples = []
}

class Sample {

def levelWater
}

默认情况下, hasMany的实现为 Set类型,它不维护插入顺序,但负责唯一性。

从那时起,现在您的样本将按照插入时的顺序保存。

关于grails - 如何按给定日期/编号顺序保存addTo?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34276989/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com