Using MyBatis generator can generate mybatis corresponding mapper and model according to the database table, the generated example can satisfy the general single table operation, use MyBatis annotation, The @mbggenerated can be used to overwrite the generated code at the next build, without affecting the manually added query (the Eclipse plugin that needs to be used, IntelliJ does not currently have a similar plugin), in the use of IntelliJ, can use the free MyBatis plug-in, can quickly locate in the Mapper class to the corresponding XML, very advantageous to SQL view;
MyBatis Configuration:
<?XML version= "1.0" encoding= "UTF-8"?> <!DOCTYPE generatorconfiguration Public "-//mybatis.org//dtd mybatis Generator Configuration 1.0//en" "Htt P://mybatis.org/dtd/mybatis-generator-config_1_0.dtd "><generatorconfiguration><Classpathentry Location= "${jdbc.driverlocation}" /> <!--Database-driven - <Classpathentry Location= "${jdbc.driverlocation}" /> <ContextID= "Db2tables"Targetruntime= "MyBatis3"> <Commentgenerator> <!--@mbggenerated the generated configuration - < Propertyname= "Suppressdate"value= "false" /> <!--whether to remove automatically generated comments true: Yes: false: No - < Propertyname= "Suppressallcomments"value= "true" /> </Commentgenerator> <!--database link URL, user name, password - <jdbcconnectionDriverclass= "Com.mysql.jdbc.Driver"Connectionurl= "${jdbc.connectionurl}"userId= "${jdbc.userid}"Password= "${jdbc.password}" /> <Javatyperesolver> < Propertyname= "Forcebigdecimals"value= "false" /> </Javatyperesolver> <!--Build the package name and location of the model - <JavamodelgeneratorTargetpackage= "${modelpackage_name}"Targetproject= "Mybatis_generator"> < Propertyname= "Enablesubpackages"value= "true" /> < Propertyname= "Trimstrings"value= "false" /> </Javamodelgenerator> <!--Build the package name and location of the mapping file - <SqlmapgeneratorTargetpackage= "${mapperpackage_name}"Targetproject= "Mybatis_generator"> < Propertyname= "Enablesubpackages"value= "true" /> </Sqlmapgenerator> <!--generate DAO's package name and location - <Javaclientgeneratortype= "Xmlmapper"Targetpackage= "${daopackage_name}"Targetproject= "Mybatis_generator"> < Propertyname= "Enablesubpackages"value= "true" /> </Javaclientgenerator> <!--which tables to generate - <TableTableName= "${table_name}"Domainobjectname= "${model_name}"Enablecountbyexample= "true"Enableupdatebyexample= "true"Enabledeletebyexample= "true"Enableselectbyexample= "true"Selectbyexamplequeryid= "true"> </Table> </Context></generatorconfiguration>
Config configuration:
jdbc.driverlocation=e://mysql-connector-java-5.1.18-bin.jarjdbc.driverclass= Com.mysql.jdbc.driverjdbc.connectionurl=jdbc:mysql://ip:port/test?useunicode=true& Characterencoding=utf-8jdbc.userid=jdbc.password= #模型的包名modelpackage_name = #dao的包名daopackage_name =# XML storage location mapperpackage_name=mapper# table name table_name=temp# The name of the generated model Model_name=temp
Attention:
Generate MyBatis corresponding model and DAO Mapper.xml based on database table, in addition to configuration item configuration, if you want to build into another project (currently only generated in
Under this project), you need to modify the Targetproject property of the Generator-config.xml (configured in the properties
Generator-config.xml can not be effective, so can only be manually changed, Targetproject property as long as the other project name is good)
MyBatis generator automatically generates mapper files and model