如何在前端和后端实现问答逻辑
在我的网站上,我将展示一个主要问题和一些答案。
因此,如果用户单击其中一个答案,我将再次显示一些问题列表以及相应的答案。因此每个答案都会再次出现某些问题。这个过程一直持续到出现没有问题的答案为止。我怎样才能在java的服务器端以及html端最有效地做到这一点。我如何将这个结构存储在某个模型中。
如果有人知道实现此逻辑的任何类型的开源项目,请提供帮助。
In my website I am gonna show a main question with some answers.
So if the user clicks one of the answers I am gonna show some list of questions again with respective answers.So each answers has got certain questions again .This process goes on till there is a answer which has got no questions. How I can i do it most efficiently on the server side in java as well as on the html side . How can i store this structure in some model.
If anybody knows any kind of opensource project which implement this logic please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,您需要一棵树:
在 Java 中,您可以这样表示:
要创建这些对象的完整树,您需要
提供每个属性采用一个参数的构造函数
在这种情况下,您需要从叶子向上构建树(因为除非您已经创建了中间节点,否则您无法提供中间节点及其参数)
创建“setter”方法,创建所有问题并将适当的孩子“设置”在他们应该在的位置。 (这将允许您从根到叶构建树。)
其他替代方案:
如果您想在多个位置重用树的部分内容(即,如果有多个答案),则可以使用 DAG(有向无环图)导致相同的答案)
如果您愿意,可以使用普通有向图允许问题系统中存在循环。
无论哪种方式,我上面描述的两个类都符合要求!
It sounds to me like you would need a tree:
In Java you would could represent it like this:
To create a full tree of these objects, you need to either
Provide constructors that takes one argument per attribute
In such case you need to build the tree from the leaves up (since you can't provide intermediate nodes with their arguments unless you've already created them)
Create "setter"-methods, create all questions and "set" the appropriate children where they are supposed to be. (This would allow you to build the tree from root to leaves.)
Other alternatives:
You could use a DAG (directed acyclic graph) if you would like to reuse parts of the tree in several places (i.e., if several answers leads to the same answer)
You could use an ordinary directed graph if you would like to allow for cycles in the question system.
In either way the two classes I described above fits the bill!