Skip to content

Commit c76ec00

Browse files
committed
update 2.7.6
1 parent 01dcc41 commit c76ec00

File tree

65 files changed

+696
-1144
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

+696
-1144
lines changed

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

+27-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>2.7.17</version>
9+
<version>2.7.18</version>
1010
<relativePath/> <!-- lookup parent from repository -->
1111
</parent>
1212

1313
<groupId>com.codingapi.springboot</groupId>
1414
<artifactId>springboot-parent</artifactId>
15-
<version>2.7.5</version>
15+
<version>2.7.6</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>
@@ -156,6 +158,29 @@
156158
<version>${commons-dbutils.version}</version>
157159
</dependency>
158160

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

160185
</dependencies>
161186
</dependencyManagement>
@@ -219,7 +244,6 @@
219244
<module>springboot-starter</module>
220245
<module>springboot-starter-security-jwt</module>
221246
<module>springboot-starter-data-fast</module>
222-
<module>springboot-starter-id-generator</module>
223247
</modules>
224248
</profile>
225249

@@ -231,7 +255,6 @@
231255
<module>springboot-starter</module>
232256
<module>springboot-starter-security-jwt</module>
233257
<module>springboot-starter-data-fast</module>
234-
<module>springboot-starter-id-generator</module>
235258
</modules>
236259

237260
<build>
@@ -281,7 +304,6 @@
281304
<module>springboot-starter</module>
282305
<module>springboot-starter-security-jwt</module>
283306
<module>springboot-starter-data-fast</module>
284-
<module>springboot-starter-id-generator</module>
285307
</modules>
286308

287309

springboot-starter-data-fast/pom.xml

+27-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>2.7.5</version>
8+
<version>2.7.6</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -28,6 +28,12 @@
2828
<artifactId>springboot-starter</artifactId>
2929
</dependency>
3030

31+
<dependency>
32+
<groupId>jakarta.servlet</groupId>
33+
<artifactId>jakarta.servlet-api</artifactId>
34+
<scope>provided</scope>
35+
</dependency>
36+
3137
<dependency>
3238
<groupId>org.springframework.boot</groupId>
3339
<artifactId>spring-boot-starter-data-jpa</artifactId>
@@ -39,6 +45,26 @@
3945
<scope>test</scope>
4046
</dependency>
4147

48+
<dependency>
49+
<groupId>org.apache.commons</groupId>
50+
<artifactId>commons-text</artifactId>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>org.apache.groovy</groupId>
55+
<artifactId>groovy</artifactId>
56+
</dependency>
57+
58+
<dependency>
59+
<groupId>org.apache.groovy</groupId>
60+
<artifactId>groovy-json</artifactId>
61+
</dependency>
62+
63+
<dependency>
64+
<groupId>org.apache.groovy</groupId>
65+
<artifactId>groovy-xml</artifactId>
66+
</dependency>
67+
4268
</dependencies>
4369

4470
</project>

0 commit comments

Comments
 (0)