首先,在mysql中,使用root账号可以访问到整个数据库中的各个数据库,像在我的数据库中我在application.yml中配置的数据源只是配置了exam,但是我其实也可以使用到其他库的,比如exam_copy或者terminal数据库
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/exam?tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowMultiQueries=true
username: root
password: daylight
做法就是:我们在实体类中使用@Table的catalog属性,来指定使用的数据库
@lombok.Data
@Table(name = "sys_task_config",catalog = "terminal")
public class SysTaskConfig implements Serializable {
//具体属性。。。
}
不然会报出找不到exam.sys_task_config这个表的错误