Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对存在one to many关系的两个类,应该如何设计上传的API #22

Open
szlghl1 opened this issue May 1, 2017 · 3 comments
Open

Comments

@szlghl1
Copy link

szlghl1 commented May 1, 2017

有两个类Menu和MenuItem,他们是one to many的结构
image
image

我要如何设计上传的API才能在上传的时候创建出关系?比较坑的是Hibernate自动做one to many关系的时候foreign key是被隐藏起来的,这样最简单的上传MenuItem -> 得到后台generate的key -> 将key list嵌入到menu的json里面上传的方法是行不通的

@hackjutsu
Copy link
Member

@szlghl1
Copy link
Author

szlghl1 commented May 2, 2017

这个post是通过手动new来创建的,不过我有点思路了,应该先create menu,然后返回id,然后upload menu item的时候不能用自带的json parser,必须手动创建一个通过menu id来指定one to many关系的json格式,然后在controller里面query 出该menu再add。听着很不简洁但是应该可以work,明天试试

@szlghl1
Copy link
Author

szlghl1 commented May 10, 2017

update:有人提醒我可以用jpa的cascade annotation,我查了一下手册似乎可行

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants