|
| 1 | +package com.codingapi.springboot.fast; |
| 2 | + |
| 3 | +import com.codingapi.springboot.fast.entity.Demo; |
| 4 | +import com.codingapi.springboot.fast.repository.DemoRepository; |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | +import org.springframework.beans.factory.annotation.Autowired; |
| 7 | +import org.springframework.boot.test.context.SpringBootTest; |
| 8 | +import org.springframework.data.domain.Page; |
| 9 | +import org.springframework.data.domain.PageRequest; |
| 10 | + |
| 11 | +import java.util.Arrays; |
| 12 | +import java.util.List; |
| 13 | +import java.util.Map; |
| 14 | + |
| 15 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 16 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 17 | + |
| 18 | +@SpringBootTest |
| 19 | +public class JdbcQueryTest { |
| 20 | + |
| 21 | + @Autowired |
| 22 | + private DemoRepository demoRepository; |
| 23 | + |
| 24 | + |
| 25 | + @Test |
| 26 | + void test() { |
| 27 | + demoRepository.deleteAll(); |
| 28 | + Demo demo = new Demo(); |
| 29 | + demo.setName("123"); |
| 30 | + demoRepository.save(demo); |
| 31 | + assertTrue(demo.getId() > 0); |
| 32 | + |
| 33 | + String sql = "select d.* from t_demo as d where d.id in (d.id,?,?)"; |
| 34 | + String countSql = "select count(d.id) from t_demo as d where d.id in (d.id,?,?)"; |
| 35 | + PageRequest pageRequest = PageRequest.of(0, 10); |
| 36 | + |
| 37 | + List<Integer> params = Arrays.asList(demo.getId(), demo.getId()); |
| 38 | + Page<Map<String, Object>> page = demoRepository.dynamicNativeMapPageMapQuery( |
| 39 | + sql, countSql, pageRequest, params.toArray() |
| 40 | + ); |
| 41 | + assertEquals(page.getTotalElements(), page.getContent().size()); |
| 42 | + } |
| 43 | + |
| 44 | +} |
0 commit comments