Skip to content

Commit 96f660e

Browse files
authored
Merge pull request #33 from codingapi/dev
Dev
2 parents 87f2057 + 167bd59 commit 96f660e

File tree

65 files changed

+669
-1127
lines changed

Some content is hidden

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

65 files changed

+669
-1127
lines changed

TODO.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# 同步
2+
3+
* com.codingapi.springboot.framework.dto.request.IdRequest add
4+
* com.codingapi.springboot.framework.dto.request.PageRequest#27 super(current, pageSize, sort);
5+
* com.codingapi.springboot.framework.em.IEnum add
6+
* com.codingapi.springboot.framework.serializer.EnumSerializer add
7+
* springboot-starter-data-fast update

docs/wiki/home.md

+1-8
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ maven install
1818
<version>${last.version}</version>
1919
</dependency>
2020
21-
<!-- Id自增策略框架 -->
22-
<dependency>
23-
<groupId>com.codingapi.springboot</groupId>
24-
<artifactId>springboot-starter-id-generator</artifactId>
25-
<version>${last.version}</version>
26-
</dependency>
2721
2822
<!-- security&jwt权限框架 -->
2923
<dependency>
@@ -35,7 +29,6 @@ maven install
3529

3630

3731
[springboot-starter](./springboot-starter)
38-
[springboot-starter-security-jwt](./springboot-starter-security-jwt)
39-
[springboot-starter-id-generator](./springboot-starter-id-generator)
32+
[springboot-starter-security-jwt](./springboot-starter-security-jwt)
4033
[springboot-starter-data-fast](./springboot-starter-data-fast.md)
4134

docs/wiki/springboot-starter-data-fast.md

+85-73
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,8 @@ springboot-starter-data-fast
22

33
基于JPA的快速API能力服务
44

5-
## FastController 快速API能力服务
6-
```java
7-
package com.codingapi.springboot.example.query;
8-
9-
import com.codingapi.springboot.example.infrastructure.jpa.entity.DemoEntity;
10-
import com.codingapi.springboot.example.infrastructure.jpa.pojo.PageSearch;
11-
import com.codingapi.springboot.fast.annotation.FastController;
12-
import com.codingapi.springboot.fast.annotation.FastMapping;
13-
import com.codingapi.springboot.framework.dto.response.MultiResponse;
14-
import org.springframework.security.access.prepost.PreAuthorize;
15-
import org.springframework.web.bind.annotation.RequestMethod;
16-
17-
@FastController
18-
public interface FastDemoApi {
19-
20-
21-
@PreAuthorize(value = "hasRole('ROLE_ADMIN')")
22-
@FastMapping(
23-
method = RequestMethod.GET,
24-
mapping = "/api/demo/findByName1",
25-
value = "select d from DemoEntity d where name = :name",
26-
countQuery = "select count(d) from DemoEntity d where name = :name")
27-
MultiResponse<DemoEntity> findByName1(PageSearch query);
28-
29-
30-
31-
@PreAuthorize(value = "hasRole('ROLE_USER')")
32-
@FastMapping(
33-
method = RequestMethod.GET,
34-
mapping = "/api/demo/findByName2",
35-
value = "select d from DemoEntity d where name = :name",
36-
countQuery = "select count(d) from DemoEntity d where name = :name")
37-
MultiResponse<DemoEntity> findByName2(PageSearch query);
38-
39-
}
40-
41-
```
42-
@FastController 用于标记当前接口为Fast接口
43-
@FastMapping 用于标记当前接口的映射关系
44-
mapping为接口映射路径,method为接口请求方法
45-
value为查询语句,countQuery为查询总数语句,query为查询参数,支持分页查询,排序查询,查询参数等等
46-
MultiResponse为返回结果
47-
@PreAuthorize(value = "hasRole('ROLE_USER')") 用于标记当前接口的权限,如果不需要权限可以不用添加
48-
495
## FastRepository 的使用教程
506

51-
527
继承FastRepository接口,实现自定义的接口,即可使用FastRepository的能力
538
```java
549

@@ -189,41 +144,98 @@ public interface DemoRepository extends FastRepository<Demo,Integer> {
189144
}
190145
191146
```
192-
## SortRepository的使用教程
193147

