瀏覽代碼

增强sqlRunner

Caratacus 8 年之前
父節點
當前提交
ceaee0e02a

+ 19 - 6
mybatis-plus/src/main/java/com/baomidou/mybatisplus/mapper/AutoSqlInjector.java

@@ -811,7 +811,8 @@ public class AutoSqlInjector implements ISqlInjector {
 	public void injectSqlRunner(Configuration configuration) {
 		this.configuration = configuration;
 		this.languageDriver = configuration.getDefaultScriptingLanguageInstance();
-		initSelect();
+		initSelectList();
+		initSelectObjs();
 		initInsert();
 		initUpdate();
 		initDelete();
@@ -873,19 +874,31 @@ public class AutoSqlInjector implements ISqlInjector {
 	}
 
 	/**
-	 * initSelect
+	 * initSelectList
 	 */
-	private void initSelect() {
-		if (hasMappedStatement(SqlRunner.SELECT)) {
+	private void initSelectList() {
+		if (hasMappedStatement(SqlRunner.SELECT_LIST)) {
 			logger.warn("MappedStatement 'SqlRunner.Select' Aalready Exists");
 			return;
 		}
 		SqlSource sqlSource = languageDriver.createSqlSource(configuration, SqlRunner.SQLScript, Map.class);
-		createSelectMappedStatement(SqlRunner.SELECT, sqlSource, Map.class);
+		createSelectMappedStatement(SqlRunner.SELECT_LIST, sqlSource, Map.class);
 	}
 
 	/**
-	 * initSelect
+	 * initSelectObjs
+	 */
+	private void initSelectObjs() {
+		if (hasMappedStatement(SqlRunner.SELECT_OBJS)) {
+			logger.warn("MappedStatement 'SqlRunner.Select' Aalready Exists");
+			return;
+		}
+		SqlSource sqlSource = languageDriver.createSqlSource(configuration, SqlRunner.SQLScript, Object.class);
+		createSelectMappedStatement(SqlRunner.SELECT_OBJS, sqlSource, Object.class);
+	}
+
+	/**
+	 * initCount
 	 */
 	private void initCount() {
 		if (hasMappedStatement(SqlRunner.COUNT)) {

+ 12 - 3
mybatis-plus/src/main/java/com/baomidou/mybatisplus/mapper/SqlRunner.java

@@ -41,7 +41,8 @@ public class SqlRunner {
 	public static final String INSERT = "com.baomidou.mybatisplus.mapper.SqlRunner.Insert";
 	public static final String DELETE = "com.baomidou.mybatisplus.mapper.SqlRunner.Delete";
 	public static final String UPDATE = "com.baomidou.mybatisplus.mapper.SqlRunner.Update";
-	public static final String SELECT = "com.baomidou.mybatisplus.mapper.SqlRunner.Select";
+	public static final String SELECT_LIST = "com.baomidou.mybatisplus.mapper.SqlRunner.SelectList";
+	public static final String SELECT_OBJS = "com.baomidou.mybatisplus.mapper.SqlRunner.SelectObjs";
 	public static final String COUNT = "com.baomidou.mybatisplus.mapper.SqlRunner.Count";
 	public static final String SQLScript = "${sql}";
 	public static final String SQL = "sql";
@@ -87,7 +88,15 @@ public class SqlRunner {
 	}
 
 	public List<Map<String, Object>> selectList(String sql, Object... args) {
-		return sqlSession().selectList(SELECT, sqlMap(sql, args));
+		return sqlSession().selectList(SELECT_LIST, sqlMap(sql, args));
+	}
+
+	public List<Object> selectObjs(String sql, Object... args) {
+		return sqlSession().selectList(SELECT_OBJS, sqlMap(sql, args));
+	}
+
+	public Object selectObj(String sql, Object... args) {
+		return SqlHelper.getObject(selectObjs(sql, args));
 	}
 
 	public int selectCount(String sql, Object... args) {
@@ -103,7 +112,7 @@ public class SqlRunner {
 		if (null == page) {
 			return null;
 		}
-		page.setRecords(sqlSession().selectList(SELECT, sqlMap(sql, args), page));
+		page.setRecords(sqlSession().selectList(SELECT_LIST, sqlMap(sql, args), page));
 		return page;
 	}