Skip to content

Commit bb67250

Browse files
committed
ApiBoot Mybatis Pageable 示例
1 parent 997adbc commit bb67250

File tree

7 files changed

+328
-0
lines changed

7 files changed

+328
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright [2019] [恒宇少年 - 于起宇]
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
~
17+
-->
18+
19+
<project xmlns="http://maven.apache.org/POM/4.0.0"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<parent>
23+
<artifactId>api-boot-samples</artifactId>
24+
<groupId>org.minbox.framework</groupId>
25+
<version>2.0.6.RELEASE</version>
26+
</parent>
27+
<modelVersion>4.0.0</modelVersion>
28+
29+
<artifactId>api-boot-sample-mybatis-pageable</artifactId>
30+
31+
<description>
32+
ApiBoot Mybatis Pageable
33+
Mybatis查询自动分页插件示例
34+
</description>
35+
<dependencies>
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-starter-web</artifactId>
39+
</dependency>
40+
<!--ApiBoot Mybatis Pageable-->
41+
<dependency>
42+
<groupId>org.minbox.framework</groupId>
43+
<artifactId>api-boot-starter-mybatis-pageable</artifactId>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.minbox.framework</groupId>
47+
<artifactId>api-boot-starter-mybatis-enhance</artifactId>
48+
</dependency>
49+
<dependency>
50+
<groupId>com.alibaba</groupId>
51+
<artifactId>druid-spring-boot-starter</artifactId>
52+
</dependency>
53+
<dependency>
54+
<groupId>mysql</groupId>
55+
<artifactId>mysql-connector-java</artifactId>
56+
</dependency>
57+
</dependencies>
58+
<dependencyManagement>
59+
<dependencies>
60+
<dependency>
61+
<groupId>org.minbox.framework</groupId>
62+
<artifactId>api-boot-dependencies</artifactId>
63+
<scope>import</scope>
64+
<type>pom</type>
65+
<version>2.0.6.RELEASE</version>
66+
</dependency>
67+
</dependencies>
68+
</dependencyManagement>
69+
<build>
70+
<plugins>
71+
<plugin>
72+
<groupId>org.springframework.boot</groupId>
73+
<artifactId>spring-boot-maven-plugin</artifactId>
74+
</plugin>
75+
</plugins>
76+
</build>
77+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright [2019] [恒宇少年 - 于起宇]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.minbox.framework.api.boot.sample;
19+
20+
import org.springframework.boot.SpringApplication;
21+
import org.springframework.boot.autoconfigure.SpringBootApplication;
22+
23+
/**
24+
* ApiBoot Mybatis Pageable Application
25+
*
26+
* @author:恒宇少年 - 于起宇
27+
* <p>
28+
* DateTime:2019-04-26 16:08
29+
* Blog:http://blog.yuqiyu.com
30+
* WebSite:http://www.jianshu.com/u/092df3f77bca
31+
* Gitee:https://gitee.com/hengboy
32+
* GitHub:https://github.com/hengboy
33+
*/
34+
@SpringBootApplication
35+
public class ApiBootMybatisPageableApplication {
36+
37+
public static void main(String[] args) {
38+
SpringApplication.run(ApiBootMybatisPageableApplication.class, args);
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright [2019] [恒宇少年 - 于起宇]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.minbox.framework.api.boot.sample;
19+
20+
import com.gitee.hengboy.mybatis.pageable.Page;
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.web.bind.annotation.GetMapping;
23+
import org.springframework.web.bind.annotation.RestController;
24+
25+
/**
26+
* @author:恒宇少年 - 于起宇
27+
* <p>
28+
* DateTime:2019-04-26 16:12
29+
* Blog:http://blog.yuqiyu.com
30+
* WebSite:http://www.jianshu.com/u/092df3f77bca
31+
* Gitee:https://gitee.com/hengboy
32+
* GitHub:https://github.com/hengboy
33+
*/
34+
@RestController
35+
public class MybatisPageableSampleController {
36+
37+
@Autowired
38+
private MybatisPageableSampleService mybatisPageableSampleService;
39+
40+
@GetMapping(value = "/users")
41+
public Page<UserEntity> list() {
42+
return mybatisPageableSampleService.pageable();
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright [2019] [恒宇少年 - 于起宇]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.minbox.framework.api.boot.sample;
19+
20+
import com.gitee.hengboy.mybatis.pageable.Page;
21+
import com.gitee.hengboy.mybatis.pageable.request.PageableRequest;
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.stereotype.Service;
24+
25+
import java.util.List;
26+
27+
/**
28+
* Mybatis Pageable Sample Service
29+
*
30+
* @author:恒宇少年 - 于起宇
31+
* <p>
32+
* DateTime:2019-04-26 16:13
33+
* Blog:http://blog.yuqiyu.com
34+
* WebSite:http://www.jianshu.com/u/092df3f77bca
35+
* Gitee:https://gitee.com/hengboy
36+
* GitHub:https://github.com/hengboy
37+
*/
38+
@Service
39+
public class MybatisPageableSampleService {
40+
41+
@Autowired
42+
private UserMapper userMapper;
43+
44+
/**
45+
* 自动分页查询
46+
*
47+
* @return
48+
*/
49+
public Page<UserEntity> pageable() {
50+
return PageableRequest.of(1, 1).request(() -> listAll());
51+
}
52+
53+
/**
54+
* 查询全部用户
55+
*
56+
* @return
57+
*/
58+
public List<UserEntity> listAll() {
59+
return userMapper.selectAll();
60+
}
61+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright [2019] [恒宇少年 - 于起宇]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.minbox.framework.api.boot.sample;
19+
20+
import com.gitee.hengboy.mybatis.enhance.common.annotation.Column;
21+
import com.gitee.hengboy.mybatis.enhance.common.annotation.Id;
22+
import com.gitee.hengboy.mybatis.enhance.common.annotation.Table;
23+
import com.gitee.hengboy.mybatis.enhance.common.enums.KeyGeneratorTypeEnum;
24+
import lombok.Data;
25+
26+
/**
27+
* Mybatis Enhance 所需用户实体
28+
*
29+
* @author:恒宇少年 - 于起宇
30+
* <p>
31+
* DateTime:2019-04-26 16:14
32+
* Blog:http://blog.yuqiyu.com
33+
* WebSite:http://www.jianshu.com/u/092df3f77bca
34+
* Gitee:https://gitee.com/hengboy
35+
* GitHub:https://github.com/hengboy
36+
*/
37+
@Data
38+
@Table(name = "local_user_info")
39+
public class UserEntity {
40+
41+
@Column(name = "ui_id")
42+
@Id(generatorType = KeyGeneratorTypeEnum.UUID)
43+
private String uiId;
44+
45+
@Column(name = "ui_phone")
46+
private String uiPhone;
47+
48+
@Column(name = "ui_password")
49+
private String uiPassword;
50+
51+
@Column(name = "ui_status")
52+
private String uiStatus;
53+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright [2019] [恒宇少年 - 于起宇]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.minbox.framework.api.boot.sample;
19+
20+
import com.gitee.hengboy.mybatis.enhance.mapper.EnhanceMapper;
21+
22+
/**
23+
* Mybatis Enhance Mapper
24+
*
25+
* @author:恒宇少年 - 于起宇
26+
* <p>
27+
* DateTime:2019-04-26 16:16
28+
* Blog:http://blog.yuqiyu.com
29+
* WebSite:http://www.jianshu.com/u/092df3f77bca
30+
* Gitee:https://gitee.com/hengboy
31+
* GitHub:https://github.com/hengboy
32+
*/
33+
public interface UserMapper extends EnhanceMapper<UserEntity, String> {
34+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
spring:
2+
application:
3+
name: api-boot-sample-mybatis-pageable
4+
datasource:
5+
druid:
6+
url: jdbc:mysql://localhost:3306/test?characterEncoding=utf8&serverTimezone=Asia/Shanghai
7+
driver-class-name: com.mysql.cj.jdbc.Driver
8+
username: root
9+
password: 123456
10+
11+
api:
12+
boot:
13+
# 数据库方言设置,默认为mysql
14+
pageable:
15+
dialect: mysql
16+
17+
logging:
18+
level:
19+
org.minbox.framework.api.boot.sample: debug

0 commit comments

Comments
 (0)