Skip to content

Dev #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Jan 2, 2024
Merged

Dev #33

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 同步

* com.codingapi.springboot.framework.dto.request.IdRequest add
* com.codingapi.springboot.framework.dto.request.PageRequest#27 super(current, pageSize, sort);
* com.codingapi.springboot.framework.em.IEnum add
* com.codingapi.springboot.framework.serializer.EnumSerializer add
* springboot-starter-data-fast update
9 changes: 1 addition & 8 deletions docs/wiki/home.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ maven install
<version>${last.version}</version>
</dependency>

<!-- Id自增策略框架 -->
<dependency>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-starter-id-generator</artifactId>
<version>${last.version}</version>
</dependency>

<!-- security&jwt权限框架 -->
<dependency>
Expand All @@ -35,7 +29,6 @@ maven install


[springboot-starter](./springboot-starter)
[springboot-starter-security-jwt](./springboot-starter-security-jwt)
[springboot-starter-id-generator](./springboot-starter-id-generator)
[springboot-starter-security-jwt](./springboot-starter-security-jwt)
[springboot-starter-data-fast](./springboot-starter-data-fast.md)

158 changes: 85 additions & 73 deletions docs/wiki/springboot-starter-data-fast.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,8 @@ springboot-starter-data-fast

基于JPA的快速API能力服务

## FastController 快速API能力服务
```java
package com.codingapi.springboot.example.query;

import com.codingapi.springboot.example.infrastructure.jpa.entity.DemoEntity;
import com.codingapi.springboot.example.infrastructure.jpa.pojo.PageSearch;
import com.codingapi.springboot.fast.annotation.FastController;
import com.codingapi.springboot.fast.annotation.FastMapping;
import com.codingapi.springboot.framework.dto.response.MultiResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMethod;

@FastController
public interface FastDemoApi {


@PreAuthorize(value = "hasRole('ROLE_ADMIN')")
@FastMapping(
method = RequestMethod.GET,
mapping = "/api/demo/findByName1",
value = "select d from DemoEntity d where name = :name",
countQuery = "select count(d) from DemoEntity d where name = :name")
MultiResponse<DemoEntity> findByName1(PageSearch query);



@PreAuthorize(value = "hasRole('ROLE_USER')")
@FastMapping(
method = RequestMethod.GET,
mapping = "/api/demo/findByName2",
value = "select d from DemoEntity d where name = :name",
countQuery = "select count(d) from DemoEntity d where name = :name")
MultiResponse<DemoEntity> findByName2(PageSearch query);

}

```
@FastController 用于标记当前接口为Fast接口
@FastMapping 用于标记当前接口的映射关系
mapping为接口映射路径,method为接口请求方法
value为查询语句,countQuery为查询总数语句,query为查询参数,支持分页查询,排序查询,查询参数等等
MultiResponse为返回结果
@PreAuthorize(value = "hasRole('ROLE_USER')") 用于标记当前接口的权限,如果不需要权限可以不用添加

## FastRepository 的使用教程


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

Expand Down Expand Up @@ -189,41 +144,98 @@ public interface DemoRepository extends FastRepository<Demo,Integer> {
}

```
## SortRepository的使用教程

```java
## ScriptMapping 教程

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

}

```
ScriptMapping scriptMapping = new ScriptMapping({mapinggUrl}, {mapinggMethod}, {mappingGrovvry});
scriptMappingRegister.addMapping(scriptMapping);

SortRepository的能力展示
```
mapinggUrl 是mvc接口的地址
mapinggMethod 是mvc接口的请求方式
mappingGrovvry 是执行的查询脚本

