I am creating an API by using spring boot. In this project, I used spring web, JPA, jstl and MySql as dependencies of the API. In this project, I have created a Controller,
You can create an object by using the columns as parameters for a constructor.
I'll give you an example of my own with a custom DTO I made:
@Query("SELECT new org.twinnation.site.dto.TitleAndDescriptionAndId(a.title, a.description, a.id) "
+ "FROM Article a")
List getAllArticlesWithoutContent();
Where the DTO TitleAndDescriptionAndId
is the following:
public class TitleAndDescriptionAndId {
private String title;
private String description;
private Long id;
public TitleAndDescriptionAndId(String title, String description, Long id) {
this.title = title;
this.description = description;
this.id = id;
}
// ...
}