|
@@ -18,6 +18,7 @@ package com.baomidou.mybatisplus.extension.injector.methods;
|
|
|
import org.apache.ibatis.mapping.MappedStatement;
|
|
|
import org.apache.ibatis.mapping.SqlSource;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.annotation.DbType;
|
|
|
import com.baomidou.mybatisplus.core.enums.SqlMethod;
|
|
|
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
|
|
import com.baomidou.mybatisplus.extension.injector.LogicAbstractMethod;
|
|
@@ -35,8 +36,16 @@ public class LogicSelectOne extends LogicAbstractMethod {
|
|
|
@Override
|
|
|
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
|
|
|
SqlMethod sqlMethod = SqlMethod.SELECT_ONE;
|
|
|
- String sql = String.format(sqlMethod.getSql(), sqlSelectColumns(tableInfo, false),
|
|
|
- tableInfo.getTableName(), this.sqlWhereEntityWrapper(tableInfo) + getGlobalConfig().getDbConfig().getDbType().getLimit(1));
|
|
|
+ DbType dbType = getGlobalConfig().getDbConfig().getDbType();
|
|
|
+ String select = this.sqlSelectColumns(tableInfo, false);
|
|
|
+ if (dbType == DbType.SQL_SERVER || dbType == DbType.SQL_SERVER2005) {
|
|
|
+ select = "TOP 1 " + select;
|
|
|
+ }
|
|
|
+ String sql = String.format(sqlMethod.getSql(), select, tableInfo.getTableName(),
|
|
|
+ this.sqlWhereEntityWrapper(tableInfo) + dbType.getLimit(1));
|
|
|
+ if (dbType == DbType.ORACLE) {
|
|
|
+ sql = String.format("SELECT * FROM (%s) ROWNUM <= 1");
|
|
|
+ }
|
|
|
SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
|
|
|
return addSelectMappedStatement(mapperClass, sqlMethod.getMethod(), sqlSource, modelClass, tableInfo);
|
|
|
}
|