Java 一对多Spring结果映射
这是我第一次发布问题,希望有人能帮助我将结果映射到:Java 一对多Spring结果映射,java,spring,spring-boot,jdbc,Java,Spring,Spring Boot,Jdbc,这是我第一次发布问题,希望有人能帮助我将结果映射到: List<Clients> 这是我的模式(java类) Name.java private int NameId; private String ClientName; .. getter and setter private int NotesId; private String ClientNote; .. getter and setter private Name name; private List<Note
List<Clients>
这是我的模式(java类)
Name.java
private int NameId;
private String ClientName;
.. getter and setter
private int NotesId;
private String ClientNote;
.. getter and setter
private Name name;
private List<Notes> notes;
.. getter and setter
class ClientResultSet implements ResultSetExtractor<List<Clients>>{
@Override
public List<Clients> extractData(ResultSet rs) throws SQLException, DataAccessException {
Map<int, Clients> map = new HashMap<int, Clients>();
while(rs.next()) {
int NameId= rs.getInt("NameId");
Clients clients= map.get(contactId);
if (clients== null) {
// I'm losing my thoughts here. :'(
}
}
return null;
}
}
Notes.java
private int NameId;
private String ClientName;
.. getter and setter
private int NotesId;
private String ClientNote;
.. getter and setter
private Name name;
private List<Notes> notes;
.. getter and setter
class ClientResultSet implements ResultSetExtractor<List<Clients>>{
@Override
public List<Clients> extractData(ResultSet rs) throws SQLException, DataAccessException {
Map<int, Clients> map = new HashMap<int, Clients>();
while(rs.next()) {
int NameId= rs.getInt("NameId");
Clients clients= map.get(contactId);
if (clients== null) {
// I'm losing my thoughts here. :'(
}
}
return null;
}
}
Clients.java
private int NameId;
private String ClientName;
.. getter and setter
private int NotesId;
private String ClientNote;
.. getter and setter
private Name name;
private List<Notes> notes;
.. getter and setter
class ClientResultSet implements ResultSetExtractor<List<Clients>>{
@Override
public List<Clients> extractData(ResultSet rs) throws SQLException, DataAccessException {
Map<int, Clients> map = new HashMap<int, Clients>();
while(rs.next()) {
int NameId= rs.getInt("NameId");
Clients clients= map.get(contactId);
if (clients== null) {
// I'm losing my thoughts here. :'(
}
}
return null;
}
}
我正在阅读ResultsTextRactor,但我不知道如何实现它。提前感谢,祝您愉快。这就是您的数据库的外观,您将创建4个表,client、name、note、client\u note。client_note表应具有一对多关系的client id和note id。因此,如果您想要获取id为1的客户机的所有注释;您的sql将如下所示
SELECT note_id FROM client_note WHERE clientId = 1;
然后,您可以使用获得的注释id查询注释表中的实际注释对象
client
int id;
int nameId (foreignKey referencing name.id);
name
int id;
String ClientName;
note
int id;
String ClientNote;
client_note
int id;
int clientId (foreignKey referencing client.id);
int noteId (foreignKey referencing note.id);
希望这有帮助?这就是您的数据库的外观,您将创建4个表,client、name、note、client\u note。client_note表应具有一对多关系的client id和note id。因此,如果您想要获取id为1的客户机的所有注释;您的sql将如下所示
SELECT note_id FROM client_note WHERE clientId = 1;
然后,您可以使用获得的注释id查询注释表中的实际注释对象
client
int id;
int nameId (foreignKey referencing name.id);
name
int id;
String ClientName;
note
int id;
String ClientNote;
client_note
int id;
int clientId (foreignKey referencing client.id);
int noteId (foreignKey referencing note.id);
希望这能有所帮助?我想每个人都误解了我的问题,我不会责怪每个人。我喜欢我的问题得到关注,我感谢所有给我建议的人 如果有人和我有同样的问题,我在这里找到了答案:
再次感谢大家,祝你们度过愉快的一天。我想每个人都误解了我的问题,我不会责怪每个人。我喜欢我的问题得到关注,我感谢所有给我建议的人 如果有人和我有同样的问题,我在这里找到了答案:
再次感谢大家,祝你们度过愉快的一天。你们是否使用了hibernate或eclipselink之类的ORM?我不知道ORM是什么,但我在Eclipse-EE中使用了Spring。你们是否使用了hibernate或eclipselink之类的ORM?我不知道ORM是什么,但我在Eclipse EE中使用了Spring。