Install the MyBatis Generator code reverse generation tool under MyEclipse

1. Install the MyBatisGenerator code reverse generation tool

1. Offline mode:

Download at https://github.com/mybatis/generator/tree/master/eclipse/UpdateSite/

features/

plugins/

For all the jar packages in it, create a new mybatis-generator folder, drop the features and plugins into the mybatis-generator folder, move the mybatis-generator folder to D:\MyEclipse10_7\MyEclipse10\dropins, and create a new mbg. link, the content is as follows:

path=D:\MyEclipse10_7\MyEclipse10\dropins\mybatis-generator

Restart MyEclipse

 

2. Online way

Since offline installation is unsuccessful, you can choose online installation

1. Select Help->Install from site...

2. In the pop-up dialog box, click the Add button in the upper right corner.

3. Enter in the pop-up dialog

Name:mybatis

Location:https://dl.bintray.com/mybatis/mybatis-generator

(You can enter the above address in the location, or click Archive and select the jar and zip compressed files that have been downloaded locally: org.mybatis.generator.eclipse.site-1.3.5.201609070108.zip)

Click OK

4. Select mybatis in Work with - https://dl.bintray.com/mybatis/mybatis-generator or the local path of your own choice (personal recommendation is to download it first, choose local installation, so the speed is fast, online installation is too slow)

5. Check MyBatis Generator and click next

6. After the installation is complete, restart myeclipse.

2. Use of MyBatisGenerator tool

1. Eclipse method

1), create a new project, put the components and the configuration file config.xml in the corresponding directory 


2), write code to run in the main function

public static void main(String[] args)throws Exception {

   List<String> warnings = new ArrayList<String>();

   boolean overwrite = true;

   //point to reverse engineering configuration file

   File configFile = new File("generatorConfig.xml");

   ConfigurationParser cp = new ConfigurationParser(warnings);

   Configuration config = cp.parseConfiguration(configFile);

   DefaultShellCallback callback = new DefaultShellCallback(overwrite);

   MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,

           callback, warnings);

   myBatisGenerator.generate(null);

}

3), run it as an application

 

2. MyEclipse method

1), create a java project with myeclipse. 


 
Put 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>

   <classPathEntry

       location="/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 generation name-->

       <javaClientGenerator targetPackage="client"

           targetProject="testcore" type="XMLMAPPER" />

       <table schema="xx" tableName="xx"

           domainObjectName="xx">

       </table>

   </context>

</generatorConfiguration>

2) Download the mybatis/generator plug-in from github, and copy the features and plugins under the directory generator/eclipse/UpdateSite to the corresponding directory of myeclipse.
3), so that you can right-click generatorConfig.xml in myeclipse, find the option to generate mybatis artifacts, you can generate mapper, model, client, as shown below: 

If there is an error: Unexpectederror while running MyBatis Generator. Exception getting JDBC Driver 
This means <classPathEntry 
location="/opt/app-w/gitresp/testcore/src/main/webapp/WEB-INF/lib/mysql-connector- java-5.1.18.jar"/> 
There is a problem with the path here, the configuration can be solved!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325519551&siteId=291194637
Recommended