我试图将菜单或菜单项的菜单安装到数据库中(递归地设计组件模式)。
如果还有其他方法可以实现,请告诉我。
void insertmenu (Menu menu){
PreparedStatement statement = connection.prepareStatement("INSERT INTO `menu` VALUES (NULL, ?, ?, ?)");
statement.setString(1, menu.getName());
statement.setDate(2, java.sql.Date.valueOf(menu.getLocalDate(menu.getDate())));
statement.setInt(3, menu.getParent_id());//--> problem that this value always is null bec it isn't created yet
for (MenuList child : menu.getChildren()) {
int x= child.getType();
if (x==0){
insertMenu((Menu) child);
}else {
MySqlMenuItemDAO a = new MySqlMenuItemDAO();
a.insertMenuItem((MenuItem) child);
}
}
int res = statement.executeUpdate();
}