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 gamesHow 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
最满意答案
这应该工作:
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.map
and wait for all of them to be resolved usingPromise.all
.The values that are not a promise will be ignored by
Promise.all
and be returned with the promises results in thevalues
array returned by the function.
相关问答
更多-
这应该工作: someFunction(array){ const promises = array.map((element, index) => { if(some checks hold){ return asyncTask1(element).then(asyncTask2); } return normalSyncTask(element); }); return Promise.all(promis ...
-
如何妥善处理承诺?(how to properly handle promises?)[2019-12-08]
查看ODataAngularResources的文档, 请尝试以下操作: var measure = $odataresource("http://windows-10:8888/ChangeMeasure/"); var myMeasure = measure.odata().filter("ID",$scope.ngData[index].ID) .query(function(data){ data[0].$updat ... -
检查https://github.com/kriskowal/q ,我想如果你有多个承诺要解决那么你可以使用Q的“全部”方法 例子: Q.all([ fooPromise1(), fooPromise2() ]); check https://github.com/kriskowal/q, i think if you have multiple promises to resolve then you can use "all" method of Q example : Q.all([ fooProm ...
-
刚刚发现如何在这种特殊情况下使用promises来做到这一点。 Mongoose有一个函数findOneAndUpdate( http://mongoosejs.com/docs/api.html#model_Model.findOneAndUpdate ),它按预期工作。 CastError通过拒绝传递。 这样我就可以在没有try / catch块的情况下处理错误。 这是代码(PermissionRepository.js): module.exports.updatePermission = funct ...
-
这是我处理这个... Parse.Cloud.define("xxx", function(request, response) { var channels = ["channel1", "channel2", "channel3", "channel4", "channel5"]; var queries = new Array(); for (var i = 0; i < channels.length; i++) { var query = ...
-
使用Q / promises与回调(Using Q/promises vs callbacks)[2023-08-18]
我喜欢承诺的原因之一是处理错误是多么容易。 在您的情况下,如果其中任何一个promise失败,它将被您定义的fail子句捕获。 如果要在现场处理它们,可以指定更多的fail子句,但这不是必需的。 作为一个简单的例子,有时我想处理错误并返回其他内容而不是传递错误。 我会做这样的事情: function awesomeFunction() { var fooPromise = getFoo().then(function() { return 'foo'; }).fail(fun ... -
您可以将标识符返回给承诺 const promises = []; const promiser = (number, id) => new Promise((resolve, reject) => window.setTimeout(() => resolve({ number, id }), number * 100)); for (let index = 0; index < 10; index++) { const promise = promiser(index, "id_" + index) ...
-
如何处理嵌套的承诺?(How to handle nested promises?)[2021-08-03]
您不必nest这些承诺,您可以执行以下操作: function start_it_all(){ return $cordovaSQLite.execute(db, "SELECT foo FROM bar") .then(function(result) { return $http.get('foo.php'); }) .then(function(){ // Here I get some data }); } 基于原始问 ... -
有几种方法可以实现你想要的 对代码的最小更改将是 function multiplePromises(targetArray) { var promises = []; var p = Promise.resolve(); // I don't know the Q equivalent of this for (var i=0; i
如何在NodeJS中使用Promises(Bluebird)处理条件回调(How to handle conditional callbacks using Promises(Bluebird) in NodeJS)[2021-02-14]
没有魔法,你可以轻松地将承诺与承诺中的return挂钩。 var promise = Collection1.find({ condn: true }).exec(); //first approach promise.then(function(val) { if(val){ return gotoStep2() .then(function(result) { //handle result from gotoStep2() ...相关文章
更多- jpa与hibernate注解混合使用
- JPA环境配置
- Spring +JPA 多持久化单元 怎么配置
- JPA ORM框架介绍
- JPA高级映射(继承)
- spring 3.0 和jpa 整合 用jboss
- JPA 增删改查入门示例
- JPA一对多、一对一、多对一、多对多实体关系
- 传智播客JPA详解视频教程
- JPA JPQL 工作原理与持久性
最新问答
更多- 散列包括方法和/或嵌套属性(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)