When I use mybatis to write the ing between a class and a data table, there are too many column names in the table and there are also many problems. It is complicated to write the corresponding column names and Class Object Attributes one by one.
To facilitate and reduce errors, you can use the code generator provided by mybatis to automatically generate xml ing files, models, maps, and other information for mybatis.
Mybatis official website to download a mybatis-generator-core-1.3.2-bundle, In the compressed package find the jar package under Lib. Write mybatis. xml and execute it.
<Generatorconfiguration>
<! -- Here is the jar package address for loading the JDBC driver -->
<Classpathentry location = "C: \ Users \ administrator. WJ-20131202XSPS \ Desktop \ mybatis-generator-core-1.3.2 \ Lib \ mysql-connector-java-5.1.7-bin.jar"/>
<Context ID = "db2tables" targetruntime = "mybatis3">
<! -- Whether to remove automatically generated comments: true: Yes, false: No -->
<Commentgenerator>
<Property name = "suppressallcomments" value = "true"/>
</Commentgenerator>
<! -- Database connection information: Driver Class, connection address, user name, password -->
<Jdbcconnection driverclass = "com. MySQL. JDBC. Driver"
Connectionurl = "JDBC: mysql: // localhost/workloads" userid = "root" Password = "mysql0000366">
</Jdbcconnection>
<! -- The default value is false. The JDBC decimal and numeric types are parsed to integer true, and the JDBC decimal and numeric types are parsed to Java. Math. bigdecimal -->
<Javatyperesolver>
<Property name = "forcebigdecimals" value = "false"/>
</Javatyperesolver>
<! -- Application entity generation information -->
<Javamodelgenerator targetpackage = "com. tly. Entity"
Targetproject = "C: \ table">
<Property name = "enablesubpackages" value = "true"/>
<Property name = "trimstrings" value = "true"/>
</Javamodelgenerator>
<! -- Sqlmapper XML file generation information, including the generated path and other targetprojects, indicating the location where the generated file is stored -->
<Sqlmapgenerator targetpackage = "com. tly. Mapping" targetproject = "C: \ table">
<Property name = "enablesubpackages" value = "true"/>
</Sqlmapgenerator>
<Javaclientgenerator type = "xmlmapper"
Targetpackage = "com. tly. Dao" targetproject = "C: \ table">
<Property name = "enablesubpackages" value = "true"/>
</Javaclientgenerator>
<! -- Ing between tables in the database and objects in the program -->
<Table tablename = "project" domainobjectname = "classrecord" enablecountbyexample = "false" enableupdatebyexample = "false"
Enabledeletebyexample = "false" enableselectbyexample = "false" selectbyexamplequeryid = "false">
</Table>
<Table tablename = "project_score" domainobjectname = "parameter" enablecountbyexample = "false" enableupdatebyexample = "false"
Enabledeletebyexample = "false" enableselectbyexample = "false" selectbyexamplequeryid = "false">
</Table>
</Context>
</Generatorconfiguration>
In cmd enter Java-jar mybatis-generator-core-1.3.2.jar-configfile generator. XML-overwrite, the path here is absolute, for convenience, we can create a BAT file in the folder where the mybatis-generator-core-1.3.2 is located, enter
TXT code
- @ Echo off
- Echo =========== mybatis starts to generate code ============================
- Java-jar mybatis-generator-core-1.3.2.jar-configfile generator. XML-overwrite
- Echo =========== mybatis code generation complete ============================
Finally, we can press shift and right-click to open the command window in the folder and directly run the BAT file.