Explorar el Código

fixed: mybatis cannot read only one row data

sn-yang hace 3 años
padre
commit
a8b367911f

+ 4 - 41
pom.xml

@@ -1,7 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project xmlns="http://maven.apache.org/POM/4.0.0"
-		 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 	<modelVersion>4.0.0</modelVersion>
 
 	<groupId>com.ruoyi</groupId>
@@ -23,7 +22,6 @@
 		<swagger.version>3.0.0</swagger.version>
 		<kaptcha.version>2.3.2</kaptcha.version>
 		<mybatis-spring-boot.version>2.2.2</mybatis-spring-boot.version>
-		<!--		<pagehelper.boot.version>1.4.1</pagehelper.boot.version>-->
 		<fastjson.version>1.2.80</fastjson.version>
 		<oshi.version>6.1.2</oshi.version>
 		<jna.version>5.10.0</jna.version>
@@ -33,11 +31,8 @@
 		<poi.version>4.1.2</poi.version>
 		<velocity.version>2.3</velocity.version>
 		<jwt.version>0.9.1</jwt.version>
-		<!--		<jpa.version>2.2</jpa.version>-->
 		<r2dbc-bom.version>Borca-RELEASE</r2dbc-bom.version>
-		<mybatis-r2dbc.version>1.0.7.RELEASE</mybatis-r2dbc.version>
-		<!--		<mybatis-generator-core.version>1.4.0</mybatis-generator-core.version>-->
-		<!--		<mybatis-dynamic-sql.version>1.3.1</mybatis-dynamic-sql.version>-->
+		<mybatis-r2dbc.version>1.1.0.RELEASE</mybatis-r2dbc.version>
 	</properties>
 
 	<!-- 依赖声明 -->
@@ -62,19 +57,12 @@
 				<scope>import</scope>
 			</dependency>
 
-			<!-- JPA -->
-			<!--			<dependency>-->
-			<!--				<groupId>javax.persistence</groupId>-->
-			<!--				<artifactId>javax.persistence-api</artifactId>-->
-			<!--				<version>${jpa.version}</version>-->
-			<!--			</dependency>-->
-
 			<!-- https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client -->
-			<dependency>
+			<!-- <dependency>
 				<groupId>org.mariadb.jdbc</groupId>
 				<artifactId>mariadb-java-client</artifactId>
 				<version>3.0.4</version>
-			</dependency>
+			</dependency> -->
 
 			<!-- https://mvnrepository.com/artifact/org.mariadb/r2dbc-mariadb -->
 			<dependency>
@@ -94,17 +82,6 @@
 				<artifactId>mybatis-r2dbc</artifactId>
 				<version>${mybatis-r2dbc.version}</version>
 			</dependency>
-			<!--			<dependency>-->
-			<!--				<groupId>org.mybatis.generator</groupId>-->
-			<!--				<artifactId>mybatis-generator-core</artifactId>-->
-			<!--				<version>${mybatis-generator-core.version}</version>-->
-			<!--			</dependency>-->
-			<!--			<dependency>-->
-			<!--				<groupId>org.mybatis.dynamic-sql</groupId>-->
-			<!--				<artifactId>mybatis-dynamic-sql</artifactId>-->
-			<!--				<version>${mybatis-dynamic-sql.version}</version>-->
-			<!--			</dependency>-->
-
 
 			<!-- 解析客户端操作系统、浏览器等 -->
 			<dependency>
@@ -113,20 +90,6 @@
 				<version>${bitwalker.version}</version>
 			</dependency>
 
-			<!-- SpringBoot集成mybatis框架 -->
-			<!--			<dependency>-->
-			<!--				<groupId>org.mybatis.spring.boot</groupId>-->
-			<!--				<artifactId>mybatis-spring-boot-starter</artifactId>-->
-			<!--				<version>${mybatis-spring-boot.version}</version>-->
-			<!--			</dependency>-->
-
-			<!-- pagehelper 分页插件 -->
-			<!--			<dependency>-->
-			<!--				<groupId>com.github.pagehelper</groupId>-->
-			<!--				<artifactId>pagehelper-spring-boot-starter</artifactId>-->
-			<!--				<version>${pagehelper.boot.version}</version>-->
-			<!--			</dependency>-->
-
 			<!-- 获取系统信息 -->
 			<dependency>
 				<groupId>com.github.oshi</groupId>

+ 8 - 12
ruoyi-admin/pom.xml

@@ -22,16 +22,16 @@
 			<artifactId>spring-boot-starter-webflux</artifactId>
 		</dependency>
 