194-
```java
148+
## ScriptMapping 教程
195149

196-
public interface DemoRepository extends FastRepository<Demo,Integer>, SortRepository<Demo,Integer> {
150+
通过动态添加mvc mapping实现查询功能.
197151

198-
}
199152

200153
```
154+
ScriptMapping scriptMapping = new ScriptMapping({mapinggUrl}, {mapinggMethod}, {mappingGrovvry});
155+
scriptMappingRegister.addMapping(scriptMapping);
201156
202-
SortRepository的能力展示
157+
```
158+
mapinggUrl 是mvc接口的地址
159+
mapinggMethod 是mvc接口的请求方式
160+
mappingGrovvry 是执行的查询脚本
203161

204-
```java
162+
脚本实例代码:
163+
* 动态分页查询
164+
```
165+
// 获取name的请求参数
166+
var name = $request.getParameter("name","");
167+
var pageNumber = $request.getParameter("pageNumber",0);
168+
var pageSize = $request.getParameter("pageSize",10);
169+
// 创建分页对象
170+
var pageRequest = $request.pageRequest(pageNumber,pageSize);
171+
// 动态组织sql
172+
var sql = "select * from api_mapping where 1 =1 ";
173+
var countSql = "select count(1) from api_mapping where 1 =1 ";
174+
// 动态组织参数
175+
var params = [];
176+
if(!"".equals(name)){
177+
sql += " and name = ? ";
178+
countSql += " and name = ? ";
179+
params.push(name);
180+
}
181+
sql += " limit ?,?";
182+
// 添加分页参数
183+
params.add(pageRequest.getOffset());
184+
params.add(pageRequest.getPageSize());
185+
// 执行分页查询
186+
return $jdbc.queryForPage(sql,countSql,pageRequest,params.toArray());
187+
```
188+
* 动态条件查询
189+
```
190+
// 获取name的请求参数
191+
var name = $request.getParameter("name","");
192+
// 动态组织sql
193+
String sql = "select * from api_mapping where 1=1 ";
194+
// 动态组织参数
195+
var params = [];
196+
if(!"".equals(name)){
197+
sql += " and name = ? ";
198+
params.add(name);
199+
}
200+
// 执行查询
201+
return $jdbc.queryForList(sql,params.toArray());
202+
```
205203

206-
@Test
207-
@Transactional
208-
void pageSort() {
209-
demoRepository.deleteAll();
210-
Demo demo1 = new Demo();
211-
demo1.setName("123");
212-
demoRepository.save(demo1);
213-
214-
Demo demo2 = new Demo();
215-
demo2.setName("456");
216-
demoRepository.save(demo2);
217-
218-
List<Integer> ids = Arrays.asList(demo1.getId(), demo2.getId());
219-
System.out.println(ids);
220-
demoRepository.pageSort(PageRequest.of(1, 10), ids);
221-
222-
Demo newDemo1 = demoRepository.getReferenceById(demo1.getId());
223-
Demo newDemo2 = demoRepository.getReferenceById(demo2.getId());
224-
225-
assertEquals(newDemo2.getSort(), 1);
226-
assertEquals(newDemo1.getSort(), 0);
227-
}
204+
脚本语法介绍:
205+
* $request
206+
```
207+
// 获取参数name的值,如果参数不存在,则返回默认值
208+
var name = $request.getParameter("name","");
209+
// 获取分页对象
210+
var pageRequest = $request.pageRequest(0,10);
211+
// 获取分页对象的页码
212+
var pageNumber = pageRequest.getPageNumber();
213+
// 获取分页对象的每页记录数
214+
var pageSize = pageRequest.getPageSize();
215+
// 获取分页对象的偏移量
216+
var offset = pageRequest.getOffset();
217+
```
218+
* $jdbc
219+
```
220+
// 查询jdbcSQL $jdbc.queryForList({sql},{params})
221+
222+
// 查询无条件的数据
223+
var res = $jdbc.queryForList("select * from api_mapping");
224+
// 查询有条件的数据
225+
var res = $jdbc.queryForList("select * from api_mapping where name = ?",name);
226+
// 查询多条件的数据
227+
var res = $jdbc.queryForList("select * from api_mapping where name = ? and url = ?",name,url);
228+
229+
// 分页查询 $jdbc.queryForPage({sql},{countSql},{pageRequest},{params})
230+
var res = $jdbc.queryForPage("select * from api_mapping where name = ? and url = ?",
231+
"select count(1) from api_mapping where name = ? and url = ?",pageRequest,params.toArray());
232+
```
233+
* $jpa
234+
```
235+
// 查询jpa $jpa.listQuery({clazz},{sql},{params})
228236
237+
// 查询无条件的数据
238+
var res = $jpa.listQuery(com.example.entity.NodeEntity.class,"from NodeEntity");
239+
// 查询有条件的数据
240+
var res = $jpa.listQuery(com.example.entity.NodeEntity.class,"from NodeEntity where name = ?",name);
229241
```

