When using MyBatis docking data, manual write Mapper,model,client will be time-consuming, you can try mybatis_gererator to generate more difficult mybatis configuration files.
Start with MyEclipse to create the Java project.
Place the Mysql-connector-java-5.1.18.jar in the specified directory project and configure Generatorconfig.xml.
<?xml version= "1.0" encoding= "UTF-8"?><! DOCTYPE generatorconfiguration Public "-//mybatis.org//dtd mybatis Generator Configuration 1.0//en" "/http Mybatis.org/dtd/mybatis-generator-config_1_0.dtd "><generatorconfiguration> <classpathentrylocation ="/opt/app-w/gitresp/testcore/src/main/webapp/web-inf/lib/ Mysql-connector-java-5.1.18.jar " /> <context id="Context1"> <jdbcconnection driverclass="Com.mysql.jdbc.Driver"connectionurl= "Jdbc:mysql://ip:3306/xx?useunicode=true&characterencoding=utf-8" userId="root" password="123456" /> <javamodelgenerator targetpackage="model"targetproject="Testcore " /> <sqlmapgenerator targetpackage= "mapper" targetproject=" Testcore " /> <!--database table name to generate a name -- <javaclientgenerator targetpackage= "client"targetproject=" Testcore " type=" Xmlmapper "/> <table Schema="xx " tableName="xx " Domainobjectname="xx"> </table> </Context></generatorconfiguration>
Then download the Mybatis/generator plugin on GitHub, git clone https://github.com/mybatis/generator.git. and put the directory generator/eclipse/ Updatesite the following features and plugins are copied to the myeclipse corresponding directory.
You can then right-click the generatorconfig.xml in MyEclipse and find the Generate mybatis artifacts option to generate mapper,model,client, such as:
If an error occurs: Unexpected error while running MyBatis Generator. Exception getting JDBC Driver
That's what <classPathEntry
location="/opt/app-w/gitresp/testcore/src/main/webapp/WEB-INF/lib/mysql-connector-java-5.1.18.jar" />
it means.
There is a problem with the path, the configuration can be solved!
MyEclipse Configuring Mybatis_generator Generation Mapper,model,client