修复了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)}
* <p>
* - {@link LocalDateTime}{@link LocalDate}{@link LocalTime}
* keyStartcolumn >= keyEndcolumn <= key
* keyStartcolumn >= valueEndcolumn <= value
*
* @param null2IsNull valuenullSQLIS NULLnullSQL
*/
@ -37,7 +37,7 @@ public class WrapperUtils {
if (key.endsWith("Start")) {
wrapper.ge(key.substring(0, key.length() - 5), value);
} else if (key.endsWith("End")) {
wrapper.ge(key.substring(key.length() - 3), value);
wrapper.le(key.substring(0, key.length() - 3), value);
}
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.service.IStaffService;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.response.ResponseMap;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.WrapperUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
@ -25,19 +28,21 @@ public class MybatisPlusTests {
@Resource
private ObjectMapper objectMapper;
@SneakyThrows
@Test
public void test() {
System.out.println(objectMapper.writeValueAsString(
ResponseMap.ofSuccess("ok",
staffService.getOne(Wrappers.<Staff>query().last("limit 1"))
)
));
Map<Object, Object> map = new HashMap<>();
map.put("123", "456");
map.put(894, 789);
System.out.println(objectMapper.writeValueAsString(
ResponseMap.ofSuccess("ok", map)
));
staffService.page(new Page<Staff>(2, 1));
}
@SneakyThrows
@Test
public void wrapperTest() {
Map<String, Object> map = new HashMap<>();
map.put("time", "aaa");
map.put("stimeStart", LocalDateTime.now());
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()));
}
}