ruoyi-vue版本部署问题纪要(SQL server)

ruoyi-vue的SQL server版本改造纪要

      • 初步参考文章
        • maven配置修改
        • application-XXX.yml配置修改
          • 数据源配置
        • PageHelper分页插件
        • 数据库初始化脚本
        • Mapper文件
          • selectGenTableList
          • selectDbTableList
          • selectDbTableListByNames
          • selectTableByName
          • selectDbTableColumnsByName
        • 代码生成模块修改
          • 生成消息初始化配置
          • 生成的sql文件

我在部署时,使用的是ruoyi-vue的3.8版本,后端数据库是sqlserver2012。从mysql改成sqlserver,改动项还是很多的。
sqlserver2012,mybatis的mapper中的list对应的sql语句需要增加order by(如果页面有分页逻辑),否则报类似的错误:OFFSET ? ROWS FETCH NEXT ? ROWS ONLY

初步参考文章

ruoyi(若依)系统使用SqlServer数据库改动部分
这个篇文章讲解了一部分,有些地方没写的详细,我又根据自己部署实践,下边会补充完善一些。

maven配置修改

<dependency>
   <groupId>com.microsoft.sqlservergroupId>
   <artifactId>mssql-jdbcartifactId>
dependency>

application-XXX.yml配置修改

