Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a6dfb84

Browse files
MyBatis Plus demo
1 parent 6a1e488 commit a6dfb84

File tree

12 files changed

+262
-0
lines changed

12 files changed

+262
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Spring Boot 使用的各种示例,以最简单、最实用为标准,此开
3333
- [spring-boot-webflux](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-webflux) :Spring Boot webflux 示例
3434
- [spring-boot-elasticsearch](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-elasticsearch) :Spring Boot elasticsearch 示例
3535
- [spring-boot-swagger](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-swagger) :Spring Boot swagger2 示例
36+
- [spring-boot-mybatis-plus](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-mybatis-plus) :Spring Boot 集成 MyBatis Plus 示例
3637

3738
**参考文章**
3839

‎README_EN.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ Spring Boot examples, using the simplest and the most useful scene demos.
2323
- [spring-boot-webflux](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-webflux) :Spring Boot webflux demo
2424
- [spring-boot-elasticsearch](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-elasticsearch) :Spring Boot elasticsearch demo
2525
- [spring-boot-swagger](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-swagger) :Spring Boot swagger2 demo
26+
- [spring-boot-mybatis-plus](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-mybatis-plus) :Spring Boot MyBatis Plus demo
27+
28+
2629
---
2730

2831
## Spring Boot (Already upgraded to 2.x)

‎spring-boot-mybatis-plus/pom.xml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example</groupId>
7+
<artifactId>spring-boot-mybatis-plus</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>Spring Boot MyBatis Plus</name>
12+
<description>Spring Boot 2 Demo</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>2.1.4.RELEASE</version>
18+
</parent>
19+
20+
<properties>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.projectlombok</groupId>
29+
<artifactId>lombok</artifactId>
30+
<optional>true</optional>
31+
</dependency>
32+
<dependency>
33+
<groupId>com.baomidou</groupId>
34+
<artifactId>mybatis-plus-boot-starter</artifactId>
35+
<version>3.1.1</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>com.h2database</groupId>
39+
<artifactId>h2</artifactId>
40+
<scope>runtime</scope>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-starter-test</artifactId>
45+
<scope>test</scope>
46+
</dependency>
47+
</dependencies>
48+
49+
<build>
50+
<plugins>
51+
<plugin>
52+
<groupId>org.springframework.boot</groupId>
53+
<artifactId>spring-boot-maven-plugin</artifactId>
54+
</plugin>
55+
</plugins>
56+
</build>
57+
58+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.neo;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class MyBatisPlusApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(MyBatisPlusApplication.class, args);
11+
}
12+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.neo.config;
2+
3+
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
4+
import org.mybatis.spring.annotation.MapperScan;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.Configuration;
7+
8+
@Configuration
9+
@MapperScan("com.neo.mapper")
10+
public class MybatisPlusConfig {
11+
12+
/**
13+
* 分页插件
14+
*/
15+
@Bean
16+
public PaginationInterceptor paginationInterceptor() {
17+
return new PaginationInterceptor();
18+
}
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.neo.mapper;
2+
3+
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4+
import com.neo.model.User;
5+
6+
public interface UserMapper extends BaseMapper<User> {
7+
8+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.neo.model;
2+
3+
import lombok.Data;
4+
5+
@Data
6+
public class User {
7+
private Long id;
8+
private String name;
9+
private Integer age;
10+
private String email;
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# DataSource Config
2+
spring:
3+
datasource:
4+
driver-class-name: org.h2.Driver
5+
schema: classpath:db/schema-h2.sql
6+
data: classpath:db/data-h2.sql
7+
url: jdbc:h2:mem:test
8+
username: root
9+
password: test
10+
11+
# Logger Config
12+
logging:
13+
level:
14+
com.neo: debug
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
DELETE FROM user;
2+
3+
INSERT INTO user (id, name, age, email) VALUES
4+
(1, 'neo', 18, 'smile1@ityouknow.com'),
5+
(2, 'keep', 36, 'smile@ityouknow.com'),
6+
(3, 'pure', 28, 'smile@ityouknow.com'),
7+
(4, 'smile', 21, 'smile@ityouknow.com'),
8+
(5, 'it', 24, 'smile@ityouknow.com');
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
DROP TABLE IF EXISTS user;
2+
3+
CREATE TABLE user
4+
(
5+
id BIGINT(20) NOT NULL COMMENT '主键ID',
6+
name VARCHAR(30) NULL DEFAULT NULL COMMENT '姓名',
7+
age INT(11) NULL DEFAULT NULL COMMENT '年龄',
8+
email VARCHAR(50) NULL DEFAULT NULL COMMENT '邮箱',
9+
PRIMARY KEY (id)
10+
);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /