0
点赞
收藏
分享

微信扫一扫

全面解析若依框架(springboot-vue前后分离--后端部分)

晒大太阳了 2022-12-17 阅读 131

1、 若依框架分解

- 启动配置

  • 前端启动
# 进入项目目录
cd ruoyi-ui

# 安装依赖
npm install

# 强烈建议不要用直接使用 cnpm 安装,会有各种诡异的 bug,可以通过重新指定 registry 来解决 npm 安装速度慢的问题。
npm install --registry=https://registry.npmmirror.com

# 本地开发 启动项目
npm run dev
  • 后端启动

在这里插入图片描述
在这里插入图片描述

- 使用技术

- 功能分解

2、功能详解

分页实现(使用PageHelper)

分页查询条件

在这里插入图片描述

注意坑点

导入导出实现(ExcelUtil.java)

导出

在这里插入图片描述

导入

拓展

数据处理

导出自定义隐藏列

在这里插入图片描述

上传下载

权限控制

示例

@PreAuthorize("@ss.hasPermi('system:dept:list')")
    @GetMapping("/list")
    public AjaxResult list(SysDept dept)
    {
        List<SysDept> depts = deptService.selectDeptList(dept);
        return success(depts);
    }

异常处理

参数验证

拓展

在这里插入图片描述

在这里插入图片描述

系统日志

AfterReturning和AfterThrowing

数据权限

数据的具体过滤

在这里插入图片描述

多数据源

使用

  • 首先要配置application-druid.yml
# 从库数据源
slave:
	# 从数据源开关/默认关闭
	enabled: true
	url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
	username: root
	password: password
  • 在DataSourceType类添加数据源枚举
/**
 * 从库
 */
SLAVE
  • 在DruidConfig配置读取数据源
@Bean
@ConfigurationProperties("spring.datasource.druid.slave")
@ConditionalOnProperty(prefix = "spring.datasource.druid.slave", name = "enabled", havingValue = "true")
public DataSource slaveDataSource(DruidProperties druidProperties)
{
	DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
	return druidProperties.dataSource(dataSource);
}

  • 在dataSource(DataSource masterDataSource)将数据源注入到容器中
 setDataSource(targetDataSources, DataSourceType.SLAVE.name(), "slaveDataSource");

内部具体实现

 public Connection getConnection() throws SQLException {
        return this.determineTargetDataSource().getConnection();
    }
  protected DataSource determineTargetDataSource() {
        Assert.notNull(this.resolvedDataSources, "DataSource router not initialized");
        Object lookupKey = this.determineCurrentLookupKey();
        DataSource dataSource = (DataSource)this.resolvedDataSources.get(lookupKey);
        if (dataSource == null && (this.lenientFallback || lookupKey == null)) {
            dataSource = this.resolvedDefaultDataSource;
        }

        if (dataSource == null) {
            throw new IllegalStateException("Cannot determine target DataSource for lookup key [" + lookupKey + "]");
        } else {
            return dataSource;
        }
    }

定时任务

使用

在这里插入图片描述

具体实现

防重复提交

具体实现(通过redis的过期时间实现)

举报

相关推荐

0 条评论