preface
Since Jeecg was not used in the early development of the project, but the subsequent team members required to use the Online form development using Jeecg to improve the development efficiency, the existing data tables in the database needed to be imported into the Online form development of Jeecg.
However, a problem was immediately found. Although Online form development has a function button to import the database, it is read from the master data source, while business-related data tables are placed in another database. So you want Jeecg to import tables from the data source.
solution
- According to the official documentation of Jeecg, the database configuration in the code generator in the current Online mode of Jeecg will be changed from the name
jeecg-boot-module-system/org.jeecg.config.init.CodeGenerateDbConfig
Read from the configuration class.
So we use the global Search Everwhere function in Idea to find this class
You can see it’s going to readspring.datasource.dynamic.datasource.master.*
Yaml, and we configured three data sources in application.yaml
We want him to be able to read the business table under zu data source, so the simplest and most violent way is to directlyCodeGeneratorDbConfig
The configuration file properties read in the configuration class are changed to the path to the ZU data source
So, after we restart JeecgSystemApplication, we can see the database we want to import in the import database in the Online form development front.
Subsequent questions
Although this can be imported into the database, click the function test and you will find that the back end still goes to the master data source to search for the table of zu data source, which of course cannot be found. We should hope that it can go to the ZU data source to find the corresponding table and data. So, how should we achieve this effect?
After a series of data review and testing, we only need to change the name of the table to {data source prefix}.{original table name}, and then Jeecg’s form development can successfully find the data in the data source we expect. For example, zu_house is changed to zu.zu_house. (Remember to configure the corresponding data source in Jeecg’s online development – Multi-data Source Management)
Tips: Jeecg may cause data loss when synchronizing a database, so it is recommended that you back up your data before synchronizing.
Something to say to Jeecg
Although Jeecg can greatly improve the development efficiency of full stack engineers after mastering it, Jeecg has a new addition to the data table in form development that may be uncomfortable for the performance obsessive. For example, vARCHar or int Id, BIGINT cannot be used to store MyBatis corresponding snowflake algorithm increment Id. For distributed MySQL development, the best ID type is BIGINT + snowflake algorithm. However, you can’t use such a combination, but rather an ID column of type VARCHAR