From 03bb32c9794c99ca41f378772f6077f2318f48d7 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Fri, 23 Feb 2024 10:51:12 +0800 Subject: [PATCH] build: v1.8.0 release (^.^)YYa!! --- changes.md | 1 - .../java/com/mybatisflex/core/BaseMapper.java | 28 +++++++++++++++---- .../com/mybatisflex/test/Account6Test.java | 6 +--- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/changes.md b/changes.md index c0e15811..cfeeb367 100644 --- a/changes.md +++ b/changes.md @@ -3,7 +3,6 @@ 查看 [全部代码贡献者](/zh/intro/what-is-mybatisflex.html#贡献者)。 ## v1.8.0 20240223: -- 优化:selectOneByQuery(QueryWrapper queryWrapper) 由用户主动添加 limit 1 - 优化:entityOrBase.tpl 中命令占位符被替换后,entity 里面多了一行空白行,感谢 @caohenghui - 修复:在复杂的 VO 嵌套查询时,addResultMap 抛出异常的问题,感谢 @leizhiyou - 修复:实体类实现多层级的接口时监听器无法匹配问题,感谢 @ruansheng diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/BaseMapper.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/BaseMapper.java index 3cdf1c9b..a6148267 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/BaseMapper.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/BaseMapper.java @@ -433,7 +433,13 @@ public interface BaseMapper { * @return 实体类数据 */ default T selectOneByQuery(QueryWrapper queryWrapper) { - return MapperUtil.getSelectOneResult(selectListByQuery(queryWrapper)); + Long limitRows = CPI.getLimitRows(queryWrapper); + try { + queryWrapper.limit(1); + return MapperUtil.getSelectOneResult(selectListByQuery(queryWrapper)); + } finally { + CPI.setLimitRows(queryWrapper, limitRows); + } } /** @@ -444,7 +450,13 @@ public interface BaseMapper { * @return 实体类数据 */ default R selectOneByQueryAs(QueryWrapper queryWrapper, Class asType) { - return MapperUtil.getSelectOneResult(selectListByQueryAs(queryWrapper, asType)); + Long limitRows = CPI.getLimitRows(queryWrapper); + try { + queryWrapper.limit(1); + return MapperUtil.getSelectOneResult(selectListByQueryAs(queryWrapper, asType)); + } finally { + CPI.setLimitRows(queryWrapper, limitRows); + } } /** @@ -455,7 +467,7 @@ public interface BaseMapper { */ default T selectOneWithRelationsByMap(Map whereConditions) { FlexAssert.notEmpty(whereConditions, "whereConditions"); - return selectOneWithRelationsByQuery(QueryWrapper.create().where(whereConditions).limit(1L)); + return selectOneWithRelationsByQuery(QueryWrapper.create().where(whereConditions)); } /** @@ -466,7 +478,7 @@ public interface BaseMapper { */ default T selectOneWithRelationsByCondition(QueryCondition whereConditions) { FlexAssert.notNull(whereConditions, "whereConditions"); - return selectOneWithRelationsByQuery(QueryWrapper.create().where(whereConditions).limit(1L)); + return selectOneWithRelationsByQuery(QueryWrapper.create().where(whereConditions)); } /** @@ -476,7 +488,13 @@ public interface BaseMapper { * @return 实体类数据 */ default T selectOneWithRelationsByQuery(QueryWrapper queryWrapper) { - return MapperUtil.queryRelations(this, MapperUtil.getSelectOneResult(selectListByQuery(queryWrapper))); + Long limitRows = CPI.getLimitRows(queryWrapper); + try { + queryWrapper.limit(1); + return MapperUtil.queryRelations(this, MapperUtil.getSelectOneResult(selectListByQuery(queryWrapper))); + } finally { + CPI.setLimitRows(queryWrapper, limitRows); + } } /** diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/test/java/com/mybatisflex/test/Account6Test.java b/mybatis-flex-test/mybatis-flex-native-test/src/test/java/com/mybatisflex/test/Account6Test.java index f0059590..31328e07 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/test/java/com/mybatisflex/test/Account6Test.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/test/java/com/mybatisflex/test/Account6Test.java @@ -82,11 +82,7 @@ public class Account6Test implements WithAssertions { // 没有 ID,插入失败 Assert.fail(); } catch (Exception e) { - assertThat(e.getCause()).isInstanceOf(InvocationTargetException.class) - .asInstanceOf(InstanceOfAssertFactories.type(InvocationTargetException.class)) - .extracting(i -> i.getTargetException().getMessage()) - .asString() - .contains("NULL not allowed for column \"ID\""); + Assert.assertTrue(e.getMessage().contains("NULL not allowed for column \"ID\"")); } List list = mapper.selectAll();