I have the following database model
create table Diary (id bigint NOT NULL AUTO_INCREMENT,
creationDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
name varchar(255) not null,
description text,
viewtype varchar(255) not null,
member bigint,
primary key (id),
foreign key (member) references Member(id));
create table Page (id bigint NOT NULL AUTO_INCREMENT,
creationDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
viewtype varchar(255) not null,
diary bigint,
member bigint,
primary key (id),
foreign key (diary) references Diary(id),
foreign key (member) references Member(id));
create table Comment (id bigint NOT NULL AUTO_INCREMENT,
postingDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
comment text not null,
page bigint,
member bigint,
primary key (id),
foreign key (page) references Page(id)
foreign key (member) references Member(id));
I am using spring JDbc template.
My interface looks like follows: accountid is the memeberid in the database.
Collection<Diary> getDiaries(Long accountId);
And my diary is as follows:
public class Diary {
private Collection<Page> pages;
private Long id;
private LocalTime creationDate;
private String name;
private String description;
private ViewType type;
}
I wanted to know what the query would look like if I wanted to prepare a diary object using the jdbc template. You can also simply run only one request and simply prepare this Diary object, because I will avoid multiple requests for a single request. For the above interface, it is very possible that I will use the s join query or there is an easier way using the spring structure of the JDBC template.
source
share