I haven't learned Java for a long time, mainly because I was lazy, and then I started playing games. Nan brother taught you to learn Java , I learned from him. Below are my lecture notes.
I learned reverse engineering this time. My understanding is: One-click generation tool ... Although it is not a mouse click and it came out, but I also wrote some code, and it came out and it was very easy to use.
First of all:
For this I have recreated a project. (The red circle is the remaining entity and repository written by yourself is automatically generated)
pom.xml file
<?xml version="1.0" encoding="UTF-8"?>
< project xmlns = " http://maven.apache.org/POM/4.0.0"
xmlns: xsi= " http://www.w3.org/2001/XMLSchema-instance"
xsi: schemaLocation= " http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
< modelVersion> 4.0.0</ modelVersion>
< groupId> com.southwind</ groupId>
< artifactId> aimgb</ artifactId>
< version> 1.0-SNAPSHOT</ version>
< dependencies>
< dependency>
< groupId> org.mybatis</ groupId>
< artifactId> mybatis</ artifactId>
< version> 3.5.3</ version>
</ dependency>
< dependency>
< groupId> mysql</ groupId>
< artifactId> mysql-connector-java</ artifactId>
< version> 8.0.19</ version>
</ dependency>
< dependency>
< groupId> org.mybatis.generator</ groupId>
< artifactId> mybatis-generator-core</ artifactId>
< version> 1.3.2</ version>
</ dependency>
</ dependencies>
</ project>
<?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>
< context id = " testTables" targetRuntime = " MyBatis3" >
< jdbcConnection driverClass = " com.mysql.cj.jdbc.Driver"
connectionURL = " jdbc:mysql://.......?useUnicode=true& characterEncoding=UTF-8"
userId = " "
password = " "
> </ jdbcConnection>
< javaModelGenerator targetPackage = " com.southwind.entity" targetProject = " ./src/main/java" > </ javaModelGenerator>
< sqlMapGenerator targetPackage = " com.southwind.repository" targetProject = " ./src/main/java" > </ sqlMapGenerator>
< javaClientGenerator type = " XMLMAPPER" targetPackage = " com.southwind.repository" targetProject = " ./src/main/java" > </ javaClientGenerator>
< table tableName = " goods" domainObjectName = " Goods" > </ table>
</ context>
</ generatorConfiguration>
package com. southwind. test;
import org. mybatis. generator. api. MyBatisGenerator;
import org. mybatis. generator. config. Configuration;
import org. mybatis. generator. config. xml. ConfigurationParser;
import org. mybatis. generator. exception. InvalidConfigurationException;
import org. mybatis. generator. exception. XMLParserException;
import org. mybatis. generator. internal. DefaultShellCallback;
import java. io. File;
import java. io. IOException;
import java. sql. SQLException;
import java. util. ArrayList;
import java. util. List;
public class Main {
public static void main ( String[ ] args) {
List< String> warings = new ArrayList < String> ( ) ;
boolean overwrite = true ;
String genCig = "/generatorConfig.xml" ;
File configFile = new File ( Main. class . getResource ( genCig) . getFile ( ) ) ;
ConfigurationParser configurationParser = new ConfigurationParser ( warings) ;
Configuration configuration = null ;
try {
configuration = configurationParser. parseConfiguration ( configFile) ;
} catch ( IOException e) {
e. printStackTrace ( ) ;
} catch ( XMLParserException e) {
e. printStackTrace ( ) ;
}
DefaultShellCallback callback = new DefaultShellCallback ( overwrite) ;
MyBatisGenerator myBatisGenerator = null;
try {
myBatisGenerator = new MyBatisGenerator ( configuration, callback, warings) ;
} catch ( InvalidConfigurationException e) {
e. printStackTrace ( ) ;
}
try {
myBatisGenerator. generate ( null) ;
} catch ( SQLException e) {
e. printStackTrace ( ) ;
} catch ( IOException e) {
e. printStackTrace ( ) ;
} catch ( InterruptedException e) {
e. printStackTrace ( ) ;
}
}
}
Then the operation is completed like my file directory. Is there any code that feels less thieves? It feels good to copy and paste it, it's pretty easy to use.