惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
F
Fortinet All Blogs
D
Docker
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
WordPress大学
WordPress大学
罗磊的独立博客
Y
Y Combinator Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
J
Java Code Geeks
T
The Blog of Author Tim Ferriss
U
Unit 42
N
Netflix TechBlog - Medium
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
V2EX
云风的 BLOG
云风的 BLOG
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
Hugging Face - Blog
Hugging Face - Blog
Stack Overflow Blog
Stack Overflow Blog
爱范儿
爱范儿
酷 壳 – CoolShell
酷 壳 – CoolShell
P
Proofpoint News Feed
G
Google Developers Blog
H
Help Net Security

Mengke's blog - Mengke's coding journey

年轻不是健康的免死金牌 深圳工作机会,前端 2025 年终总结 Skill 不是 MCP 的替代品:我理解的渐进式披露与选型原则 独立开发者如何开具发票 香港银行卡开户完整指南(2025年9月最新) 招商银行储蓄卡微信动账提醒恢复方法 再谈 MCP - Model Context Protocol(MCP)详解和开发教程 Get Human-Readable "Time Ago" in TypeScript 以「asset-price-mcp」为例,从 0 开发 MCP Server Model Context Protocol (MCP) 快速开始 DeepSeek + Dify 搭建本地知识库 An elegant solution for implementing optional property types using TypeScript 2024 年终总结 Quickly Create a Fullscreen WebView with Autoplay Support for Testing 以数字开头的 ID 在 querySelector 中的处理 String casing utilities in JavaScript Check if a string is a valid color Simple Event-Emitter/PubSub pattern Find which process is running on a certain port and kill it Markdown Code block's basic and advanced syntaxes Common npm commands to use locally Pnpm aliases How to safely rename a case sensitive file/directory in a git repo? A custom hooks to use an async effect A custom hooks to use local storage state 🤩 Mengke'blog 上线的这一年 🗼 五月底去了一趟日本,记录一下我的游记和攻略 网站性能优化:如何高效预加载大型静态资源 闰年之约 - 2024年2月29日
Strapi 快速入门
Mengke · 2023-04-11 · via Mengke's blog - Mengke's coding journey

Postman sign.webp

Published on
/

3 mins read

/

––– views

Share:

1. 安装

npx create-strapi-app@latest my-project
# or
yarn create strapi-app my-project --quickstart

2. 设置为中文

新建 src/app.js,并粘贴以下内容:

const config = {
    locales: ['zh'],
};
 
const bootstrap = (app) => {
    console.log(app);
};
 
export default {
    config,
    bootstrap,
};

重启后进入网站首页,点击左下角头像→个人资料→体验→界面语言,调整为中文即可。

Untitled

3. 新建表

默认已经创建了 User 表,点击 创建一个新的 Content Type 来创建表新表:

Untitled

4. 创建关系

在一个表中新建一个字段,类型选择引用,可以选择关系的类型,包括1v1、1v多、多v1等等。下面是 User 多对一 Article :

Untitled

5. 放开 权限

设置 → 角色 → public

开放文章查询权限:

Untitled

开放文章作者查询权限,否则连表查询的时候查不到作者信息:

Untitled

6. 接口测试

http://localhost:1337/api/articles

会发现只查到了文章列表:

{
  "data": [
    {
      "id": 6,
      "attributes": {
        "content": "test1test1test1\n\n# test1test1",
        "title": "test1",
        "desc": "test1test1",
        "createdAt": "2023-04-11T03:41:59.599Z",
        "updatedAt": "2023-04-11T03:47:21.010Z",
        "publishedAt": "2023-04-11T03:42:00.405Z"
      }
    }
  ],
  "meta": {
    "pagination": {
      "page": 1,
      "pageSize": 25,
      "pageCount": 1,
      "total": 1
    }
  }
}

需要添加参数进行连表查询:

http://localhost:1337/api/articles?populate=*
{
  "data": [
    {
      "id": 6,
      "attributes": {
        "content": "test1test1test1\n\n# test1test1",
        "title": "test1",
        "desc": "test1test1",
        "createdAt": "2023-04-11T03:41:59.599Z",
        "updatedAt": "2023-04-11T06:16:17.782Z",
        "publishedAt": "2023-04-11T03:42:00.405Z",
        "user": {
          "data": {
            "id": 3,
            "attributes": {
              "username": "mkmk",
              "email": "[email protected]",
              "provider": "local",
              "confirmed": true,
              "blocked": false,
              "createdAt": "2023-04-11T02:51:19.930Z",
              "updatedAt": "2023-04-11T02:51:19.930Z"
            }
          }
        },
        "tags": {
          "data": [
            {
              "id": 1,
              "attributes": {
                "label": "testTag",
                "createdAt": "2023-04-11T03:47:12.104Z",
                "updatedAt": "2023-04-11T03:47:12.680Z",
                "publishedAt": "2023-04-11T03:47:12.679Z"
              }
            },
            {
              "id": 2,
              "attributes": {
                "label": "testTag2",
                "createdAt": "2023-04-11T06:16:08.647Z",
                "updatedAt": "2023-04-11T06:16:09.256Z",
                "publishedAt": "2023-04-11T06:16:09.255Z"
              }
            }
          ]
        }
      }
    }
  ],
  "meta": {
    "pagination": {
      "page": 1,
      "pageSize": 25,
      "pageCount": 1,
      "total": 1
    }
  }
}