-		<dependency>
+		<!-- <dependency>
 			<groupId>org.mariadb.jdbc</groupId>
 			<artifactId>mariadb-java-client</artifactId>
-		</dependency>
+		</dependency> -->
 
 		<!-- Mysql驱动包 -->
-		<!--		<dependency>-->
-		<!--			<groupId>mysql</groupId>-->
-		<!--			<artifactId>mysql-connector-java</artifactId>-->
-		<!--		</dependency>-->
+		<dependency>
+			<groupId>mysql</groupId>
+			<artifactId>mysql-connector-java</artifactId>
+		</dependency>
 
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
@@ -49,16 +49,12 @@
 			<groupId>pro.chenggang</groupId>
 			<artifactId>mybatis-r2dbc</artifactId>
 		</dependency>
-		<!--		<dependency>-->
-		<!--			<groupId>org.mybatis.dynamic-sql</groupId>-->
-		<!--			<artifactId>mybatis-dynamic-sql</artifactId>-->
-		<!--		</dependency>-->
 
 		<!-- spring-boot-devtools -->
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-devtools</artifactId>
-			<optional>true</optional> <!-- 表示依赖不会传递 -->
+			<optional>true</optional>            <!-- 表示依赖不会传递 -->
 		</dependency>
 
 		<!-- swagger3-->
@@ -102,7 +98,7 @@
 				<artifactId>spring-boot-maven-plugin</artifactId>
 				<version>2.1.1.RELEASE</version>
 				<configuration>
-					<fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
+					<fork>true</fork>                    <!-- 如果没有该配置,devtools不会生效 -->
 				</configuration>
 				<executions>
 					<execution>

+ 3 - 3
ruoyi-admin/src/main/resources/application-dev.yml

@@ -2,7 +2,7 @@
 spring:
     r2dbc:
         mybatis:
-            r2dbc-url: r2dbc:mariadb://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
+            r2dbc-url: r2dbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
             username: ruoyi
             password: password
             pool:
@@ -15,10 +15,10 @@ spring:
                 validation-depth: REMOTE
                 max-create-connection-time: PT30S
     datasource:
-        jdbcUrl: jdbc:mariadb://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
+        jdbcUrl: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
         username: ruoyi
         password: password
-        driver-class-name: org.mariadb.jdbc.Driver
+        driver-class-name: com.mysql.cj.jdbc.Driver
         hikari:
             connection-init-sql: SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci
             minimum-idle: 1

+ 0 - 6
ruoyi-common/pom.xml

@@ -35,12 +35,6 @@
 			<artifactId>spring-boot-starter-security</artifactId>
 		</dependency>
 
-		<!-- pagehelper 分页插件 -->
-		<!--        <dependency>-->
-		<!--            <groupId>com.github.pagehelper</groupId>-->
-		<!--            <artifactId>pagehelper-spring-boot-starter</artifactId>-->
-		<!--        </dependency>-->
-
 		<!-- 自定义验证注解 -->
 		<dependency>
 			<groupId>org.springframework.boot</groupId>

+ 36 - 36
ruoyi-generator/pom.xml

@@ -1,40 +1,40 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <parent>
-        <artifactId>ruoyi</artifactId>
-        <groupId>com.ruoyi</groupId>
-        <version>3.8.2</version>
-    </parent>
-    <modelVersion>4.0.0</modelVersion>
-
-    <artifactId>ruoyi-generator</artifactId>
-
-    <description>
-        generator代码生成
-    </description>
-
-    <dependencies>
-
-        <!--velocity代码生成使用模板 -->
-        <dependency>
-            <groupId>org.apache.velocity</groupId>
-            <artifactId>velocity-engine-core</artifactId>
-        </dependency>
-
-        <!-- collections工具类 -->
-        <dependency>
-            <groupId>commons-collections</groupId>
-            <artifactId>commons-collections</artifactId>
-        </dependency>
-
-        <!-- 通用工具-->
-        <dependency>
-            <groupId>com.ruoyi</groupId>
-            <artifactId>ruoyi-common</artifactId>
-        </dependency>
-
-    </dependencies>
+		 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<parent>
+		<artifactId>ruoyi</artifactId>
+		<groupId>com.ruoyi</groupId>
+		<version>3.8.2</version>
+	</parent>
+	<modelVersion>4.0.0</modelVersion>
+
+	<artifactId>ruoyi-generator</artifactId>
+
+	<description>
+		generator代码生成
+	</description>
+
+	<dependencies>
+
+		<!--velocity代码生成使用模板 -->
+		<dependency>
+			<groupId>org.apache.velocity</groupId>
+			<artifactId>velocity-engine-core</artifactId>
+		</dependency>
+
+		<!-- collections工具类 -->
+		<dependency>
+			<groupId>commons-collections</groupId>
+			<artifactId>commons-collections</artifactId>
+		</dependency>
+
+		<!-- 通用工具-->
+		<dependency>
+			<groupId>com.ruoyi</groupId>
+			<artifactId>ruoyi-common</artifactId>
+		</dependency>
+
+	</dependencies>
 
 </project>

