JPA ORM을 이용한 @Query의 결과값을 Map, JSON형식으로 바로 만들어주는 방법은 2가지가 있다
1. Map을 이용한다.
2. DTO(POJO, VO)를 생성하여 이용한다.
JPA EntityManager를 이용한 Map형식으로 Mapping하는 방법은 아래 링크에 있다.
1. 2018/10/28 - [Develop/Spring Boot] - Spring boot JPA EntityManager를 이용한 Map형식으로 mapping하기
Spring Boot Json익히기
Spring boot Json 1편, 2편, 3편, 4편, 마지막
1. 2018/11/06 - [Develop/Spring Boot] - Spring Boot Json, JsonObject로 만들기 - JSON 1편
3. 2018/11/09 - [Develop/Spring Boot] - Spring Boot Json, Jackson을 이용한 JsonParsing - Json 3편
5. 2018/11/13 - [Develop/Spring Boot] - Spring Boot Json, hashmap to json , JsonObject 만들기- JSON 마지막
Spring boot에서 MySQL JSON 타입 SELECT하는 방법
1. 2018/11/30 - [Develop/Spring Boot] - Spring boot MySQL JSON - MySQL JSON DATA TYPE 값 가져오기
1. Map을 이용.
(html편집기가 자꾸 안되서 사진으로 대체합니다)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | public class TestDTO{ private String id; private String password; public TestDTO(){} public Test(String id, String password){ this .id = id; this .password=password; } public String getId(){ return id; } public void setId(String id){ this .id =id; } public String getPassword(){ return password; } public void setPassword(String password){ this .password =password; } } |
1 2 3 4 5 6 7 8 | @Query ( "select new net.test.com.TestDTO(t.test_id, t.test_password) from Test t" ) List<testdto> test(); //위의 값을 가져오는 방법. List<testdto> t = testDAO.test(); t.getId() </testdto></testdto> |
'Develop > Spring Boot' 카테고리의 다른 글
Spring boot JPA EntityManager를 이용한 Map형식으로 mapping하기 (0) | 2018.10.28 |
---|---|
Spring Boot AWS Elastic BeanStalk을 이용한 배포 (0) | 2018.10.26 |
application.properties에 작성안하고 Run Configuration에 설정하기 (0) | 2018.10.26 |
Spring boot 커맨드라인으로 profile 또는 외부 properties시 주의사항. (0) | 2018.10.23 |
Spring boot Log 개발용 로그, 배포용 로그 profile 설정 (1) | 2018.10.23 |