From 8066b17c491d288928d7304719a0a5a44fceff47 Mon Sep 17 00:00:00 2001 From: mazhicheng Date: Sat, 20 Jun 2020 12:59:43 +0800 Subject: [PATCH] =?UTF-8?q?BindQuery=E6=94=AF=E6=8C=81between=E7=BB=91?= =?UTF-8?q?=E5=AE=9AList?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/diboot/core/binding/QueryBuilder.java | 9 ++++++++ .../core/test/service/BaseServiceTest.java | 23 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java b/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java index f7454cb..4c039a7 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java @@ -230,6 +230,15 @@ public class QueryBuilder { wrapper.between(columnName, valueArray[0], valueArray[1]); } } + else if(value instanceof List){ + List valueList = (List)value; + if(valueList.size() == 1){ + wrapper.ge(columnName, valueList.get(0)); + } + else if(valueList.size() >= 2){ + wrapper.between(columnName, valueList.get(0), valueList.get(1)); + } + } // 支持逗号分隔的字符串 else if(value instanceof String && ((String) value).contains(",")){ Object[] valueArray = ((String) value).split(","); diff --git a/diboot-core/src/test/java/diboot/core/test/service/BaseServiceTest.java b/diboot-core/src/test/java/diboot/core/test/service/BaseServiceTest.java index 829795b..7d06e54 100644 --- a/diboot-core/src/test/java/diboot/core/test/service/BaseServiceTest.java +++ b/diboot-core/src/test/java/diboot/core/test/service/BaseServiceTest.java @@ -20,6 +20,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.OrderItem; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.diboot.core.binding.QueryBuilder; import com.diboot.core.config.BaseConfig; import com.diboot.core.entity.Dictionary; import com.diboot.core.service.impl.DictionaryServiceImpl; @@ -289,4 +290,26 @@ public class BaseServiceTest { List ids = dictionaryService.getEntityListLimit(queryWrapper, 5); Assert.assertTrue(ids.size() == 2); } + + @Test + public void testPagination(){ + Dictionary dict = new Dictionary(); + dict.setParentId(1L); + dict.setType("GENDER"); + dict.setEditable(true); + + QueryWrapper queryWrapper = QueryBuilder.toQueryWrapper(dict); + + // 查询当前页的数据 + Pagination pagination = new Pagination(); + pagination.setPageSize(1); + + List voList = dictionaryService.getViewObjectList(queryWrapper, pagination, DictionaryVO.class); + Assert.assertTrue(voList.size() == 1); + Assert.assertTrue(pagination.getTotalPage() >= 2); + + pagination.setPageIndex(2); + voList = dictionaryService.getViewObjectList(queryWrapper, pagination, DictionaryVO.class); + Assert.assertTrue(voList.size() == 1); + } } \ No newline at end of file