数据源配置
# 数据源配置
spring:
    datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver  #改驱动
        druid:
            # 主库数据源
            master:
                url: jdbc:sqlserver://localhost:1433;DatabaseName=XXXXXX;SelectMethod=cursor  #SelectMethod=cursor新增
                username: XXX
                password: XXXXX
            # 从库数据源
            slave:
                # 从数据源开关/默认关闭
                enabled: false
                url: 
                username: 
                password: 
            # 初始连接数
            initialSize: 5
            # 最小连接池数量
            minIdle: 10
            # 最大连接池数量
            maxActive: 20
            # 配置获取连接等待超时的时间
            maxWait: 60000
            # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
            timeBetweenEvictionRunsMillis: 60000
            # 配置一个连接在池中最小生存的时间,单位是毫秒
            minEvictableIdleTimeMillis: 300000
            # 配置一个连接在池中最大生存的时间,单位是毫秒
            maxEvictableIdleTimeMillis: 900000
            # 配置检测连接是否有效
            validationQuery: SELECT 'X'   #此处新增
            testWhileIdle: true
            testOnBorrow: false
            testOnReturn: false
            webStatFilter: 
                enabled: true
            statViewServlet:
                enabled: true
                # 设置白名单,不填则允许所有访问
                allow:
                url-pattern: /druid/*
                # 控制台管理用户名和密码
                login-username: ruoyi
                login-password: 123456
            filter:
                stat:
                    enabled: true
                    # 慢SQL记录
                    log-slow-sql: true
                    slow-sql-millis: 1000
                    merge-sql: false     #此处新增
                wall:
                    config:
                        multi-statement-allow: true

PageHelper分页插件

# PageHelper分页插件
pagehelper:
  helperDialect: sqlserver2012   #此处修改,2008前的是sqlserver
  supportMethodsArguments: true
  params: count=countSql
  reasonable: true

数据库初始化脚本

数据库表的主键字段要设置成自增长的 IDENTITY(1, 1)
数据库初始化脚本

Mapper文件

在ruoyi-generator模块下的resources文件包下的GenTableMapper.xml

selectGenTableList
<select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult">
		<include refid="selectGenTableVo"/>
		<where>
			<if test="tableName != null and tableName != ''">
				AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
			if>
			<if test="tableComment != null and tableComment != ''">
				AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
			if>
			<if test="params.beginTime != null and params.beginTime != ''">
-- 				AND date_format(create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')
				and DATEDIFF(day, #{params.beginTime}, create_time) >= 0
			if>
			<if test="params.endTime != null and params.endTime != ''">
-- 				AND date_format(create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
				and DATEDIFF(day, create_time , #{params.endTime}) >= 0
			if>
		where>
		order by create_time desc   -- 新增语句
	select>
selectDbTableList
<select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult">
		select a.[name] as table_name,isnull(g.[value],'-') as table_comment
		,create_date as create_time,modify_date as update_time
		from sys.tables a
		left join sys.extended_properties g on (a.object_id = g.major_id AND g.minor_id = 0)
		where a.[name] NOT LIKE 'qrtz_%' AND a.[name] NOT LIKE 'gen_%' and a.[name] NOT LIKE 'sys_%'
		AND a.[name] NOT IN (select table_name from gen_table)
		<if test="tableName != null and tableName != ''">
			AND lower(a.[name]) like lower(concat('%', #{tableName}, '%'))
		if>
		<if test="tableComment != null and tableComment != ''">
			AND lower(g.[value]) like lower(concat('%', #{tableComment}, '%'))
		if>
		<if test="params.beginTime != null and params.beginTime != ''">
-- 			AND date_format(create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')
			and DATEDIFF(day, #{params.beginTime}, create_date) >= 0
		if>
		<if test="params.endTime != null and params.endTime != ''">
-- 			AND date_format(create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
			and DATEDIFF(day, create_date , #{params.endTime}) >= 0
		if>
        order by create_date desc
	select>
	
	--   新增部分:这个是分页所需,如果不加入,就会报错order by有问题
	<select id="selectDbTableList_COUNT" resultType="Long">
			select count(0)
			from sys.tables a
			left join sys.extended_properties g on (a.object_id = g.major_id AND g.minor_id = 0)
			where a.[name] NOT LIKE 'qrtz_%' AND a.[name] NOT LIKE 'gen_%' and a.[name] NOT LIKE 'sys_%'
			AND a.[name] NOT IN (select table_name from gen_table)
		select>
selectDbTableListByNames
<select id="selectDbTableListByNames" resultMap="GenTableResult">
		select a.[name] as table_name,isnull(g.[value],'-') as table_comment
		,create_date as create_time,modify_date as update_time
		from sys.tables a
		left join sys.extended_properties g on (a.object_id = g.major_id AND g.minor_id = 0)
		where a.[name] NOT LIKE 'qrtz_%' AND a.[name] NOT LIKE 'gen_%'
		and a.[name] in
	    <foreach collection="array" item="name" open="(" separator="," close=")">
 			#{name}
        foreach> 
	select>
selectTableByName
<select id="selectTableByName" parameterType="String" resultMap="GenTableResult">
		select a.[name] as table_name,isnull(g.[value],'-') as table_comment
		,create_date as create_time,modify_date as update_time
		from sys.tables a
		left join sys.extended_properties g on (a.object_id = g.major_id AND g.minor_id = 0)
		where a.[name] NOT LIKE 'qrtz_%' AND a.[name] NOT LIKE 'gen_%'
			AND g.[value]  ]]> ''
		and table_name = #{tableName}
	select>

在ruoyi-generator模块下的resources文件包下的GenTableColumnMapper.xml

selectDbTableColumnsByName
<select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
		SELECT a.name AS column_name,
	   (
		   CASE
			   WHEN a.isnullable = 1 THEN
				   0
			   ELSE
				   1
			   END
		   )  AS is_required,
	   (
		   CASE
			   WHEN (
						SELECT COUNT(*)
						FROM sysobjects
						WHERE (
								name IN (
								SELECT name
								FROM sysindexes
								WHERE (id = a.id)
								  AND (
										indid IN (
										SELECT indid
										FROM sysindexkeys
										WHERE (id = a.id)
										  AND (
												colid IN (
												SELECT colid
												FROM syscolumns
												WHERE (id = a.id)
												  AND (name = a.name)
											)
											)
									)
									)
							)
							)
						  AND (xtype = 'PK')
					) > 0 THEN
				   1
			   ELSE
				   0
			   END
		   )  AS is_pk,
	   a.colorder  AS sort,
	   isnull(g.[value], ' ') AS column_comment,
	   (
		   CASE
			   WHEN COLUMNPROPERTY(a.id, a.name, 'IsIdentity') = 1 THEN
				   1
			   ELSE
				   0
			   END
		) AS is_increment,
	   b.name  AS column_type
		FROM syscolumns a
				 LEFT JOIN systypes b ON a.xtype = b.xusertype
				 INNER JOIN sysobjects d ON a.id = d.id
			AND d.xtype = 'U'
			AND d.name   ]]> 'dtproperties'
				 LEFT JOIN syscomments e ON a.cdefault = e.id
				 LEFT JOIN sys.extended_properties g ON a.id = g.major_id
			AND a.colid = g.minor_id
				 LEFT JOIN sys.extended_properties f ON d.id = f.class
			AND f.minor_id = 0
				 LEFT JOIN sys.objects h ON a.id = h.object_id
				 LEFT JOIN sys.schemas i ON h.schema_id = i.schema_id
		WHERE d.name = #{tableName}
		ORDER BY a.colorder
	select>

代码生成模块修改

生成消息初始化配置

路径:\ruoyi-generator\src\main\resources\generator.yml

gen: 
  # 作者
  author: wade
  # 默认生成包路径 system 需改成自己的模块名称 如 system monitor tool
  packageName: com.ruoyi.customer
  # 自动去除表前缀,默认是false
  autoRemovePre: false
  # 表前缀(生成类名不会包含表前缀,多个用逗号分隔)
  tablePrefix: lx_
生成的sql文件

路径:\ruoyi-generator\src\main\resources\vm\sql\sql.vm
把函数名称sysdate改成getdate

-- 按钮父菜单ID(mysql)
-- SELECT @parentId := LAST_INSERT_ID();
-- 按钮父菜单ID(sqlserver)

-- 改成下边
-- 返回insertinto 语句后的主键值
declare @parentId int
set @parentId = @@IDENTITY;

你可能感兴趣的:(srping,boot,SQLserver,部署,sqlserver,ruoyi)