-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from vnobo/dev
Dev
- Loading branch information
Showing
9 changed files
with
575 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
## Project Structure | ||
|
||
The project is structured in a typical Spring Boot fashion, with the main application entry point in the | ||
`com.plate.boot` package. It includes various sub-packages for different concerns such as security, relational data | ||
handling, and common utilities. | ||
The project is organized in a typical Spring Boot manner, with the main application entry point located in the | ||
`com.plate.boot` package. It contains various sub-packages dealing with different aspects such as security, relational | ||
data handling, and common utilities. | ||
|
||
## Features | ||
|
||
The application includes the following key features: | ||
The application encompasses the following key features: | ||
|
||
- **User Management**: Handles user-related operations and authentication. | ||
- **Security**: Implements security configurations and OAuth2 support. | ||
- **Logging**: Manages application logs efficiently with pagination and cleanup. | ||
- **User Management**: Deals with user-related operations and authentication. | ||
- **Security**: Implements security configurations and provides OAuth2 support. | ||
- **Logging**: Effectively manages application logs with pagination and cleanup functions. | ||
- **Menus**: Manages menu items and their associated permissions. | ||
- **Tenant Support**: Provides multi-tenancy capabilities. | ||
- **Caching**: Utilizes caching mechanisms to improve performance. | ||
- **Tenant Support**: Offers multi-tenancy capabilities. | ||
- **Caching**: Utilizes caching mechanisms to enhance performance. | ||
|
||
## Dependencies | ||
|
||
The project relies on several dependencies, including: | ||
The project depends on several dependencies, including: | ||
|
||
- Spring Boot 3.x.x | ||
- Spring Data R2DBC | ||
|
@@ -30,16 +30,16 @@ The project relies on several dependencies, including: | |
To run the application, you need to have Java 17 and Maven installed. Then, you can start the application by running the | ||
following command from the root directory of the project: | ||
|
||
This will start the Spring Boot application, and it should be accessible at `http://localhost:8080`. | ||
This will launch the Spring Boot application, and it should be accessible at `http://localhost:8080`. | ||
|
||
## API Documentation | ||
|
||
The API documentation is available using Swagger UI. Once the application is running, you can access the Swagger UI at: | ||
The API documentation can be accessed via Swagger UI. Once the application is running, you can visit the Swagger UI at: | ||
|
||
## Contributing | ||
|
||
Contributions are welcome! If you find any issues or want to add new features, feel free to open an issue or submit a | ||
pull request. | ||
Contributions are welcome! If you come across any issues or wish to add new features, feel free to open an issue or | ||
submit a pull request. | ||
|
||
## SSL Certificate Generation | ||
|
||
|
@@ -51,4 +51,127 @@ pull request. | |
keytool -importkeystore -srckeystore plate.p12 -srcstoretype pkcs12 -srcalias 1 -destkeystore plate.jks -deststoretype jks -deststorepass 123456 -destalias plate | ||
``` | ||
|
||
### Developer Documentation: Using QueryHelper, QueryJsonHelper and QueryFragment | ||
|
||
#### 1. Overview | ||
|
||
`QueryHelper`, `QueryJsonHelper` and `QueryFragment` are three utility classes that work together to assist developers | ||
in constructing and executing dynamic SQL queries, especially those involving JSON fields. These utility classes offer a | ||
secure and flexible way to handle database queries, reducing the risk of SQL injection and simplifying the query | ||
construction process. | ||
|
||
#### 2. QueryFragment | ||
|
||
`QueryFragment` is a core class used for building different parts of an SQL query, including selected columns, query | ||
conditions, sorting and pagination. | ||
|
||
**Usage Example**: | ||
|
||
```java | ||
QueryFragment queryFragment = QueryFragment.withNew() | ||
.addColumn("id", "name", "email") | ||
.addQuery("users") | ||
.addWhere("age > :age") | ||
.addOrder("name ASC"); | ||
|
||
queryFragment. | ||
|
||
put("age",18); // Bind parameters | ||
|
||
String sqlQuery = queryFragment.querySql(); // Generate the SQL query string | ||
``` | ||
|
||
#### 3. QueryHelper | ||
|
||
`QueryHelper` provides static methods to build a `QueryFragment` from an object, especially when the object contains | ||
pagination information. | ||
|
||
**Usage Example**: | ||
|
||
```java | ||
UserRequest userRequest = new UserRequest(); | ||
userRequest. | ||
|
||
setUsername("john"); | ||
|
||
Pageable pageable = PageRequest.of(0, 10); | ||
|
||
QueryFragment queryFragment = QueryHelper.query(userRequest, pageable); | ||
String sqlQuery = queryFragment.querySql(); | ||
``` | ||
|
||
#### 4. QueryJsonHelper | ||
|
||
`QueryJsonHelper` focuses on handling queries for JSON fields, allowing developers to construct SQL query conditions for | ||
JSON data. | ||
|
||
**Usage Example**: | ||
|
||
```java | ||
Map<String, Object> jsonParams = new HashMap<>(); | ||
jsonParams. | ||
|
||
put("extend.requestBody.nameEq","Test User"); | ||
jsonParams. | ||
|
||
put("extend.emailEq","[email protected]"); | ||
|
||
QueryFragment queryFragment = QueryJsonHelper.queryJson(jsonParams, "a"); | ||
String sqlQuery = queryFragment.querySql(); | ||
``` | ||
|
||
#### 5. Full-text Search Use Case | ||
|
||
For full-text search, you can use the `addQuery` method of `QueryFragment` to add conditions for full-text search. | ||
|
||
**Usage Example**: | ||
|
||
```java | ||
QueryFragment queryFragment = QueryFragment.withNew() | ||
.addColumn("id", "name", "email") | ||
.addQuery("users") | ||
.addWhere("to_tsvector('english', bio) @@ to_tsquery('english', :search)") | ||
.addOrder("ts_rank(to_tsvector('english', bio), to_tsquery('english', :search)) DESC"); | ||
|
||
queryFragment. | ||
|
||
put("search","test user"); // Bind the full-text search parameter | ||
|
||
String sqlQuery = queryFragment.querySql(); // Generate the SQL query string containing the full-text search | ||
``` | ||
|
||
In this example, `to_tsvector` and `to_tsquery` are PostgreSQL's full-text search functions used to convert text into | ||
vectors and query strings respectively. | ||
|
||
#### 6. Integration with UserRequest | ||
|
||
The `UserRequest` class extends the `User` class and adds additional attributes and methods for handling user requests. | ||
|
||
**Usage Example**: | ||
|
||
```java | ||
UserRequest userRequest = new UserRequest(); | ||
userRequest. | ||
|
||
setUsername("john"); | ||
userRequest. | ||
|
||
setSecurityCode("secure-code"); | ||
|
||
// Convert UserRequest to QueryFragment | ||
QueryFragment queryFragment = userRequest.toParamSql(); | ||
String sqlQuery = queryFragment.querySql(); | ||
``` | ||
|
||
In this example, the `toParamSql` method converts the `UserRequest` object into a `QueryFragment` instance for | ||
constructing an SQL query. | ||
|
||
#### 7. Precautions | ||
|
||
- Ensure that the database connection and configuration are correctly set when using these utility classes. | ||
- For full-text search, make sure that the database supports the full-text search function and that the corresponding | ||
indexes have been created. | ||
- When binding parameters, ensure that the parameter names and values match the placeholders in the query. | ||
|
||
Through these utility classes, developers can build and execute SQL queries more conveniently while maintaining the | ||
security and maintainability of the code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.