局部变量是否允许与全局变量同名?(Local variable is allowed the same name as global variable?)
我知道在某些情况下你可以有一个全局变量和一个具有相同名称的局部变量,例如
int i = 0; public Something(int i) { this.i = i; }
但是我很困惑为什么这样做。 我的代码看起来有点像这样
TableRowSorter dataSorter; //Global Variable public void setUpTable() { //Some Code dataSorter = new TableRowSorter(table.getModel()); table.setRowSorter(dataSorter); DefaultRowSorter dataSorter = (DefaultRowSorter) table.getRowSorter(); //Local Variable //Some More Code }
为什么允许
DefaultRowSorter
具有与TableRowSorter
相同的变量名?I am aware in certain circumstances you can have a global variable and a local variable which have the same name such as
int i = 0; public Something(int i) { this.i = i; }
However I am confused to why this works. My code looks a little like this
TableRowSorter dataSorter; //Global Variable public void setUpTable() { //Some Code dataSorter = new TableRowSorter(table.getModel()); table.setRowSorter(dataSorter); DefaultRowSorter dataSorter = (DefaultRowSorter) table.getRowSorter(); //Local Variable //Some More Code }
Why is the
DefaultRowSorter
allowed to have the same variable name asTableRowSorter
does?
原文:https://stackoverflow.com/questions/38283730
最满意答案
你可以使用JPQL查询来完成它。 您可以选择管理器并对具有
group by
或distinct
项目进行连接以消除重复项,或者可以在子查询中使用exists
。 如果您显示实体及其相关字段,我可以帮助您使用JPQL。You could do it with a JPQL query. You can select the managers and do a join on projects with a
group by
ordistinct
to eliminate duplicates, or you could useexists
in a subquery. I can help you with the JPQL if you show your entities and their relevant fields.
相关问答
更多-
这个问题已经在Hibernate论坛上提出并得到解答: https : //forum.hibernate.org/viewtopic.php?t= 954178&highlight = unidirectional+null+foriegn+foreign+ key 。 这似乎不是一个DB设计的问题,更多的是Hibernate的功能之一。 This question has been asked and answered on the Hibernate forums: https://forum.hib ...
-
在服务层或Web服务层(如果这是一个Web项目)创建除@Entity之外的两个不同的类作为DTO(数据传输对象),这有助于从一个层到另一个层的数据传输。 public class CustomerAccountEnduserOrderDetailsPojo { private List
productPojoList = new ArrayList<> (); // getter and setter } public class Custo ... -
您的存储过程应该看起来像这样。 SELECT [TeamName] FROM [Team] WHERE [TeamID] = @NewTeamID SELECT [PlayerName] FROM [Player] WHERE [TeamID] = @NewTeamID SELECT [SponsorName] FROM [Sponsor] WHERE [TeamID] = @NewTeamID 然后通过Consume Adapter Service生成模式。 您将获得具有三个记录集的模式,然 ...
-
由于公司和杂工pojos定义了与工作顺序的一对多关系,并且还设置了级联,更好的解决方案是:1。创建公司对象,设置值和工作订单对象的集合2.创建一个勤杂工的对象,设置值和工作订单对象的集合3.打开会话并以单批次保存1和2。 Since the company and handyman pojos define one to many relationship with workorder and also has cascade set to all, a better solution would be t ...
-
你的代码中有一个错字, userhome的小写字母h: @OneToMany(mappedBy = "userhome") private Set
keys; 应该是(大写H): @OneToMany(mappedBy = "userHome") private Set keys; 在像mappedBy这样的字段中引用的字段/属性应该具有JavaBean中字段的确切名称和大小写。 There is a typo in your code, the lowercase h in use ... -
你如何为一个人和一个地址的人添加地址? 由于您没有PersonAddress的域对象,因此对这些关系的编辑必须发生在Person或Address之一,不是吗? 如果是,那么审计是作为人员或地址审计的一部分进行的。 例如,在Person中: class Person { private List addedAddresses; private Set addresses; . . . public void addAddres ...
-
如何在Hibernate中获取所有具有一对多关系的记录?(How to get all records that have one-to-many relationships in Hibernate?)[2023-10-07]
你可以使用JPQL查询来完成它。 您可以选择管理器并对具有group by或distinct项目进行连接以消除重复项,或者可以在子查询中使用exists 。 如果您显示实体及其相关字段,我可以帮助您使用JPQL。 You could do it with a JPQL query. You can select the managers and do a join on projects with a group by or distinct to eliminate duplicates, or you ... -
好。 因此,您希望使用其品牌加载经销商,并且您只希望经销商的ID大于给定ID。 首先,你可以装载经销商。 当你调用getDealerMakes()时,Hibernate会自动加载它们的getDealerMakes() : Criteria c = session.createCriteria(Dealer.class); c.add(Restrictions.gt("dealerId", dealerId)); // let's say delerId = 6 List
dealers = ... -
我假设postProfile()方法接收一个Person实例,该实例仅包含该人员的ID,名称,地址等,由Web表单发布,但其书籍列表为null或为空。 而且你告诉Hibernate保存那个人。 因此,您有效地告诉Hibernate这个由给定ID标识的人有一个新名称,一个新地址,一个新电子邮件,......以及一个恰好为空的新书籍列表,并且应该保存进入数据库。 所以Hibernate做了你要告诉它的事情:它保存了人的新状态。 由于这个新人没有任何书,所以以前拥有的所有书籍都没有人拥有。 您必须从数据库中获取实 ...