Skip to content

Commit 878c86e

Browse files
committed
Merge branch 'develop'
# Conflicts: # README.md # lambda-query-core/pom.xml # lambda-query-mongo/pom.xml # mongo-demo/pom.xml # pom.xml
2 parents 912fe41 + 5e4fde4 commit 878c86e

File tree

49 files changed

+1512
-198
lines changed

Some content is hidden

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

49 files changed

+1512
-198
lines changed

.gitignore

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### JetBrains template
3+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
4+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
5+
6+
# User-specific stuff
7+
.idea/**/workspace.xml
8+
.idea/**/tasks.xml
9+
.idea/**/usage.statistics.xml
10+
.idea/**/dictionaries
11+
.idea/**/shelf
12+
13+
# Generated files
14+
.idea/**/contentModel.xml
15+
16+
# Sensitive or high-churn files
17+
.idea/**/dataSources/
18+
.idea/**/dataSources.ids
19+
.idea/**/dataSources.local.xml
20+
.idea/**/sqlDataSources.xml
21+
.idea/**/dynamic.xml
22+
.idea/**/uiDesigner.xml
23+
.idea/**/dbnavigator.xml
24+
25+
# Gradle
26+
.idea/**/gradle.xml
27+
.idea/**/libraries
28+
29+
# Gradle and Maven with auto-import
30+
# When using Gradle or Maven with auto-import, you should exclude module files,
31+
# since they will be recreated, and may cause churn. Uncomment if using
32+
# auto-import.
33+
# .idea/artifacts
34+
# .idea/compiler.xml
35+
# .idea/jarRepositories.xml
36+
# .idea/modules.xml
37+
# .idea/*.iml
38+
# .idea/modules
39+
# *.iml
40+
# *.ipr
41+
42+
# CMake
43+
cmake-build-*/
44+
45+
# Mongo Explorer plugin
46+
.idea/**/mongoSettings.xml
47+
48+
# File-based project format
49+
*.iws
50+
51+
# IntelliJ
52+
out/
53+
54+
# mpeltonen/sbt-idea plugin
55+
.idea_modules/
56+
57+
# JIRA plugin
58+
atlassian-ide-plugin.xml
59+
60+
# Cursive Clojure plugin
61+
.idea/replstate.xml
62+
63+
# Crashlytics plugin (for Android Studio and IntelliJ)
64+
com_crashlytics_export_strings.xml
65+
crashlytics.properties
66+
crashlytics-build.properties
67+
fabric.properties
68+
69+
# Editor-based Rest Client
70+
.idea/httpRequests
71+
72+
# Android studio 3.1+ serialized cache file
73+
.idea/caches/build_file_checksums.ser
74+
75+
### Java template
76+
# Compiled class file
77+
*.class
78+
79+
# Log file
80+
*.log
81+
82+
# BlueJ files
83+
*.ctxt
84+
85+
# Mobile Tools for Java (J2ME)
86+
.mtj.tmp/
87+
88+
# Package Files #
89+
*.jar
90+
*.war
91+
*.nar
92+
*.ear
93+
*.zip
94+
*.tar.gz
95+
*.rar
96+
97+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
98+
hs_err_pid*
99+

README.md

