Skip to content

Commit 5288f39

Browse files
committed
"mybatis-enhance" and "mybatis-pageable" example
1 parent 21ee9c8 commit 5288f39

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

api-boot-samples/api-boot-sample-mybatis-enhance/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
<groupId>org.minbox.framework</groupId>
3939
<artifactId>api-boot-starter-mybatis-enhance</artifactId>
4040
</dependency>
41+
<!--ApiBoot Mybatis Pageable-->
42+
<dependency>
43+
<groupId>org.minbox.framework</groupId>
44+
<artifactId>api-boot-starter-mybatis-pageable</artifactId>
45+
</dependency>
4146
<dependency>
4247
<groupId>com.alibaba</groupId>
4348
<artifactId>druid-spring-boot-starter</artifactId>

api-boot-samples/api-boot-sample-mybatis-enhance/src/main/java/org/minbox/framework/api/boot/sample/mybatis/enhance/mapper/SystemUserMapper.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,12 @@ public interface SystemUserMapper extends EnhanceMapper<SystemUser> {
8989
* @param userStatus
9090
*/
9191
void removeByUserNameAndStatus(@Param("userName") String userName, @Param("status") Integer userStatus);
92+
93+
/**
94+
* XML方式查询用户
95+
*
96+
* @param user 查询条件
97+
* @return 返回的结果
98+
*/
99+
List<SystemUser> selectUsers(@Param("userName") String userName);
92100
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
3+
<mapper namespace="org.minbox.framework.api.boot.sample.mybatis.enhance.mapper.SystemUserMapper">
4+
5+
<select id="selectUsers" resultType="org.minbox.framework.api.boot.sample.mybatis.enhance.entity.SystemUser">
6+
select * from iot_system_user
7+
<where>
8+
<if test="userName!=null">
9+
and su_user_name = #{userName}
10+
</if>
11+
</where>
12+
</select>
13+
</mapper>

api-boot-samples/api-boot-sample-mybatis-enhance/src/test/java/org/minbox/framework/api/boot/sample/mybatis/enhance/ApiBootEnhanceSampleTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@
1717

1818
package org.minbox.framework.api.boot.sample.mybatis.enhance;
1919

20+
import com.alibaba.fastjson.JSON;
21+
import com.gitee.hengboy.mybatis.enhance.dsl.factory.EnhanceDslFactory;
22+
import com.gitee.hengboy.mybatis.pageable.Page;
23+
import com.gitee.hengboy.mybatis.pageable.request.PageableRequest;
24+
import org.junit.Assert;
2025
import org.junit.Test;
2126
import org.junit.runner.RunWith;
27+
import org.minbox.framework.api.boot.sample.mybatis.enhance.dsl.DSystemUser;
2228
import org.minbox.framework.api.boot.sample.mybatis.enhance.dto.SystemUserDTO;
2329
import org.minbox.framework.api.boot.sample.mybatis.enhance.entity.SystemUser;
2430
import org.minbox.framework.api.boot.sample.mybatis.enhance.mapper.SystemUserMapper;
@@ -53,6 +59,9 @@ public class ApiBootEnhanceSampleTest {
5359
@Autowired
5460
private SystemUserService systemUserService;
5561

62+
@Autowired
63+
private EnhanceDslFactory dslFactory;
64+
5665
@Autowired
5766
private SystemUserMapper systemUserMapper;
5867

@@ -184,4 +193,19 @@ public void removeNamed() {
184193
systemUserMapper.removeByUserNameAndStatus("admin", 0);
185194
}
186195

196+
@Test
197+
public void selectUsers() {
198+
Page<SystemUser> userPage = PageableRequest.of(1, 1).request(() -> {
199+
DSystemUser dSystemUser = DSystemUser.DSL();
200+
dslFactory.createSearchable()
201+
.selectFrom(dSystemUser)
202+
.where(dSystemUser.userName.eq("admin"))
203+
.resultType(SystemUser.class)
204+
.fetch();
205+
});
206+
System.out.println(userPage.getTotalElements());
207+
List<SystemUser> users = userPage.getData();
208+
Assert.assertNotNull(users);
209+
System.out.println(JSON.toJSONString(users));
210+
}
187211
}

0 commit comments

Comments
 (0)