我正在使用loopback-4构建一个API,在一个模型中有一个名为"day“的属性,它是一个Date类型( MySQL列也是Date类型)。但是我不能向它发布像"2019-09-09“这样的值,因为它想要像"2019-09-09T12:41:05.942Z”这样的值。我如何指定它必须是一个日期(没有时间)?
我很困惑,因为您可以在查询参数(类型为date)中传递"2019-09-09“,但不能在模型中传递
我目前在模型中有这样的属性:
@property({
type: Date,
required: true,
mysql: {
columnName: 'day',
dataType: 'date',
dataLength: null,
dataPrecision: null,
dataScale: null,
nullable: 'N',
},
})
day: Date;预期:接受"2019-09-09“作为值
实际: 422:日期应与\“日期-时间\”格式匹配
发布于 2021-03-16 23:05:28
我也遇到过同样的问题,我使用jsonSchema来指定请求JSON的格式来解决这个问题。
在您的示例中,您必须通过以下方式更改代码:
@property({
type: 'date', // Types in LoopBack4 are not case-sensitive so Date is the same than date
jsonSchema: {
format: 'date', //This can be changed to 'date-time', 'time' or 'date'
},
required: true,
mysql: {
columnName: 'day',
dataType: 'date',
dataLength: null,
dataPrecision: null,
dataScale: null,
nullable: 'N',
},
})
day: string; // Change this also发布于 2020-05-04 17:01:04
类型应更改为'date',而不是Date。这将允许更灵活的日期模式:
@property({
type: 'date',
required: true,
mysql: {
columnName: 'day',
dataType: 'date',
dataLength: null,
dataPrecision: null,
dataScale: null,
nullable: 'N',
},
})
day: string;https://stackoverflow.com/questions/57854413
复制相似问题