无法通过 ID 找到一条记录(404 未找到),但可以在 Strapi 5 中找到样本数据的所有记录

问题描述 投票:0回答:1
  • Strapi 版本:5.0.2 社区
  • 操作系统:Windows 11 专业版 23H2(操作系统内部版本 22631.4249)
  • 数据库:sqlite
  • 节点版本:v20.17.0
  • NPM 版本:10.8.3
  • 纱线版本:1.22.22

我使用以下命令新安装了 Strapi,并选择创建示例数据。

纱线创建带子

我发布了所有文章,并仔细检查了 find 和 findOne 权限是否已授予作者数据的公共角色。

我使用Google Chrome查询作者记录。

我可以通过这个URL获取所有作者记录: http://localhost:1337/api/authors

    {
        "data": [
            {
                "id": 1,
                "documentId": "j32zwfrmo0h7ed5fk51qb1is",
                "name": "David Doe",
                "email": "[email protected]",
                "createdAt": "2024-10-03T14:54:43.775Z",
                "updatedAt": "2024-10-03T14:54:43.775Z",
                "publishedAt": "2024-10-03T14:54:43.772Z",
                "locale": null
            },
            {
                "id": 2,
                "documentId": "d7tjdbzbakg83kgnxe7818fi",
                "name": "Sarah Baker",
                "email": "[email protected]",
                "createdAt": "2024-10-03T14:54:44.657Z",
                "updatedAt": "2024-10-03T14:54:44.657Z",
                "publishedAt": "2024-10-03T14:54:44.652Z",
                "locale": null
            }
        ],
        "meta": {
            "pagination": {
                "page": 1,
                "pageSize": 25,
                "pageCount": 1,
                "total": 2
            }
        }
    }

但是,我无法从下面的 URL 获取任何单独的记录,并且会抛出 404 未找到错误。

http://localhost:1337/api/authors/2

{
    "data": null,
    "error": {
        "status": 404,
        "name": "NotFoundError",
        "message": "Not Found",
        "details": {}
    }
}

我没有对此作者集合类型进行自定义。

Gift集合的控制器./src/api/author/controllers/author.ts如下:

/**
 *  author controller
 */

import { factories } from '@strapi/strapi';

export default factories.createCoreController('api::author.author');

我错过了什么步骤吗?

strapi
1个回答
0
投票

尝试使用

documentId
属性值而不是
id

http://localhost:1337/api/authors/d7tjdbzbakg83kgnxe7818fi
在你的情况下。

© www.soinside.com 2019 - 2024. All rights reserved.