如何通过列表保存到数据库中,使用play framework ebean? [英] How to save through a list into the Database, using play Framework ebean?

查看:177
本文介绍了如何通过列表保存到数据库中,使用play framework ebean?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过副标题列表保存,但具有相同的部门ID,但是subheadDepartmentID不同。我如何去做呢?

I'm trying to save through a list of subheads but with the same Department Id but different subheadDepartmentID. How do i Go about it?

subHeadDepartment.department= department;
    for(String thissubhead: ConstructedList){
         SubHead subHead = SubHead.retrievebyName(thissubhead);
         subHeadDepartment.subhead=subHead;
         subHeadDepartment.save();
        }

我在这里的代码只更新循环中的第一个subheadDepartment Id。虽然我想要的是为每个输入的子头创建一个subheaddepartmentId,但所有将在DB.Thanks中有相同的departmentId

The code I have here is updating just the first subheadDepartment Id in the loop.While what i want is to create a subheaddepartmentId for each subhead entered but all will have same departmentId in the DB.Thanks

推荐答案

需要为要创建的每个元素创建一个SubHeadDepartment的新实例:

You need to create a new instance of SubHeadDepartment for each element you want to create:

for(String thissubhead: ConstructedList){
     SubHead subHead = SubHead.retrievebyName(thissubhead);
     SubHeadDepartment subHeadDepartment = new SubHeadDepartment();
     subHeadDepartment.department = department;
     subHeadDepartment.subhead = subHead;
     subHeadDepartment.save();
    }

这篇关于如何通过列表保存到数据库中,使用play framework ebean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