|
3 | 3 | import com.codingapi.springboot.fast.entity.Demo; |
4 | 4 | import com.codingapi.springboot.fast.entity.Profile; |
5 | 5 | import com.codingapi.springboot.fast.entity.User; |
| 6 | +import com.codingapi.springboot.fast.jpa.map.MapViewResult; |
| 7 | +import com.codingapi.springboot.fast.jpa.map.QueryColumnsContext; |
6 | 8 | import com.codingapi.springboot.fast.repository.DemoRepository; |
7 | 9 | import com.codingapi.springboot.fast.repository.ProfileRepository; |
8 | 10 | import com.codingapi.springboot.fast.repository.UserRepository; |
|
13 | 15 | import org.springframework.boot.test.context.SpringBootTest; |
14 | 16 | import org.springframework.data.domain.Page; |
15 | 17 |
|
| 18 | +import java.util.List; |
| 19 | + |
16 | 20 | import static org.junit.jupiter.api.Assertions.assertTrue; |
17 | 21 |
|
18 | 22 | @Slf4j |
@@ -59,6 +63,50 @@ void test1() { |
59 | 63 | } |
60 | 64 |
|
61 | 65 |
|
| 66 | + @Test |
| 67 | + void testMapQuery() { |
| 68 | + |
| 69 | + Demo demo = new Demo(); |
| 70 | + demo.setName("123"); |
| 71 | + demoRepository.save(demo); |
| 72 | + |
| 73 | + |
| 74 | + Profile profile = new Profile(); |
| 75 | + profile.setDemo(demo); |
| 76 | + profile.setName("123"); |
| 77 | + profileRepository.save(profile); |
| 78 | + |
| 79 | + |
| 80 | + User user = new User(); |
| 81 | + user.setName("li"); |
| 82 | + user.setProfile(profile); |
| 83 | + userRepository.save(user); |
| 84 | + |
| 85 | + assertTrue(demo.getId() > 0); |
| 86 | + assertTrue(user.getId() > 0); |
| 87 | + |
| 88 | + PageRequest request = new PageRequest(); |
| 89 | + request.addFilter("profile.demo.id", 1); |
| 90 | + |
| 91 | + String querySql = "from User u where u.profile.demo.id = ?1"; |
| 92 | + String countSQL = "from User u where u.profile.demo.id = ?1"; |
| 93 | + Page<MapViewResult> page = |
| 94 | + userRepository.dynamicMapPageQuery( |
| 95 | + QueryColumnsContext.build("u.id as iii","u.name"), |
| 96 | + querySql, |
| 97 | + countSQL, request, 1); |
| 98 | + List<MapViewResult> queryMaps = page.getContent(); |
| 99 | + System.out.println(queryMaps); |
| 100 | + |
| 101 | + List<MapViewResult> list = |
| 102 | + userRepository.dynamicMapListQuery( |
| 103 | + QueryColumnsContext.build("u.id as iii","u.name"), |
| 104 | + querySql, |
| 105 | + 1); |
| 106 | + System.out.println(list); |
| 107 | + |
| 108 | + } |
| 109 | + |
62 | 110 |
|
63 | 111 | @Test |
64 | 112 | void test2() { |
|
0 commit comments