Skip to content

Commit 34c234d

Browse files
authored
mybatis-generator & mybatis plus (#30)
* group mybatis modules * Init DDL and DML * Regenerate * Regenerate * Regenerate and fix testcases * Rename module name * Add mybatis plus example
1 parent 3f95f76 commit 34c234d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1610
-2001
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252

5353
<dependencyManagement>
5454
<dependencies>
55+
<dependency>
56+
<groupId>org.projectlombok</groupId>
57+
<artifactId>lombok</artifactId>
58+
<version>1.18.30</version>
59+
</dependency>
5560
<dependency>
5661
<groupId>com.google.guava</groupId>
5762
<artifactId>guava</artifactId>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
How to generate:
2+
3+
Set `generator.generate` to true
4+
5+
Run `GeneratorApplication`
6+
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>alex</groupId>
7+
<artifactId>spring-boot-mybatis</artifactId>
8+
<version>0.1.0-SNAPSHOT</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
12+
<artifactId>mybatis-generator</artifactId>
13+
<version>0.1.0-SNAPSHOT</version>
14+
<packaging>jar</packaging>
15+
16+
<properties>
17+
<h2.version>2.2.224</h2.version>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.mybatis.spring.boot</groupId>
23+
<artifactId>mybatis-spring-boot-starter</artifactId>
24+
<version>3.0.3</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.mybatis.generator</groupId>
28+
<artifactId>mybatis-generator-core</artifactId>
29+
<version>1.4.2</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>com.h2database</groupId>
33+
<artifactId>h2</artifactId>
34+
<version>${h2.version}</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.projectlombok</groupId>
38+
<artifactId>lombok</artifactId>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-starter-test</artifactId>
44+
<scope>test</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.mybatis.spring.boot</groupId>
48+
<artifactId>mybatis-spring-boot-starter-test</artifactId>
49+
<version>3.0.3</version>
50+
<scope>test</scope>
51+
</dependency>
52+
</dependencies>
53+
54+
<build>
55+
<resources>
56+
<resource>
57+
<directory>src/main/resources</directory>
58+
</resource>
59+
<resource>
60+
<directory>src/main/java</directory>
61+
<excludes>
62+
<exclude>**/*.java</exclude>
63+
</excludes>
64+
</resource>
65+
</resources>
66+
<plugins>
67+
<plugin>
68+
<groupId>org.springframework.boot</groupId>
69+
<artifactId>spring-boot-maven-plugin</artifactId>
70+
</plugin>
71+
<plugin>
72+
<groupId>org.mybatis.generator</groupId>
73+
<artifactId>mybatis-generator-maven-plugin</artifactId>
74+
<version>1.4.2</version>
75+
<configuration>
76+
<configurationFile>${project.basedir}/src/main/resources/generatorConfig.xml</configurationFile>
77+
<verbose>true</verbose>
78+
<overwrite>true</overwrite>
79+
</configuration>
80+
<dependencies>
81+
<dependency>
82+
<groupId>com.h2database</groupId>
83+
<artifactId>h2</artifactId>
84+
<version>${h2.version}</version>
85+
</dependency>
86+
<dependency>
87+
<groupId>alex</groupId>
88+
<artifactId>mybatis-generator</artifactId>
89+
<version>0.1.0-SNAPSHOT</version>
90+
</dependency>
91+
</dependencies>
92+
</plugin>
93+
</plugins>
94+
</build>
95+
</project>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package alex;
2+
3+
import java.io.File;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import lombok.extern.java.Log;
7+
import org.mybatis.generator.api.MyBatisGenerator;
8+
import org.mybatis.generator.api.VerboseProgressCallback;
9+
import org.mybatis.generator.config.Configuration;
10+
import org.mybatis.generator.config.xml.ConfigurationParser;
11+
import org.mybatis.generator.internal.DefaultShellCallback;
12+
import org.mybatis.spring.annotation.MapperScan;
13+
import org.springframework.beans.factory.annotation.Value;
14+
import org.springframework.boot.CommandLineRunner;
15+
import org.springframework.boot.SpringApplication;
16+
import org.springframework.boot.autoconfigure.SpringBootApplication;
17+
import org.springframework.util.ResourceUtils;
18+
19+
/** Created by qct on 2017/10/5. */
20+
@SpringBootApplication
21+
@MapperScan("alex.dao")
22+
@Log
23+
public class GeneratorApplication implements CommandLineRunner {
24+
25+
@Value("${generator.generate}")
26+
boolean generate;
27+
28+
public static void main(String[] args) {
29+
SpringApplication.run(GeneratorApplication.class, args);
30+
}
31+
32+
@Override
33+
public void run(String... args) throws Exception {
34+
if (!generate) {
35+
log.info("generator.generate is false, skip generator");
36+
return;
37+
}
38+
39+
List<String> warnings = new ArrayList<>();
40+
boolean overwrite = true;
41+
42+
File configFile = ResourceUtils.getFile("classpath:generatorConfig.xml");
43+
ConfigurationParser cp = new ConfigurationParser(warnings);
44+
Configuration config = cp.parseConfiguration(configFile);
45+
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
46+
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
47+
myBatisGenerator.generate(new VerboseProgressCallback());
48+
49+
warnings.forEach(log::warning);
50+
}
51+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package alex.dao;
2+
3+
import alex.dto.Person;
4+
5+
public interface PersonMapper {
6+
/**
7+
* This method was generated by MyBatis Generator.
8+
* This method corresponds to the database table person
9+
*
10+
* @mbg.generated Mon Nov 27 23:50:17 GST 2023
11+
*/
12+
int deleteByPrimaryKey(Integer id);
13+
14+
/**
15+
* This method was generated by MyBatis Generator.
16+
* This method corresponds to the database table person
17+
*
18+
* @mbg.generated Mon Nov 27 23:50:17 GST 2023
19+
*/
20+
int insert(Person row);
21+
22+
/**
23+
* This method was generated by MyBatis Generator.
24+
* This method corresponds to the database table person
25+
*
26+
* @mbg.generated Mon Nov 27 23:50:17 GST 2023
27+
*/
28+
int insertSelective(Person row);
29+
30+
/**
31+
* This method was generated by MyBatis Generator.
32+
* This method corresponds to the database table person
33+
*
34+
* @mbg.generated Mon Nov 27 23:50:17 GST 2023
35+
*/
36+
Person selectByPrimaryKey(Integer id);
37+
38+
/**
39+
* This method was generated by MyBatis Generator.
40+
* This method corresponds to the database table person
41+
*
42+
* @mbg.generated Mon Nov 27 23:50:17 GST 2023
43+
*/
44+
int updateByPrimaryKeySelective(Person row);
45+
46+
/**
47+
* This method was generated by MyBatis Generator.
48+
* This method corresponds to the database table person
49+
*
50+
* @mbg.generated Mon Nov 27 23:50:17 GST 2023
51+
*/
52+
int updateByPrimaryKey(Person row);
53+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package alex.dao;
2+
3+
import alex.dto.School;
4+
5+
public interface SchoolMapper {
6+
/**
7+
* This method was generated by MyBatis Generator.
8+
* This method corresponds to the database table school
9+
*
10+
* @mbg.generated Mon Nov 27 23:50:17 GST 2023
11+
*/
12+
int deleteByPrimaryKey(Integer id);
13+
14+
/**
15+
* This method was generated by MyBatis Generator.
16+
* This method corresponds to the database table school
17+
*
18+
* @mbg.generated Mon Nov 27 23:50:17 GST 2023
19+
*/
20+
int insert(School row);
21+
22+
/**
23+
* This method was generated by MyBatis Generator.
24+
* This method corresponds to the database table school
25+
*
26+
* @mbg.generated Mon Nov 27 23:50:17 GST 2023
27+
*/
28+
int insertSelective(School row);
29+
30+
/**
31+
* This method was generated by MyBatis Generator.
32+
* This method corresponds to the database table school
33+
*
34+
* @mbg.generated Mon Nov 27 23:50:17 GST 2023
35+
*/
36+
School selectByPrimaryKey(Integer id);
37+
38+
/**
39+
* This method was generated by MyBatis Generator.
40+
* This method corresponds to the database table school
41+
*
42+
* @mbg.generated Mon Nov 27 23:50:17 GST 2023
43+
*/
44+
int updateByPrimaryKeySelective(School row);
45+
46+
/**
47+
* This method was generated by MyBatis Generator.
48+
* This method corresponds to the database table school
49+
*
50+
* @mbg.generated Mon Nov 27 23:50:17 GST 2023
51+
*/
52+
int updateByPrimaryKey(School row);
53+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package alex.dto;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
@Data
9+
@Builder
10+
@NoArgsConstructor
11+
@AllArgsConstructor
12+
public class Person {
13+
/**
14+
*
15+
* This field was generated by MyBatis Generator.
16+
* This field corresponds to the database column person.id
17+
*
18+
* @mbg.generated Mon Nov 27 23:50:17 GST 2023
19+
*/
20+
private Integer id;
21+
22+
/**
23+
*
24+
* This field was generated by MyBatis Generator.
25+
* This field corresponds to the database column person.name
26+
*
27+
* @mbg.generated Mon Nov 27 23:50:17 GST 2023
28+
*/
29+
private String name;
30+
31+
/**
32+
*
33+
* This field was generated by MyBatis Generator.
34+
* This field corresponds to the database column person.address
35+
*
36+
* @mbg.generated Mon Nov 27 23:50:17 GST 2023
37+
*/
38+
private String address;
39+
40+
/**
41+
*
42+
* This field was generated by MyBatis Generator.
43+
* This field corresponds to the database column person.age
44+
*
45+
* @mbg.generated Mon Nov 27 23:50:17 GST 2023
46+
*/
47+
private Integer age;
48+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package alex.dto;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
@Data
9+
@Builder
10+
@NoArgsConstructor
11+
@AllArgsConstructor
12+
public class School {
13+
/**
14+
*
15+
* This field was generated by MyBatis Generator.
16+
* This field corresponds to the database column school.id
17+
*
18+
* @mbg.generated Mon Nov 27 23:50:17 GST 2023
19+
*/
20+
private Integer id;
21+
22+
/**
23+
*
24+
* This field was generated by MyBatis Generator.
25+
* This field corresponds to the database column school.name
26+
*
27+
* @mbg.generated Mon Nov 27 23:50:17 GST 2023
28+
*/
29+
private String name;
30+
}

0 commit comments

Comments
 (0)