```java
脚本实例代码:
* 动态分页查询
```
// 获取name的请求参数
var name = $request.getParameter("name","");
var pageNumber = $request.getParameter("pageNumber",0);
var pageSize = $request.getParameter("pageSize",10);
// 创建分页对象
var pageRequest = $request.pageRequest(pageNumber,pageSize);
// 动态组织sql
var sql = "select * from api_mapping where 1 =1 ";
var countSql = "select count(1) from api_mapping where 1 =1 ";
// 动态组织参数
var params = [];
if(!"".equals(name)){
sql += " and name = ? ";
countSql += " and name = ? ";
params.push(name);
}
sql += " limit ?,?";
// 添加分页参数
params.add(pageRequest.getOffset());
params.add(pageRequest.getPageSize());
// 执行分页查询
return $jdbc.queryForPage(sql,countSql,pageRequest,params.toArray());
```
* 动态条件查询
```
// 获取name的请求参数
var name = $request.getParameter("name","");
// 动态组织sql
String sql = "select * from api_mapping where 1=1 ";
// 动态组织参数
var params = [];
if(!"".equals(name)){
sql += " and name = ? ";
params.add(name);
}
// 执行查询
return $jdbc.queryForList(sql,params.toArray());
```

@Test
@Transactional
void pageSort() {
demoRepository.deleteAll();
Demo demo1 = new Demo();
demo1.setName("123");
demoRepository.save(demo1);

Demo demo2 = new Demo();
demo2.setName("456");
demoRepository.save(demo2);

List<Integer> ids = Arrays.asList(demo1.getId(), demo2.getId());
System.out.println(ids);
demoRepository.pageSort(PageRequest.of(1, 10), ids);

Demo newDemo1 = demoRepository.getReferenceById(demo1.getId());
Demo newDemo2 = demoRepository.getReferenceById(demo2.getId());

assertEquals(newDemo2.getSort(), 1);
assertEquals(newDemo1.getSort(), 0);
}
脚本语法介绍:
* $request
```
// 获取参数name的值,如果参数不存在,则返回默认值
var name = $request.getParameter("name","");
// 获取分页对象
var pageRequest = $request.pageRequest(0,10);
// 获取分页对象的页码
var pageNumber = pageRequest.getPageNumber();
// 获取分页对象的每页记录数
var pageSize = pageRequest.getPageSize();
// 获取分页对象的偏移量
var offset = pageRequest.getOffset();
```
* $jdbc
```
// 查询jdbcSQL $jdbc.queryForList({sql},{params})

// 查询无条件的数据
var res = $jdbc.queryForList("select * from api_mapping");
// 查询有条件的数据
var res = $jdbc.queryForList("select * from api_mapping where name = ?",name);
// 查询多条件的数据
var res = $jdbc.queryForList("select * from api_mapping where name = ? and url = ?",name,url);

// 分页查询 $jdbc.queryForPage({sql},{countSql},{pageRequest},{params})
var res = $jdbc.queryForPage("select * from api_mapping where name = ? and url = ?",
"select count(1) from api_mapping where name = ? and url = ?",pageRequest,params.toArray());
```
* $jpa
```
// 查询jpa $jpa.listQuery({clazz},{sql},{params})

// 查询无条件的数据
var res = $jpa.listQuery(com.example.entity.NodeEntity.class,"from NodeEntity");
// 查询有条件的数据
var res = $jpa.listQuery(com.example.entity.NodeEntity.class,"from NodeEntity where name = ?",name);
```
34 changes: 0 additions & 34 deletions docs/wiki/springboot-starter-id-generator.md

This file was deleted.

33 changes: 28 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.5</version>
<version>3.1.7</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-parent</artifactId>
<version>3.1.6</version>
<version>3.1.7</version>

<url>https://github.com/codingapi/springboot-framewrok</url>
<name>springboot-parent</name>
Expand All @@ -35,11 +35,13 @@
<jsonwebtoken.jjwt.version>0.12.3</jsonwebtoken.jjwt.version>
<commons-io.version>2.15.0</commons-io.version>
<commons-dbutils.version>1.8.1</commons-dbutils.version>
<commons-text.version>1.11.0</commons-text.version>
<org.reflections.version>0.10.2</org.reflections.version>
<perf4j.version>0.9.16</perf4j.version>
<bcprov-jdk15on.version>1.70</bcprov-jdk15on.version>
<commons-crypto.version>1.2.0</commons-crypto.version>
<snakeyaml.version>2.2</snakeyaml.version>
<apache-groovy.version>4.0.15</apache-groovy.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -157,6 +159,30 @@
<version>${commons-dbutils.version}</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>${commons-text.version}</version>
</dependency>

<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy</artifactId>
<version>${apache-groovy.version}</version>
</dependency>

<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy-json</artifactId>
<version>${apache-groovy.version}</version>
</dependency>

<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy-xml</artifactId>
<version>${apache-groovy.version}</version>
</dependency>

</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -219,7 +245,6 @@
<module>springboot-starter</module>
<module>springboot-starter-security-jwt</module>
<module>springboot-starter-data-fast</module>
<module>springboot-starter-id-generator</module>
</modules>
</profile>

Expand All @@ -231,7 +256,6 @@
<module>springboot-starter</module>
<module>springboot-starter-security-jwt</module>
<module>springboot-starter-data-fast</module>
<module>springboot-starter-id-generator</module>
</modules>

<build>
Expand Down Expand Up @@ -281,7 +305,6 @@
<module>springboot-starter</module>
<module>springboot-starter-security-jwt</module>
<module>springboot-starter-data-fast</module>
<module>springboot-starter-id-generator</module>
</modules>


Expand Down
22 changes: 21 additions & 1 deletion springboot-starter-data-fast/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>springboot-parent</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.1.6</version>
<version>3.1.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -39,6 +39,26 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
</dependency>

<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy</artifactId>
</dependency>

<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy-json</artifactId>
</dependency>

<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy-xml</artifactId>
</dependency>

</dependencies>

</project>
Loading