MyBatis can also generate code in the direction of generating entity Class (PO), mapper interface and Mapper interface mapping file, can reduce the workload of our Code. Detailed steps are as follows
1, download MyBatis Generation Rack Package tool Mybatis_generator_1.3.1.zip, decompression rack package to features, plugins folder under the package to copy to the Eclipse installation directory features, plugins folder. It's OK to restart Eclipse.
After decompression the picture is as follows:
The eclipse path is shown in figure:
Copy Replacement as shown:
2, create generatorconfig.xml files, install a good mybatis can be created Generatorconfig.xml
3, configuration generatorconfig.xml configuration file, detailed as follows
<?xml version= "1.0" encoding= "UTF-8"?> <! DOCTYPE generatorconfiguration Public "-//mybatis.org//dtd mybatis generator Configuration" "1.0//en Mybatis.org/dtd/mybatis-generator-config_1_0.dtd "> <generatorConfiguration> <!--<classpathentry location= "D:\rep\mysql\mysql-connector-java\5.1.19\mysql-connector-java-5.1.19.jar"/>--> < Classpathentry location= "D:\repo\com\oracle\ojdbc14\10.2.0.1.0\ojdbc14-10.2.0.1.0.jar"/> <context id= " Db2tables "targetruntime=" MyBatis3 "> <commentGenerator> <property name=" suppressallcomments "value=" True '/> <property name= ' suppressdate value= ' true '/> </commentGenerator> <jdbcconnection driv erclass= "Oracle.jdbc.driver.OracleDriver" connectionurl= Jdbc:oracle:thin: @xxx. Xxx.xxx.xxx:1521:orcl4 "Userid=" xxx "password=" xxxx "/> <javaTypeResolver> <property name=" Forcebigdecimals "value=" false "/> < !--default False to resolve the JDBC DECIMAL and NUMERIC types toInteger true to resolve the JDBC DECIMAL and NUMERIC types to Java.math.BigDecimal--> </javaTypeResolver> <javamodelgenerato R targetpackage= "Com.pcmall.domain.sale.order" targetproject= "Pos-service/src/main/java" > <property name= "
Enablesubpackages "value=" true "/> <property name=" trimstrings "value=" true "/> </javaModelGenerator>
<sqlmapgenerator targetpackage= "Mybatis.mapper.sale.order" targetproject= "Pos-service/src/main/resources" > <property name= "Enablesubpackages" value= "false"/> </sqlMapGenerator> <javaclientgenerator Targetpac Kage= "Com.pcmall.dao.sale.order" targetproject= "Pos-service/src/main/java" type= "Xmlmapper" > <property name= "Enablesubpackages" value= "false"/> </javaClientGenerator> <table tablename= "HS_ZXZFLX" Enableselectbye Xample= "false" enabledeletebyexample= "false" enablecountbyexample= "false" selectbyexamplequeryid= "true" Enableupdatebyexample= "false" > <!--<GENERATEDKEY column= "ID" sqlstatement= "Oracle" identity= "true"/>--> </table> </context> </generatorconfig Uration>
4, right click Generatorconfig.xml click Generate mybatis/ibatis artifacts generate corresponding interface, interface mapping file, entity class
5, view the results