- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package com.mybatisflex.core;
@@ -345,8 +345,7 @@ public interface BaseMapper {
* @return entity 数据
*/
default T selectOneByQuery(QueryWrapper queryWrapper) {
- List entities = selectListByQuery(queryWrapper.limit(1));
- return (entities == null || entities.isEmpty()) ? null : entities.get(0);
+ return SqlUtil.getSelectOneResult(selectListByQuery(queryWrapper));
}
@@ -358,8 +357,7 @@ public interface BaseMapper {
* @return 数据内容
*/
default R selectOneByQueryAs(QueryWrapper queryWrapper, Class asType) {
- List entities = selectListByQueryAs(queryWrapper.limit(1), asType);
- return (entities == null || entities.isEmpty()) ? null : entities.get(0);
+ return SqlUtil.getSelectOneResult(selectListByQueryAs(queryWrapper, asType));
}
/**
@@ -495,8 +493,7 @@ public interface BaseMapper {
* @return 数据量
*/
default Object selectObjectByQuery(QueryWrapper queryWrapper) {
- List