修复了WrapperUtils中的bug

master
ArgonarioD 2022-06-30 14:48:34 +08:00
parent 07beec4039
commit 912bf97e3f
2 changed files with 21 additions and 16 deletions

View File

@ -20,7 +20,7 @@ public class WrapperUtils {
* - 使{@link QueryWrapper#allEq(Map, boolean)} * - 使{@link QueryWrapper#allEq(Map, boolean)}
* <p> * <p>
* - {@link LocalDateTime}{@link LocalDate}{@link LocalTime} * - {@link LocalDateTime}{@link LocalDate}{@link LocalTime}
* keyStartcolumn >= keyEndcolumn <= key * keyStartcolumn >= valueEndcolumn <= value
* *
* @param null2IsNull valuenullSQLIS NULLnullSQL * @param null2IsNull valuenullSQLIS NULLnullSQL
*/ */
@ -37,7 +37,7 @@ public class WrapperUtils {
if (key.endsWith("Start")) { if (key.endsWith("Start")) {
wrapper.ge(key.substring(0, key.length() - 5), value); wrapper.ge(key.substring(0, key.length() - 5), value);
} else if (key.endsWith("End")) { } else if (key.endsWith("End")) {
wrapper.ge(key.substring(key.length() - 3), value); wrapper.le(key.substring(0, key.length() - 3), value);
} }
return; return;
} }

View File

@ -2,14 +2,17 @@ package cn.edu.hfut.rmdjzz.projectmanagement;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Staff; import cn.edu.hfut.rmdjzz.projectmanagement.entity.Staff;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IStaffService; import cn.edu.hfut.rmdjzz.projectmanagement.service.IStaffService;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.response.ResponseMap; import cn.edu.hfut.rmdjzz.projectmanagement.utils.WrapperUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -25,19 +28,21 @@ public class MybatisPlusTests {
@Resource @Resource
private ObjectMapper objectMapper; private ObjectMapper objectMapper;
@SneakyThrows
@Test @Test
public void test() { public void test() {
System.out.println(objectMapper.writeValueAsString( staffService.page(new Page<Staff>(2, 1));
ResponseMap.ofSuccess("ok", }
staffService.getOne(Wrappers.<Staff>query().last("limit 1"))
) @SneakyThrows
)); @Test
Map<Object, Object> map = new HashMap<>(); public void wrapperTest() {
map.put("123", "456"); Map<String, Object> map = new HashMap<>();
map.put(894, 789); map.put("time", "aaa");
System.out.println(objectMapper.writeValueAsString( map.put("stimeStart", LocalDateTime.now());
ResponseMap.ofSuccess("ok", map) map.put("null", null);
)); map.put("etimeEnd", LocalDate.now());
QueryWrapper<String> wrapper = WrapperUtils.<String>allEqAndTimeIntervalQueryWrapper(map, true);
System.out.println(wrapper.getCustomSqlSegment());
System.out.println(objectMapper.writeValueAsString(wrapper.getParamNameValuePairs()));
} }
} }