TIMESTAMP
简介
校验参数值是否为日期时间格式
示例
Tested on Luwak 1.11
数据字典
hrm.sys_tasks 人力资源系统 - 系统任务表
列名 | 数据类型 | 非空 | 自增 | 键 | 描述 |
---|---|---|---|---|---|
id | int(11) | 是 | 是 | 主键 | - |
title | varchar(255) | 是 | - | - | 任务标题 |
completed | tinyint(1) | - | - | - | 任务是否完成 |
start_time | timestamp | - | - | - | 任务开始时间 |
end_time | timestamp | - | - | - | 任务结束时间 |
-
创建 hrm.sys_tasks 任务表
DROP TABLE IF EXISTS hrm.sys_tasks;
CREATE TABLE hrm.sys_tasks
(
id INT PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
completed BOOLEAN COMMENT '0未完成 1完成 data_type=bool',
start_time TIMESTAMP,
end_time TIMESTAMP
); -
表注释
data_type=bool
表示允许1
,0
参数映射和校验
校验规则
- completed 只能是数字 1 或 0
- title 必填项
- id 可选,如果传了 id 参考主键约束
- start_time 是日期时间,如 "2023-11-01 08:00:00"
- end_time 是日期时间,如 "2023-11-01 09:00:00"
请求
POST http://127.0.0.1:21000
Content-Type: application/json;charset=utf-8
{
"jsonrpc": "2.0",
"method": "hrm.sysTasks.add",
"params": {
"title": "testing timestamp type",
"completed": 1,
"startTime": "2023-11-01",
"endTime": "2023-11-01"
},
"id": "client-unique-request-id"
}
响应
HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
{
"jsonrpc": "2.0",
"error": {
"code": -32602,
"message": "validating data type: endTime: 2023-11-01 does not validate as timestamp;startTime: 2023-11-01 does not validate as timestamp",
"data": {
"errorCode": "EU.Validator.DataTypeError",
"errorDetails": [
{
"field": "startTime",
"fieldValue": "2023-11-01",
"location": "hrm.sys_tasks",
"message": "startTime: 2023-11-01 does not validate as timestamp",
"validator": "timestamp"
},
{
"field": "endTime",
"fieldValue": "2023-11-01",
"location": "hrm.sys_tasks",
"message": "endTime: 2023-11-01 does not validate as timestamp",
"validator": "timestamp"
}
],
"errorMessage": "endTime: 2023-11-01 does not validate as timestamp;startTime: 2023-11-01 does not validate as timestamp"
}
},
"id": "client-unique-request-id"
}
备注: 以上示例在Luwak 1.12.9测试通过。