首页 \ 问答 \ JComboBox + JPA(JComboBox + JPA)

JComboBox + JPA(JComboBox + JPA)

考虑到java持久性API和JComboBox,我目前停留在Java问题上。

问题如下:

我有一个JDialog,我用它来添加一些东西到数据库中。

在该视图中:

cbGenre = new JComboBox();
cbPublisher = new JComboBox();

我想要的是在这两个组合框中,从List或ArrayList中加载值。 标准,从我发现,是一个组合框只接受一个字符串数组。 我还发现一个使用ArrayList的例子,我可以使用它。

现在主要的问题是:

我有2个表(只列出重要的列将被列出):

games
id pk int
genre int

genre
id pk int
name varchar

它们通过JPA以M:1的关系连接

所以一场比赛只能有一种类型
一种流派可以有一个或多个游戏

我将如何在相应的组合框中添加检索到的流派名称,并且当我按下保存按钮时,检索组合框中名称的ID和该名称的ID?

这是可能通过ArrayList,或者JCombobox不允许值对吗? 我想这样做的原因是,当我将游戏保存到数据库时,我需要将选定的流派ID添加到数据库中,显然,用户不应该看到一个ID,而应该看到Action或RPG以及什么不。

对不起,如果我的问题有点不清楚。 如果是这样,请告诉我,这样我可以尝试更好地解释它。

英语不是我的母语,你现在可能已经注意到了:)

感谢阅读,我希望能尽快找到解决方案。 与此同时,谷歌更多地浏览谷歌


I am currently stuck on a Java issue considering the java persistance API and JComboBox.

The issue is as follows:

I have a JDialog, whom I use to add something to the database.

In the view:

cbGenre = new JComboBox();
cbPublisher = new JComboBox();

What I want, is in these 2 combo boxes, to be loaded the values out of a List or ArrayList. Standard, from what I found out, was a combobox only accepting a String array. I also found one example that uses ArrayList, whom I can work with.

Now the main question is:

I have 2 tables(only columns that matter will be listed):

games
id pk int
genre int

genre
id pk int
name varchar

They are connected via JPA in a M:1 relationship

so one game can only have one genre
one genre can have one or more games

How will I go about to add the retrieved genre names in the appropriate combobox, and when I press the save button, retrieve both the id of the name in the combobox and the id of that name?

Is this possible via an ArrayList, or does a JCombobox not allow value pairs? The reason I want this, is when I save a game to the database, I need to have the selected genre id and add it to the database, and obviously, the user should not see an id, but rather Action, or RPG and what not.

Sorry if my question is a bit unclear. If it is, please do tell me so I can try to explain it better.

English is not my native tongue, whom you have probably noticed by now :)

Thanks for reading and I hope to find a solution soon. In the meantime ill browse trough google some more


原文:https://stackoverflow.com/questions/5270513
更新时间:2022-12-18 12:12

最满意答案

这应该工作:

someFunction(array){
    const promises = array.map((element, index) => {
        if(some checks hold){
            return asyncTask1(element).then(asyncTask2);
        }
        return normalSyncTask(element);
    });

    return Promise.all(promises).then((values) => {
        console.log('Everything is OK', values);
    });
}

使用Array.map生成一个promises数组,并等待使用Promise.all解析所有这些。

Promise.all将忽略不是promise的值,并返回promises会导致函数返回的values数组。


This should work:

someFunction(array){
    const promises = array.map((element, index) => {
        if(some checks hold){
            return asyncTask1(element).then(asyncTask2);
        }
        return normalSyncTask(element);
    });

    return Promise.all(promises).then((values) => {
        console.log('Everything is OK', values);
    });
}

You generate an array of promises using Array.mapand wait for all of them to be resolved using Promise.all.

The values that are not a promise will be ignored by Promise.all and be returned with the promises results in the values array returned by the function.

相关问答

更多

相关文章

更多

最新问答

更多
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)
  • 是否可以嵌套hazelcast IMaps?(Is it possible to nest hazelcast IMaps? And whick side effects can I expect? Is it a good Idea anyway?)
  • UIViewAnimationOptionRepeat在两个动画之间暂停(UIViewAnimationOptionRepeat pausing in between two animations)
  • 在x-kendo-template中使用Razor查询(Using Razor query within x-kendo-template)
  • 在BeautifulSoup中替换文本而不转义(Replace text without escaping in BeautifulSoup)
  • 如何在存根或模拟不存在的方法时配置Rspec以引发错误?(How can I configure Rspec to raise error when stubbing or mocking non-existing methods?)
  • asp用javascript(asp with javascript)
  • “%()s”在sql查询中的含义是什么?(What does “%()s” means in sql query?)
  • 如何为其编辑的内容提供自定义UITableViewCell上下文?(How to give a custom UITableViewCell context of what it is editing?)
  • c ++十进制到二进制,然后使用操作,然后回到十进制(c++ Decimal to binary, then use operation, then back to decimal)
  • 以编程方式创建视频?(Create videos programmatically?)
  • 无法在BeautifulSoup中正确解析数据(Unable to parse data correctly in BeautifulSoup)
  • webform和mvc的区别 知乎
  • 如何使用wadl2java生成REST服务模板,其中POST / PUT方法具有参数?(How do you generate REST service template with wadl2java where POST/PUT methods have parameters?)
  • 我无法理解我的travis构建有什么问题(I am having trouble understanding what is wrong with my travis build)
  • iOS9 Scope Bar出现在Search Bar后面或旁边(iOS9 Scope Bar appears either behind or beside Search Bar)
  • 为什么开机慢上面还显示;Inetrnet,Explorer
  • 有关调用远程WCF服务的超时问题(Timeout Question about Invoking a Remote WCF Service)