docs/wiki/springboot-starter-id-generator.md

-34
This file was deleted.

pom.xml

+28-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
<parent>
77
<groupId>org.springframework.boot</groupId>
88
<artifactId>spring-boot-starter-parent</artifactId>
9-
<version>3.1.5</version>
9+
<version>3.1.7</version>
1010
<relativePath/> <!-- lookup parent from repository -->
1111
</parent>
1212

1313
<groupId>com.codingapi.springboot</groupId>
1414
<artifactId>springboot-parent</artifactId>
15-
<version>3.1.6</version>
15+
<version>3.1.7</version>
1616

1717
<url>https://github.com/codingapi/springboot-framewrok</url>
1818
<name>springboot-parent</name>
@@ -35,11 +35,13 @@
3535
<jsonwebtoken.jjwt.version>0.12.3</jsonwebtoken.jjwt.version>
3636
<commons-io.version>2.15.0</commons-io.version>
3737
<commons-dbutils.version>1.8.1</commons-dbutils.version>
38+
<commons-text.version>1.11.0</commons-text.version>
3839
<org.reflections.version>0.10.2</org.reflections.version>
3940
<perf4j.version>0.9.16</perf4j.version>
4041
<bcprov-jdk15on.version>1.70</bcprov-jdk15on.version>
4142
<commons-crypto.version>1.2.0</commons-crypto.version>
4243
<snakeyaml.version>2.2</snakeyaml.version>
44+
<apache-groovy.version>4.0.15</apache-groovy.version>
4345
</properties>
4446

4547
<dependencies>
@@ -157,6 +159,30 @@
157159
<version>${commons-dbutils.version}</version>
158160
</dependency>
159161

162+
<dependency>
163+
<groupId>org.apache.commons</groupId>
164+
<artifactId>commons-text</artifactId>
165+
<version>${commons-text.version}</version>
166+
</dependency>
167+
168+
<dependency>
169+
<groupId>org.apache.groovy</groupId>
170+
<artifactId>groovy</artifactId>
171+
<version>${apache-groovy.version}</version>
172+
</dependency>
173+
174+
<dependency>
175+
<groupId>org.apache.groovy</groupId>
176+
<artifactId>groovy-json</artifactId>
177+
<version>${apache-groovy.version}</version>
178+
</dependency>
179+
180+
<dependency>
181+
<groupId>org.apache.groovy</groupId>
182+
<artifactId>groovy-xml</artifactId>
183+
<version>${apache-groovy.version}</version>
184+
</dependency>
185+
160186
</dependencies>
161187
</dependencyManagement>
162188

@@ -219,7 +245,6 @@
219245
<module>springboot-starter</module>
220246
<module>springboot-starter-security-jwt</module>
221247
<module>springboot-starter-data-fast</module>
222-
<module>springboot-starter-id-generator</module>
223248
</modules>
224249
</profile>
225250

@@ -231,7 +256,6 @@
231256
<module>springboot-starter</module>
232257
<module>springboot-starter-security-jwt</module>
233258
<module>springboot-starter-data-fast</module>
234-
<module>springboot-starter-id-generator</module>
235259
</modules>
236260

237261
<build>
@@ -281,7 +305,6 @@
281305
<module>springboot-starter</module>
282306
<module>springboot-starter-security-jwt</module>
283307
<module>springboot-starter-data-fast</module>
284-
<module>springboot-starter-id-generator</module>
285308
</modules>
286309

287310

springboot-starter-data-fast/pom.xml

+21-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-parent</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.1.6</version>
8+
<version>3.1.7</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -39,6 +39,26 @@
3939
<scope>test</scope>
4040
</dependency>
4141

42+
<dependency>
43+
<groupId>org.apache.commons</groupId>
44+
<artifactId>commons-text</artifactId>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>org.apache.groovy</groupId>
49+
<artifactId>groovy</artifactId>
50+
</dependency>
51+
52+
<dependency>
53+
<groupId>org.apache.groovy</groupId>
54+
<artifactId>groovy-json</artifactId>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>org.apache.groovy</groupId>
59+
<artifactId>groovy-xml</artifactId>
60+
</dependency>
61+
4262
</dependencies>
4363

4464
</project>

0 commit comments

Comments
 (0)