Custom GenerateMysqlEntity class
Singleton mode:
Entry:
Generate method next
Database information:
DataBaseUtils
Reference: juejin. Cn/post / 699434…
Static data used:
Generate entity class file:
Generate all contents of class:
StringBuffer class
Construct a characterless string buffer with an initial capacity of 16 characters
CommonUtils.getTransStr
Reference: juejin. Cn/post / 699585…
getKeyStringList
Generate a Key list (a list of fields in a database table)
Generated effect:
getKeyLabelList
Generate comments corresponding to keys
Generated effect:
processAllAttrs
Generate all member variables
Generated effect:
sqlType2JavaType
Find the Java type corresponding to the SQL field type
Summary steps:
-
Get table information. (Use DataBaseUtils)
-
Gets the root directory path. (File type)
-
Return the absolute path of packageOutPath (com.api.johnzeng.Entity).
-
Generate file instance of packageOutPath (com.api.johnzeng.Entity).
-
Generate packageOutPath (com.api.johnzeng.Entity) directory.
-
Traverse tableInfoList.
- Generate file content.
- Use FileWriter, PrintWriter, write content, output to Entity (com.api.johnzeng.Entity) directory
Use of entity classes:
Configuration MyBatisPlugsConfig
Create mapper
Place mapper in the Mapper directory and MapperScan will scan for it
The service layer using
- Inject mapper using @autoWired
- Initialize the QueryWrapper class for the singleton
- Refer to the Documentation of Maybatis Plus for instructions