Controller.java
===============
@Autowired
private Service Service;
@ApiHeader(
apiOperation = "get all Content Manage",
apiOperationNotes = "get all Content Manage"
)
@GetMapping(value = UriConstants.CONTENT_MANAGE_QUERY,produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<CMListResponse> queryAllCM(
@RequestHeader HttpHeaders apiRequest){
CMListResponse response = CMService.queryAllCM();
return ResponseEntity.ok(response);
}
CMListResponse.java
==============================
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CMListResponse {
List<CMVO> contents;
}
CMVO.java
=====================
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CMVO {
private static final long serialVersionUID = 92012330342289044L;
@ApiModelProperty(value = "id", example = "123")
@JsonProperty(value = "id")
private int id;
@ApiModelProperty(value = "position", example = "123")
@JsonProperty(value = "position")
private int position;
@ApiModelProperty(value = "title", example = "desc")
@JsonProperty(value = "title")
private String title;
@ApiModelProperty(value = "shortDescription", example = "shortDescription")
@JsonProperty(value = "shortDescription")
private String shortdescription;
@ApiModelProperty(value = "thumbnailimage", example = "thumbnailimage")
@JsonProperty(value = "thumbnailimage")
private String thumbnailimage;
@ApiModelProperty(value = "linkactions", example = "linkactions")
@JsonProperty(value = "linkactions")
private String linkactions;
/*@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")*/
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX")
@ApiModelProperty(value = "last_updated_date", example = "2021-03-17T02:59:24.120Z")
@JsonProperty(value = "last_updated_date")
private ZonedDateTime last_updated_date;
@ApiModelProperty(value = "last_updated_by", example = "A9002255")
@JsonProperty(value = "last_updated_by")
private String last_updated_by;
@ApiModelProperty(value = "countryid", example = "3023D08B-D861-4514-8E13-FFCF97A3D1DD")
@JsonProperty(value = "countryid")
private String countryid;
@ApiModelProperty(value = "countryName", example = "Singapore")
@JsonProperty(value = "countryName")
private String countryName;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX")
@ApiModelProperty(value = "date_published", example = "2021-03-17T02:59:24.120Z")
@JsonProperty(value = "date_published")
private ZonedDateTime date_published;
@Override
public String toString() {
return "CMVO{" +
"id=" + id +
", position=" + position +
", title='" + title + '\'' +
", shortdescription='" + shortdescription + '\'' +
", thumbnailimage='" + thumbnailimage + '\'' +
", linkactions='" + linkactions + '\'' +
", last_updated_date=" + last_updated_date +
", last_updated_by='" + last_updated_by + '\'' +
", countryid='" + countryid + '\'' +
", countryName='" + countryName + '\'' +
", date_published=" + date_published +
'}';
}
}
service.java
=============
private Repository repository;
@Autowired
public CMService(Repository Repository) {
this.Repository = Repository;
}
public CMListResponse queryAllCM() {
List<CCDTO> CMList =
Repository.fetchAllCMData();
List<CMVO> CMVOList = new ArrayList<>();
for (CCDTO CM : CMList) {
CMVO CMVO = new CMVO();
BeanUtils.copyProperties(CM,CMVO);
CMVOList.add(CMVO);
}
return CMListResponse.builder().contents(CMVOList).build();
}
CCDTO.java
==========
@Setter
@Getter
@Builder
@AllArgsConstructor
public class CCDTO {
private int id;
private int position;
private String title;
private String shortdescription;
private String thumbnailimage;
private String linkactions;
private ZonedDateTime last_updated_date;
private String last_updated_by;
private String countryid;
private String countryName;
private ZonedDateTime date_published;
@Override
public String toString() {
return "CCDTO{" +
"id=" + id +
", position=" + position +
", title='" + title + '\'' +
", shortdescription='" + shortdescription + '\'' +
", thumbnailimage='" + thumbnailimage + '\'' +
", linkactions='" + linkactions + '\'' +
", last_updated_date=" + last_updated_date +
", last_updated_by='" + last_updated_by + '\'' +
", countryid='" + countryid + '\'' +
", countryName='" + countryName + '\'' +
", date_published=" + date_published +
'}';
}
}
repository.java
===============
@Transactional(rollbackFor = Exception.class)
@Query("select new com.model.entity.CCDTO (A.id, A.position ,A.title," +
"A.shortdescription,A.thumbnailimage, A.linkactions, A.last_updated_date, A.last_updated_by, " +
"A.country.countryId, A.country.countryName, A.date_published) " +
"from CM as A inner join A.country as B order by A.id asc")
List<CCDTO> fetchAllCMData();