Lines changed: 232 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# lambda-query 1.0 版本
2-
[![](https://travis-ci.org/xuejike/lambda-query.svg?branch=master)]
3-
4-
2+
[![](https://travis-ci.org/xuejike/lambda-query.svg?branch=master)](https://github.com/xuejike/lambda-query)
3+
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.xuejike/lambda-query/badge.svg)](https://mvnrepository.com/artifact/com.github.xuejike)
54
## 介绍
65
LambdaQuery 将支持通过Lambda进行多种数据源的查询 实现java端的简单数据的统一查询
76
## 功能规划
@@ -10,7 +9,7 @@ LambdaQuery 将支持通过Lambda进行多种数据源的查询 实现java端的
109
* [ ] 实现 新增,删除,更新等基础操作[开发中]
1110

1211
### 2. mybatis-plus
13-
* [ ] 接入mybatis-plus的查询接口
12+
* [x] 接入mybatis-plus的查询接口(已完成)
1413
* [ ] 接入mybatis-plus 的新增,删除,更新操作
1514
* [ ] 新增LoadJoin功能,通过selectIn的方式进行数据表join
1615
* [ ] 新增Cache功能,采用redis 进行数据缓存,配合selectIn方式避免join查询直接访问数据库
@@ -46,13 +45,236 @@ LambdaQuery 将支持通过Lambda进行多种数据源的查询 实现java端的
4645

4746

4847

49-
### 3.持久化操作
48+
## 使用说明
49+
### 1.依赖引入
50+
1. springBoot自动配置
51+
```xml
52+
<!--Mongo 查询器依赖-->
53+
<dependency>
54+
<groupId>com.github.xuejike</groupId>
55+
<artifactId>lambda-query-mongo-starter</artifactId>
56+
<version>${jkquery.version}</version>
57+
</dependency>
58+
<!--MybatisPlus 查询器依赖-->
59+
60+
<dependency>
61+
<groupId>com.github.xuejike</groupId>
62+
<artifactId>lambda-query-mybatis-plus-starter</artifactId>
63+
<version>${jkquery.version}</version>
64+
</dependency>
65+
66+
```
67+
2. 手动配置
68+
69+
引入依赖
70+
```xml
71+
<!--Mongo 查询器依赖-->
72+
<dependency>
73+
<groupId>com.github.xuejike</groupId>
74+
<artifactId>lambda-query-mongo</artifactId>
75+
<version>${jkquery.version}</version>
76+
</dependency>
77+
78+
<!--MybatisPlus 查询器依赖-->
79+
80+
<dependency>
81+
<groupId>com.github.xuejike</groupId>
82+
<artifactId>lambda-query-mybatis-plus</artifactId>
83+
<version>${jkquery.version}</version>
84+
</dependency>
85+
86+
```
87+
88+
初始化工厂类
89+
```java
90+
// MongoDB 查询器初始化
91+
@Bean
92+
public MongoDaoFactory mongoDaoFactory(MongoTemplate mongoTemplate){
93+
return new MongoDaoFactory(mongoTemplate);
94+
}
95+
96+
// MybatisPlus 查询器初始化
97+
@Bean
98+
public MyBatisPlusDaoFactory myBatisPlusDaoFactory(Collection<BaseMapper> mapperCollection){
99+
MyBatisPlusDaoFactory myBatisPlusDaoFactory = new MyBatisPlusDaoFactory(mapperCollection);
100+
return myBatisPlusDaoFactory;
101+
}
102+
```
103+
### 2.Mongo查询器使用
104+
105+
1. 创建实体类
106+
107+
```java
108+
@Document("demo_doc")
109+
@Data
110+
// 采用mongo进行查询
111+
@MongoDaoSelect
112+
public class TestDoc {
113+
@MongoId
114+
private String id;
115+
private String name;
116+
private String title;
117+
private Long num;
118+
private List<Title> toc;
119+
@Data
120+
public static class Title{
121+
private String title;
122+
private String desc;
123+
124+
}
125+
}
126+
127+
```
128+
129+
2. 进行查询
130+
```java
131+
132+
/**
133+
* == 查询
134+
*/
135+
@Test
136+
public void testEq(){
137+
List<TestDoc> list = JkQuerys.lambdaQuery(TestDoc.class).eq(TestDoc::getName, "name_1").list();
138+
Assertions.assertEquals(list.size(),1);
139+
TestDoc testDoc = list.get(0);
140+
Assertions.assertEquals(testDoc.getTitle(),"title_1");
141+
}
142+
143+
/**
144+
* 大于号查询
145+
*
146+
*/
147+
@Test
148+
public void testGt(){
149+
List<TestDoc> list = JkQuerys.lambdaQuery(TestDoc.class).gt(TestDoc::getNum,3 ).list();
150+
Assertions.assertEquals(list.size(),1);
151+
TestDoc testDoc = list.get(0);
152+
Assertions.assertEquals(testDoc.getTitle(),"title_4");
153+
}
154+
155+
/**
156+
* 大于等于查询
157+
*/
158+
@Test
159+
public void testGte(){
160+
List<TestDoc> list = JkQuerys.lambdaQuery(TestDoc.class).gte(TestDoc::getNum,4 ).list();
161+
Assertions.assertEquals(list.size(),1);
162+
TestDoc testDoc = list.get(0);
163+
Assertions.assertEquals(testDoc.getTitle(),"title_4");
164+
}
165+
166+
/**
167+
* 小于号查询
168+
*/
169+
@Test
170+
public void testLt(){
171+
List<TestDoc> list = JkQuerys.lambdaQuery(TestDoc.class).lt(TestDoc::getNum,1 ).list();
172+
Assertions.assertEquals(list.size(),1);
173+
TestDoc testDoc = list.get(0);
174+
Assertions.assertEquals(testDoc.getTitle(),"title_0");
175+
}
176+
177+
/**
178+
* 小于等于查询
179+
*/
180+
@Test
181+
public void testLte(){
182+
List<TestDoc> list = JkQuerys.lambdaQuery(TestDoc.class).lte(TestDoc::getNum,0 ).list();
183+
Assertions.assertEquals(list.size(),1);
184+
TestDoc testDoc = list.get(0);
185+
Assertions.assertEquals(testDoc.getTitle(),"title_0");
186+
}
187+
188+
/**
189+
* In 查询
190+
*/
191+
@Test
192+
public void testIn(){
193+
List<TestDoc> list = JkQuerys.lambdaQuery(TestDoc.class)
194+
.in(TestDoc::getTitle,"title_0" ).list();
195+
Assertions.assertEquals(list.size(),1);
196+
TestDoc testDoc = list.get(0);
197+
Assertions.assertEquals(testDoc.getTitle(),"title_0");
198+
}
199+
200+
/**
201+
* NotIn 查询
202+
*/
203+
@Test
204+
public void testNotIn(){
205+
List<TestDoc> list = JkQuerys.lambdaQuery(TestDoc.class)
206+
.notIn(TestDoc::getTitle,"title_0","title_1","title_2","title_3" ).list();
207+
Assertions.assertEquals(list.size(),1);
208+
TestDoc testDoc = list.get(0);
209+
Assertions.assertEquals(testDoc.getTitle(),"title_4");
210+
}
211+
212+
/**
213+
* or 查询
214+
*/
215+
@Test
216+
public void testOr(){
217+
List<TestDoc> list = JkQuerys.lambdaQuery(TestDoc.class).or().eq(TestDoc::getNum, 0).or().eq(TestDoc::getNum, 1).list();
218+
Assertions.assertEquals(list.size(),2);
219+
220+
list = JkQuerys.lambdaQuery(TestDoc.class).or(it->{
221+
it.eq(TestDoc::getNum,0).eq(TestDoc::getName,"name_0");
222+
}).or(it->{
223+
it.eq(TestDoc::getNum,1).eq(TestDoc::getName,"name_1");
224+
}).list();
225+
Assertions.assertEquals(list.size(),2);
226+
227+
228+
}
229+
230+
/**
231+
* 排序查询
232+
*/
233+
@Test
234+
public void testOrder(){
235+
List<TestDoc> list = JkQuerys.lambdaQuery(TestDoc.class).in(TestDoc::getNum, 1, 2).orderAsc(TestDoc::getNum).list();
236+
Assertions.assertEquals(list.size(),2);
237+
Assertions.assertEquals(list.get(0).getNum(),1);
238+
Assertions.assertEquals(list.get(1).getNum(),2);
239+
240+
list = JkQuerys.lambdaQuery(TestDoc.class).in(TestDoc::getNum, 1, 2).orderDesc(TestDoc::getNum).list();
241+
Assertions.assertEquals(list.size(),2);
242+
Assertions.assertEquals(list.get(0).getNum(),2);
243+
Assertions.assertEquals(list.get(1).getNum(),1);
244+
}
245+
246+
/**
247+
* 二级字段查询
248+
*/
249+
@Test
250+
public void testSubField(){
251+
List<TestDoc> list = JkQuerys.lambdaQuery(TestDoc.class).eq(of().subList(TestDoc::getToc).sub(TestDoc.Title::getTitle), "sub_title_0_0").list();
252+
Assertions.assertEquals(list.size(),1);
253+
Assertions.assertEquals(list.get(0).getNum(),0);
254+
}
255+
public CascadeField<TestDoc,TestDoc> of(){
256+
return new CascadeField<>();
257+
}
258+
259+
```
260+
261+
262+
### 3.MybatisPlus查询器使用
263+
264+
mybatis-plus 实体初始化
265+
266+
```java
267+
@Data
268+
@TableName("u1")
269+
@MyBatisPlusDaoSelect
270+
public class U1 {
271+
@TableId(type = IdType.AUTO)
272+
private Long id;
273+
private String name;
274+
private String type;
50275

51-
* 新增
52-
* 删除
53-
* 更新
54-
* 条件更新
276+
}
55277

56-
## 扩展其他查询
57278

279+
```
58280

lambda-query-core/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<parent>
66
<artifactId>lambda-query</artifactId>
77
<groupId>com.github.xuejike</groupId>
8-
<version>1.0</version>
8+
<version>1.0.1-SNAPSHOT</version>
99
</parent>
1010
<artifactId>lambda-query-core</artifactId>
1111
<name>lambda-query-core</name>
1212
<description>Demo project for Spring Boot</description>
13-
<version>1.0</version>
13+
<version>1.0.1-SNAPSHOT</version>
1414

1515
<dependencies>
1616

0 commit comments

Comments
 (0)