上传网站到虚拟主机,网站检索 标签,岗顶网站设计,网站建设用阿里还是华为云文章目录 1. 添加依赖项2. 更新配置文件 application-druid.yml2.1. 配置数据源2.2. 配置连接验证 3. 更新 MybatisPlusConfig4. 解决 mapper 中使用 sysdate() 的问题4.1. 修改 BaseEntity4.2. 修改 Mapper 5. 更新 YML 配置 正文开始#xff1a; 前提条件#xff1a;在您的… 文章目录 1. 添加依赖项2. 更新配置文件 application-druid.yml2.1. 配置数据源2.2. 配置连接验证 3. 更新 MybatisPlusConfig4. 解决 mapper 中使用 sysdate() 的问题4.1. 修改 BaseEntity4.2. 修改 Mapper 5. 更新 YML 配置 正文开始 前提条件在您的项目中已经集成了 MyBatis-Plus。
1. 添加依赖项
位置ruoyi-admin/pom.xml
!-- SQLite3驱动 --
dependencygroupIdorg.xerial/groupIdartifactIdsqlite-jdbc/artifactIdversion3.36.0.3/version
/dependencydependencygroupIdcom.baomidou/groupIdartifactIdmybatis-plus-boot-starter/artifactIdversion3.4.3.1/version
/dependency2. 更新配置文件 application-druid.yml
2.1. 配置数据源
# 数据源配置
spring:datasource:type: com.alibaba.druid.pool.DruidDataSourcedriverClassName: org.sqlite.JDBCdruid:# 主库数据源配置master:url: jdbc:sqlite:db\\db.sqlite3?date_string_formatyyyy-MM-dd HH:mm:ssusername:password:注意务必添加 date_string_formatyyyy-MM-dd HH:mm:ss否则在某些情况下查询时会报错 Caused by: java.sql.SQLException: Error parsing time stamp。具体错误信息示例 13:53:38.671 [restartedMain] ERROR o.s.b.SpringApplication - [reportFailure,870] - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name captchaController: Unsatisfied dependency expressed through field configService;
...
Error parsing time stamp; nested exception is java.sql.SQLException: Error parsing time stamp2.2. 配置连接验证
# 配置检测连接有效性
validationQuery: SELECT 1 FROM sys_config3. 更新 MybatisPlusConfig
在 MybatisPlusConfig 类中配置分页插件以支持 SQLite 数据库
/*** 分页插件自动识别数据库类型 https://baomidou.com/guide/interceptor-pagination.html*/
public PaginationInnerInterceptor paginationInnerInterceptor() {PaginationInnerInterceptor paginationInnerInterceptor new PaginationInnerInterceptor();// 设置数据库类型为SQLitepaginationInnerInterceptor.setDbType(DbType.SQLITE);// 设置最大单页限制数量默认500条-1表示不限制paginationInnerInterceptor.setMaxLimit(-1L);return paginationInnerInterceptor;
}4. 解决 mapper 中使用 sysdate() 的问题
4.1. 修改 BaseEntity
/** 当前时间 */
Setter
TableField(exist false)
private Date nowDate;public Date getNowDate() {return DateUtils.getNowDate();
}4.2. 修改 Mapper
在 SysLogininforMapper.xml 中替换为以下内容
insert parameterTypeSysLogininforINSERT INTO sys_logininfor (user_name, status, ipaddr, login_location, browser, os, msg, login_time) VALUES (#{userName}, #{status}, #{ipaddr}, #{loginLocation}, #{browser}, #{os}, #{msg}, CURRENT_TIMESTAMP)
/insert在 SysUserMapper.xml 中修改更新操作
update parameterTypeSysUserif testremark ! nullremark #{remark},/ifupdate_time CURRENT_TIMESTAMPWHERE user_id #{userId}
/update5. 更新 YML 配置
在打包为 jar 后您可以通过配置数据库的路径来灵活设置数据库位置。示例配置如下
url: jdbc:sqlite:.//DB//sql.db?date_string_formatyyyy-MM-dd HH:mm:ss通过以上步骤您便成功将项目的数据库更改为 SQLite并配置相应的环境以确保顺利运行。确保在每一步都仔细核对配置以避免潜在的问题。