+ 3 - 52
ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java

@@ -65,14 +65,7 @@ public class GenTableServiceImpl
 	 */
 	@Override
 	public Mono<GenTable> selectById(Long id) {
-		return mapper.selectById(id).flatMap(table -> {
-			// 获取字段信息
-			return genTableColumnMapper.selectGenTableColumnListByTableId(table.getTableId())
-				.collectList().map(columns -> {
-					table.setColumns(columns);
-					return table;
-				});
-		}).map(genTable -> {
+		return mapper.selectById(id).map(genTable -> {
 			setTableFromOptions(genTable);
 			return genTable;
 		});
@@ -115,14 +108,7 @@ public class GenTableServiceImpl
 	 */
 	@Override
 	public Mono<List<GenTable>> selectGenTableAll() {
-		return mapper.selectGenTableAll().flatMap(table -> {
-			// 获取字段信息
-			return genTableColumnMapper.selectGenTableColumnListByTableId(table.getTableId())
-				.collectList().map(columns -> {
-					table.setColumns(columns);
-					return table;
-				});
-		}).collectList();
+		return mapper.selectGenTableAll().collectList();
 	}
 
 	/**
@@ -203,13 +189,6 @@ public class GenTableServiceImpl
 	public Mono<Map<String, String>> previewCode(Long tableId) {
 		// 查询表信息
 		return mapper.selectById(tableId).flatMap(table -> {
-			// 获取字段信息
-			return genTableColumnMapper.selectGenTableColumnListByTableId(table.getTableId())
-				.collectList().map(columns -> {
-					table.setColumns(columns);
-					return table;
-				});
-		}).flatMap(table -> {
 			// 设置主子表信息
 			return setSubTable(table).thenReturn(table);
 		}).map(table -> {
@@ -264,13 +243,6 @@ public class GenTableServiceImpl
 		// 查询表信息
 		return mapper.selectGenTableByName(tableName
 		).flatMap(table -> {
-			// 获取字段信息
-			return genTableColumnMapper.selectGenTableColumnListByTableId(table.getTableId())
-				.collectList().map(columns -> {
-					table.setColumns(columns);
-					return table;
-				});
-		}).flatMap(table -> {
 			// 设置主子表信息
 			return setSubTable(table).thenReturn(table);
 		}).doOnSuccess(table -> {
@@ -310,13 +282,6 @@ public class GenTableServiceImpl
 	public Mono<Long> synchDb(final String tableName) {
 		return mapper.selectGenTableByName(tableName
 		).flatMap(table -> {
-			// 获取字段信息
-			return genTableColumnMapper.selectGenTableColumnListByTableId(table.getTableId())
-				.collectList().map(columns -> {
-					table.setColumns(columns);
-					return table;
-				});
-		}).flatMap(table -> {
 			return genTableColumnMapper
 				.selectDbTableColumnsByName(tableName)
 				.collectList()
@@ -391,13 +356,6 @@ public class GenTableServiceImpl
 	private Mono<Long> generatorCode(String tableName, ZipOutputStream zip) {
 		// 查询表信息
 		return mapper.selectGenTableByName(tableName).flatMap(table -> {
-			// 获取字段信息
-			return genTableColumnMapper.selectGenTableColumnListByTableId(table.getTableId())
-				.collectList().map(columns -> {
-					table.setColumns(columns);
-					return table;
-				});
-		}).flatMap(table -> {
 			// 设置主子表信息
 			return setSubTable(table).thenReturn(table);
 		}).flatMap(table -> {
@@ -492,14 +450,7 @@ public class GenTableServiceImpl
 	public Mono<Long> setSubTable(GenTable table) {
 		String subTableName = table.getSubTableName();
 		if (StringUtils.isNotEmpty(subTableName)) {
-			return mapper.selectGenTableByName(subTableName).flatMap(subTable -> {
-				// 获取字段信息
-				return genTableColumnMapper.selectGenTableColumnListByTableId(subTable.getTableId())
-					.collectList().map(columns -> {
-						subTable.setColumns(columns);
-						return subTable;
-					});
-			}).doOnSuccess(subTable -> {
+			return mapper.selectGenTableByName(subTableName).doOnSuccess(subTable -> {
 				table.setSubTable(subTable);
 			}).thenReturn(1L);
 		}

+ 17 - 7
ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml

@@ -25,7 +25,7 @@
 		<result property="updateBy" column="update_by"/>
 		<result property="updateTime" column="update_time"/>
 		<result property="remark" column="remark"/>
-		<!--		<collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult"/>-->
+		<collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult"/>
 	</resultMap>
 
 	<resultMap type="GenTableColumn" id="GenTableColumnResult">
@@ -144,27 +144,37 @@
 		and table_name = #{tableName}
 	</select>
 
-	<select id="selectById" parameterType="Long" resultMap="GenTableResult">
+	<select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
 		SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name,
 		t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type,
-		t.gen_path, t.options, t.remark
+		t.gen_path, t.options, t.remark,
+		c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment,
+		c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
 		FROM gen_table t
-		where t.table_id = #{tableId}
+		LEFT JOIN gen_table_column c ON t.table_id = c.table_id
+		where t.table_id = #{tableId} order by c.sort
 	</select>
 
 	<select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
 		SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name,
 		t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type,
-		t.gen_path, t.options, t.remark
+		t.gen_path, t.options, t.remark,
+		c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment,
+		c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
 		FROM gen_table t
-		where t.table_name = #{tableName}
+		LEFT JOIN gen_table_column c ON t.table_id = c.table_id
+		where t.table_name = #{tableName} order by c.sort
 	</select>
 
 	<select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult">
 		SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name,
 		t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.options,
-		t.remark
+		t.remark,
+		c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment,
+		c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
 		FROM gen_table t
+		LEFT JOIN gen_table_column c ON t.table_id = c.table_id
+		order by c.sort
 	</select>
 
 	<insert id="insert" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId" keyColumn="table_id">

+ 0 - 1
ruoyi-generator/src/main/resources/vm/java/serviceImpl.java.vm

@@ -34,7 +34,6 @@ public class ${ClassName}ServiceImpl
      * @param ${className} ${functionName}
      * @return 结果
      */
-#if($tabl
     @Transactional
     @Override
     public Mono<Long> insert(${ClassName} ${className})

+ 30 - 30
ruoyi-quartz/pom.xml

@@ -1,40 +1,40 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <parent>
-        <artifactId>ruoyi</artifactId>
-        <groupId>com.ruoyi</groupId>
-        <version>3.8.2</version>
-    </parent>
-    <modelVersion>4.0.0</modelVersion>
+		 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<parent>
+		<artifactId>ruoyi</artifactId>
+		<groupId>com.ruoyi</groupId>
+		<version>3.8.2</version>
+	</parent>
+	<modelVersion>4.0.0</modelVersion>
 
-    <artifactId>ruoyi-quartz</artifactId>
+	<artifactId>ruoyi-quartz</artifactId>
 
-    <description>
-        quartz定时任务
-    </description>
+	<description>
+		quartz定时任务
+	</description>
 
-    <dependencies>
+	<dependencies>
 
-        <!-- 定时任务 -->
-        <dependency>
-            <groupId>org.quartz-scheduler</groupId>
-            <artifactId>quartz</artifactId>
-            <exclusions>
-                <exclusion>
-                    <groupId>com.mchange</groupId>
-                    <artifactId>c3p0</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
+		<!-- 定时任务 -->
+		<dependency>
+			<groupId>org.quartz-scheduler</groupId>
+			<artifactId>quartz</artifactId>
+			<exclusions>
+				<exclusion>
+					<groupId>com.mchange</groupId>
+					<artifactId>c3p0</artifactId>
+				</exclusion>
+			</exclusions>
+		</dependency>
 
-        <!-- 通用工具-->
-        <dependency>
-            <groupId>com.ruoyi</groupId>
-            <artifactId>ruoyi-common</artifactId>
-        </dependency>
+		<!-- 通用工具-->
+		<dependency>
+			<groupId>com.ruoyi</groupId>
+			<artifactId>ruoyi-common</artifactId>
+		</dependency>
 
-    </dependencies>
+	</dependencies>
 
 </project>

+ 2 - 2
ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -41,8 +41,8 @@
 		<result property="updateBy" column="update_by"/>
 		<result property="updateTime" column="update_time"/>
 		<result property="remark" column="remark"/>
-		<!--		<association property="dept" column="dept_id" javaType="SysDept" resultMap="deptResult"/>-->
-		<!--		<collection property="roles" resultMap="RoleResult"/>-->
+		<association property="dept" column="dept_id" javaType="SysDept" resultMap="deptResult"/>
+		<collection property="roles" resultMap="RoleResult"/>
 	</resultMap>
 
 	<sql id="roleFields">