1 |
List<Object[]> resultList = query.getResultList(); |
이런 형태로 결과값이 나오는 경우가 있다.
이 값을 responseDto형태의 클래스를 미리 선언해서 받는 경우
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
@Data public class CommonIdNameCntDto implements Serializable { @Min(0) private int cnt; @NotNull private Long id; @NotNull @Size(min = 1) private String name; @Setter(AccessLevel.PRIVATE) private int i = 0; public void orderedSet(Object object){ switch (i){ case 0: this.cnt = (int) object; break; case 1: setId((Long) object); break; case 2: setName((String) object); break; default: throw new IllegalArgumentException("no more field"); } } i++; } |
orderedSet형태로 선언을 해두면 그냥 세터선언해서 foreach로 받는다.