1.关于多数据源配置:
修改ruoyi-admin里的application-druid.yml:
druid:
# 主库数据源
master:
url: jdbc:mysql://192.168.156.11:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: root
# 从库数据源
slave:
# 从数据源开关/默认关闭
enabled: true
url: jdbc:mysql://192.168.156.11:3306/shopping-mall?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: root
2.使用ruoyi-genarator生成从库代码:
2.1 创建上面数据源从库shopping-mall,并把ry-vue数据库里的gen_table和gen_table_column同步到shopping-mall,新建ishop_order表,
2.2 修改GenController,指定读取从库数据表,重启后台,并启动前端项目ruoyi-vue
@RestController
@RequestMapping("/tool/gen")
@DataSource(DataSourceType.SLAVE)
public class GenController extends BaseController
{}
3.读取从库的数据,在相应的Controller添加数据源注解:
@RestController
@RequestMapping("/system/order")
@DataSource(DataSourceType.SLAVE)
public class ShopOrderController extends BaseController
{}
未完待续......