Automatically generate entity classes (method 1)
YMP framework has supported automatic generation of entity class code through database table structure since v1.0, so v2.0 version not only reconstructs the entity code generator, but also makes it simpler and easier to use!
#------------------------------------- # JDBC数据实体代码生成器配置参数 #------------------------------------- # 是否生成新的BaseEntity类,默认为false(即表示使用框架提供的BaseEntity类) ymp.params.jdbc.use_base_entity= # 是否使用类名后缀,不使用和使用的区别如: User-->UserModel,默认为false ymp.params.jdbc.use_class_suffix= # 是否采用链式调用模式,默认为false ymp.params.jdbc.use_chain_mode= # 是否添加类成员属性值状态变化注解,默认为false ymp.params.jdbc.use_state_support= # 数据库名称(仅针对特定的数据库使用,如Oracle),默认为空 ymp.params.jdbc.db_name= # 数据库用户名称(仅针对特定的数据库使用,如Oracle),默认为空 ymp.params.jdbc.db_username= # 数据库表名称前缀,多个用'|'分隔,默认为空 ymp.params.jdbc.table_prefix= # 否剔除生成的实体映射表名前缀,默认为false ymp.params.jdbc.remove_table_prefix= # 预生成实体的数据表名称列表,多个用'|'分隔,默认为空表示全部生成 ymp.params.jdbc.table_list= # 排除的数据表名称列表,在此列表内的数据表将不被生成实体,多个用'|'分隔,默认为空 ymp.params.jdbc.table_exclude_list= # 生成的代码文件输出路径,默认为${root} ymp.params.jdbc.output_path= # 生成的代码所属包名称,默认为: packages ymp.params.jdbc.package_name=
In fact, you don’t need to configure anything (please refer to the above configuration item description and configure it according to the actual situation), but you need to pay attention to the following points during use Point:
The code generator relies on the JDBC persistence module to complete operations such as connecting to the database;
In multi-data source mode Below, the code generator uses the default data source;
The code generator relies on the freemarker template engine, so please check whether the dependencies are correct;
When running the code generator in the WEB project, please confirm whether the servlet-api and jsp-api package dependencies are correct;
If your project references a lot of modules, When running the code generator, you can temporarily exclude it through the ymp.excluded_modules parameter;
After understanding the above configuration, run the code generator directly:
net.ymate.platform.persistence.jdbc.scaffold.EntityGenerator
Find and run it. If it is a Maven project, you can execute it with the following command:
mvn compile exec:java -Dexec.mainClass="net.ymate.platform.persistence.jdbc.scaffold.EntityGenerator"
OK! It's that simple, it's all over!