简体   繁体   English

在 ReactJS MySQL Node.js 和 Express 中完成的论坛的查询问题

[英]Query issue for a forum done in ReactJS MySQL Node.js and Express

I am a junior developer and right now I'm building a simple forum using ReactJS, Node.js, Express and MySQL.我是一名初级开发人员,现在我正在使用 ReactJS、Node.js、Express 和 MySQL 构建一个简单的论坛。

In the forum each Topic must have many many Posts.在论坛中,每个主题必须有很多很多帖子。

I do not know if the problem comes from the back-end query or if it comes from the client side but the posts aren't well separated per topic.我不知道问题是来自后端查询还是来自客户端,但每个主题的帖子没有很好地分开。 Right now I have all the posts from the posts table in topic 1 and again in topic 2.现在,我拥有主题 1 和主题 2 中的帖子表中的所有帖子。

Test Page测试页

In the server folder here are my imports in index.js在服务器文件夹中,这是我在 index.js 中的导入

Server side imports服务器端导入

and here are my queries for Posts.这是我对帖子的查询。

Server side queries服务器端查询

Thank you for any help.感谢您的任何帮助。

Have a very nice day, Ana有一个非常愉快的一天,安娜

Your query seems ok, which will return all records by inner join with topics table.您的查询似乎没问题,它将通过与主题表的内部连接返回所有记录。 One more suggestion, use the below code to get the proper HTTP response code.还有一个建议,使用下面的代码来获得正确的 HTTP 响应代码。

return res.status(200).send(result);

Also, use try...catch to handle exceptions as well.此外,还可以使用 try...catch 来处理异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM