### Basic fd-framework Configuration Example
Source: https://www.dlightaiflow.com/fd-doc/1.0.0-SNAPSHOT/index
This snippet demonstrates a minimal set of conventional configurations for an application using fd-framework. It includes setting the application name and enabling Swagger, along with configuring the log level. These settings can be adjusted based on project requirements.
```yaml
spring:
application:
name: your-app-name
fd:
swagger:
enable: true
log:
level: INFO
```
--------------------------------
### Include Specific fd-framework Starter Modules
Source: https://www.dlightaiflow.com/fd-doc/1.0.0-SNAPSHOT/index
After importing the fd-framework BOM, you can include specific starter modules as needed without explicitly defining their versions. This example shows how to include the bootstrap starter, which provides basic Web capabilities, Swagger, global exception handling, and serialization enhancements.
```xml
com.fd.frameworkbootstrap-spring-boot-starter
```
--------------------------------
### GET /example/user
Source: https://www.dlightaiflow.com/fd-doc/1.0.0-SNAPSHOT/modules/example
This endpoint demonstrates basic web functionalities, including how Long and Date types are serialized and the structure of the BaseResult.
```APIDOC
## GET /example/user
### Description
Demonstrates basic web functionalities, including Long to String serialization (to prevent frontend precision loss) and Date formatting to `yyyy-MM-dd HH:mm:ss`. Also shows the `BaseResult` structure (code/message/data).
### Method
GET
### Endpoint
/example/user
### Parameters
#### Path Parameters
None
#### Query Parameters
None
### Request Example
```json
{}
```
### Response
#### Success Response (200)
- **code** (integer) - Response status code.
- **message** (string) - Response message.
- **data** (object) - The actual response data, which may include serialized Longs and formatted Dates.
#### Response Example
```json
{
"code": 200,
"message": "Success",
"data": {
"userId": "1234567890123456789",
"timestamp": "2023-10-27 10:30:00"
}
}
```
```
--------------------------------
### GET /example/exception
Source: https://www.dlightaiflow.com/fd-doc/1.0.0-SNAPSHOT/modules/example
This endpoint tests the global exception handling mechanism, ensuring that all exceptions are uniformly presented as 'System busy'.
```APIDOC
## GET /example/exception
### Description
Tests the global exception handling. This endpoint is designed to trigger an exception that should be caught and uniformly returned as 'System busy' to the client.
### Method
GET
### Endpoint
/example/exception
### Parameters
#### Path Parameters
None
#### Query Parameters
None
### Request Example
```json
{}
```
### Response
#### Success Response (200)
- **code** (integer) - Response status code, expected to be a server error code.
- **message** (string) - Response message, expected to be 'System busy'.
- **data** (null) - Data field should be null or absent.
#### Response Example
```json
{
"code": 500,
"message": "System busy",
"data": null
}
```
```
--------------------------------
### Execute an HTTP Request with OkHttp
Source: https://www.dlightaiflow.com/fd-doc/1.0.0-SNAPSHOT/modules/easy-http-spring-boot-starter
This Java code illustrates how to execute an HTTP GET request using an OkHttpClient instance. It shows how to build a request, execute it, and retrieve the response body. Error handling for the response body is included.
```java
Request request = new Request.Builder().url("https://example.com").get().build();
try (Response resp = okHttpClient.newCall(request).execute()) {
String body = resp.body() == null ? null : resp.body().string();
}
```
--------------------------------
### Introduce Resource Spring Boot Starter Dependency
Source: https://www.dlightaiflow.com/fd-doc/1.0.0-SNAPSHOT/modules/resource-spring-boot-starter
This snippet shows how to add the resource-spring-boot-starter dependency to your Maven project. This is the first step to start using the module's functionalities.
```xml
com.fd.frameworkresource-spring-boot-starter
```
--------------------------------
### OpenAI Chat Configuration with Proxy
Source: https://www.dlightaiflow.com/fd-doc/1.0.0-SNAPSHOT/modules/ai-spring-boot-starter
Example of configuring the OpenAI service and OkHttp proxy settings in your application. This includes API key, host, and proxy details like URL, port, and type. It also shows OkHttp timeout and logging configurations.
```yaml
ai:
openai:
api-key: your-api-key
api-host: https://api.openai.com/
okhttp:
proxy-url: 127.0.0.1
proxy-port: 7890
proxy-type: HTTP
log: HEADERS
connect-timeout: 300
read-timeout: 300
write-timeout: 300
time-unit: SECONDS
```
--------------------------------
### Configure Tripartite Auth with JustAuth Properties
Source: https://www.dlightaiflow.com/fd-doc/1.0.0-SNAPSHOT/modules/tripartite-auth-spring-boot-starter
This example demonstrates the minimal configuration required to enable and set up tripartite authentication using JustAuth. It specifies the authentication type (e.g., Gitee) with its client ID, client secret, and redirect URI. It also shows how to configure the state cache type, with Redis being an option.
```yaml
justauth:
enabled: true
type:
GITEE:
client-id: your-client-id
client-secret: your-client-secret
redirect-uri: http://localhost:8080/oauth/gitee/callback
cache:
type: redis
```
--------------------------------
### Manage fd-framework Versions with Maven BOM
Source: https://www.dlightaiflow.com/fd-doc/1.0.0-SNAPSHOT/index
Import fd-framework as a Bill of Materials (BOM) in your business project to uniformly manage the versions of various starters. This simplifies dependency management by allowing you to import the BOM and then include specific modules without specifying their versions.
```xml
com.fd.frameworkfd-framework1.0.0-SNAPSHOTpomimport
```
--------------------------------
### Dual-Level Cache Usage (List Example)
Source: https://www.dlightaiflow.com/fd-doc/1.0.0-SNAPSHOT/modules/cache-spring-boot-starter
Illustrates how to use the dual-level caching strategy for lists. This method includes an additional parameter for the secondary cache expiration time. It fetches a list of users based on a department ID, utilizing both primary and secondary caches.
```java
return fdCacheManager.getListHasSecond(
"dept:users:" + deptId,
5,
1800,
7200,
User.class,
() -> userMapper.selectByDeptId(deptId)
);
```
--------------------------------
### Typical Controller Usage for Tripartite OAuth Login
Source: https://www.dlightaiflow.com/fd-doc/1.0.0-SNAPSHOT/modules/tripartite-auth-spring-boot-starter
This Java code snippet illustrates a typical controller setup for handling tripartite OAuth login flows. It utilizes `AuthRequestFactory` to obtain authentication requests for different platforms and manages the authorization and callback processes.
```java
@RestController
@RequestMapping("/oauth")
public class AuthController {
@Resource
private AuthRequestFactory factory;
@GetMapping
public List list() {
return factory.oauthList();
}
@GetMapping("/login/{type}")
public void login(@PathVariable String type, HttpServletResponse response) throws IOException {
AuthRequest authRequest = factory.get(type);
response.sendRedirect(authRequest.authorize(AuthStateUtils.createState()));
}
@GetMapping("/{type}/callback")
public AuthResponse callback(@PathVariable String type, AuthCallback callback) {
AuthRequest authRequest = factory.get(type);
return authRequest.login(callback);
}
}
```
--------------------------------
### Get User Endpoint
Source: https://www.dlightaiflow.com/fd-doc/1.0.0-SNAPSHOT/guides/example
Retrieves a user record by ID. This endpoint verifies MyBatis-Plus CRUD operations.
```APIDOC
## GET /user/get
### Description
Retrieves a specific user record by their ID using MyBatis-Plus.
### Method
GET
### Endpoint
/user/get
### Parameters
#### Path Parameters
None
#### Query Parameters
- **id** (integer) - Required - The ID of the user to retrieve.
### Request Example
```
GET /user/get?id=1
```
### Response
#### Success Response (200)
- **id** (integer) - The user's ID.
- **username** (string) - The user's username.
- **email** (string) - The user's email.
#### Response Example
```json
{
"id": 1,
"username": "existinguser",
"email": "existinguser@example.com"
}
```
```
--------------------------------
### GET /user/get?id=1
Source: https://www.dlightaiflow.com/fd-doc/1.0.0-SNAPSHOT/modules/example
Retrieves a user by their ID. This endpoint verifies the basic CRUD operations of the MyBatis-Plus ORM.
```APIDOC
## GET /user/get?id=1
### Description
Retrieves a user by their unique identifier. This endpoint validates the fundamental Create, Read, Update, and Delete (CRUD) operations provided by MyBatis-Plus.
### Method
GET
### Endpoint
/user/get
### Parameters
#### Path Parameters
None
#### Query Parameters
- **id** (long) - Required - The unique identifier of the user to retrieve.
### Request Example
```json
{
"id": 1
}
```
### Response
#### Success Response (200)
- **id** (long) - The unique identifier for the user.
- **username** (string) - The username of the user.
- **email** (string) - The email address of the user.
- **createTime** (datetime) - The timestamp when the user was created.
- **updateTime** (datetime) - The timestamp when the user was last updated.
- **version** (integer) - The version number of the user record.
#### Response Example
```json
{
"id": 1,
"username": "janedoe",
"email": "jane.doe@example.com",
"createTime": "2023-10-26 09:00:00",
"updateTime": "2023-10-27 11:00:00",
"version": 2
}
```
```
--------------------------------
### Word to PDF Conversion
Source: https://www.dlightaiflow.com/fd-doc/1.0.0-SNAPSHOT/modules/common-spring-boot-starter
Shows how to use the `DocumentTools.wordToPdf` method to convert Word documents to PDF. Note: This functionality depends on Aspose.Words and requires proper licensing and error handling for production use.
```java
DocumentTools.wordToPdf("D:/tmp/a.docx", "D:/tmp/a.pdf");
```
--------------------------------
### Include OkHttp Dependency in Maven Project
Source: https://www.dlightaiflow.com/fd-doc/1.0.0-SNAPSHOT/modules/easy-http-spring-boot-starter
This snippet shows how to add the easy-http-spring-boot-starter dependency to your Maven project's pom.xml. This allows for unified referencing and version management of OkHttp dependencies.
```xml
com.fd.frameworkeasy-http-spring-boot-starter
```
--------------------------------
### Hash Operations
Source: https://www.dlightaiflow.com/fd-doc/1.0.0-SNAPSHOT/modules/redis-spring-boot-starter
Methods for interacting with Redis Hash data structures, including setting, getting, checking existence, deleting fields, and incrementing/decrementing values.
```APIDOC
## Hash Operations
### Description
Methods for interacting with Redis Hash data structures, including setting, getting, checking existence, deleting fields, and incrementing/decrementing values.
### Methods
#### `RedisUtil.hSet(String key, Map data)`
- **Description**: Sets multiple fields in a Hash.
- **Method**: POST (or similar, conceptually)
- **Endpoint**: N/A (Utility Method)
- **Parameters**:
- **key** (String) - Required - The key of the Hash.
- **data** (Map) - Required - A map of field-value pairs to set.
#### `RedisUtil.hSet(String key, String hashKey, Object value)`
- **Description**: Sets a single field in a Hash.
- **Method**: POST (or similar, conceptually)
- **Endpoint**: N/A (Utility Method)
- **Parameters**:
- **key** (String) - Required - The key of the Hash.
- **hashKey** (String) - Required - The field name.
- **value** (Object) - Required - The value to set for the field.
#### `RedisUtil.hSet(String key, Map data, Long expireSeconds)`
- **Description**: Sets multiple fields in a Hash with an expiration time.
- **Method**: POST (or similar, conceptually)
- **Endpoint**: N/A (Utility Method)
- **Parameters**:
- **key** (String) - Required - The key of the Hash.
- **data** (Map) - Required - A map of field-value pairs to set.
- **expireSeconds** (Long) - Required - The expiration time in seconds.
#### `RedisUtil.hSet(String key, String hashKey, Object value, Long expireSeconds)`
- **Description**: Sets a single field in a Hash with an expiration time.
- **Method**: POST (or similar, conceptually)
- **Endpoint**: N/A (Utility Method)
- **Parameters**:
- **key** (String) - Required - The key of the Hash.
- **hashKey** (String) - Required - The field name.
- **value** (Object) - Required - The value to set for the field.
- **expireSeconds** (Long) - Required - The expiration time in seconds.
#### `RedisUtil.hGet(String key)`
- **Description**: Retrieves all fields and values from a Hash.
- **Method**: GET (or similar, conceptually)
- **Endpoint**: N/A (Utility Method)
- **Parameters**:
- **key** (String) - Required - The key of the Hash.
- **Response**: Map - A map containing all field-value pairs.
#### `RedisUtil.hGet(String key, String hashKey)`
- **Description**: Retrieves the value of a single field from a Hash.
- **Method**: GET (or similar, conceptually)
- **Endpoint**: N/A (Utility Method)
- **Parameters**:
- **key** (String) - Required - The key of the Hash.
- **hashKey** (String) - Required - The field name.
- **Response**: Object - The value of the specified field.
#### `RedisUtil#hashKey(String key, String hashKey)`
- **Description**: Checks if a field exists within a Hash.
- **Method**: GET (or similar, conceptually)
- **Endpoint**: N/A (Utility Method)
- **Parameters**:
- **key** (String) - Required - The key of the Hash.
- **hashKey** (String) - Required - The field name to check.
- **Response**: Boolean - True if the field exists, false otherwise.
#### `RedisUtil#hahsDel(String key, String... hashKeys)`
- **Description**: Deletes one or more fields from a Hash.
- **Method**: DELETE (or similar, conceptually)
- **Endpoint**: N/A (Utility Method)
- **Parameters**:
- **key** (String) - Required - The key of the Hash.
- **hashKeys** (String...) - Required - The field names to delete.
#### `RedisUtil#increment(String key, String hashKey, long number)`
- **Description**: Increments or decrements the value of a field in a Hash by a specified number.
- **Method**: POST (or similar, conceptually)
- **Endpoint**: N/A (Utility Method)
- **Parameters**:
- **key** (String) - Required - The key of the Hash.
- **hashKey** (String) - Required - The field name.
- **number** (long) - Required - The number to increment/decrement by (use negative for decrement).
- **Response**: Long - The value of the field after the increment/decrement operation.
```
--------------------------------
### Maven Dependency for ai-spring-boot-starter
Source: https://www.dlightaiflow.com/fd-doc/1.0.0-SNAPSHOT/modules/ai-spring-boot-starter
This snippet shows how to include the ai-spring-boot-starter library as a Maven dependency in your project. It automatically bundles necessary libraries like OkHttp and Logging.
```xml
com.fd.frameworkai-spring-boot-starter
```
--------------------------------
### Parse Date Parameters in GET/Query
Source: https://www.dlightaiflow.com/fd-doc/1.0.0-SNAPSHOT/modules/bootstrap-spring-boot-starter
Automatically parse date strings from GET or Query parameters into java.util.Date objects. The module supports various date string formats for parsing.
```java
@GetMapping("/report")
public BaseResult report(@RequestParam Date startTime, @RequestParam Date endTime) {
// startTime/endTime will be automatically parsed using multiple formats
return BaseResult.success();
}
```
--------------------------------
### List Operations
Source: https://www.dlightaiflow.com/fd-doc/1.0.0-SNAPSHOT/modules/redis-spring-boot-starter
Methods for managing Redis List data structures, including pushing elements to the left or right, retrieving elements by index or range, and getting the list length.
```APIDOC
## List Operations
### Description
Methods for managing Redis List data structures, including pushing elements to the left or right, retrieving elements by index or range, and getting the list length.
### Methods
#### `RedisUtil#leftPush(String key, Object value)`
- **Description**: Pushes an element to the left (head) of a List.
- **Method**: POST (or similar, conceptually)
- **Endpoint**: N/A (Utility Method)
- **Parameters**:
- **key** (String) - Required - The key of the List.
- **value** (Object) - Required - The element to push.
#### `RedisUtil#leftPush(String key, Object value, Long expireSeconds)`
- **Description**: Pushes an element to the left (head) of a List with an expiration time.
- **Method**: POST (or similar, conceptually)
- **Endpoint**: N/A (Utility Method)
- **Parameters**:
- **key** (String) - Required - The key of the List.
- **value** (Object) - Required - The element to push.
- **expireSeconds** (Long) - Required - The expiration time in seconds.
#### `RedisUtil#index(String key, long index)`
- **Description**: Retrieves the element at a specific index in a List.
- **Method**: GET (or similar, conceptually)
- **Endpoint**: N/A (Utility Method)
- **Parameters**:
- **key** (String) - Required - The key of the List.
- **index** (long) - Required - The index of the element to retrieve (0-based).
- **Response**: Object - The element at the specified index.
#### `RedisUtil#range(String key, long start, long end)`
- **Description**: Retrieves a range of elements from a List.
- **Method**: GET (or similar, conceptually)
- **Endpoint**: N/A (Utility Method)
- **Parameters**:
- **key** (String) - Required - The key of the List.
- **start** (long) - Required - The starting index of the range (inclusive).
- **end** (long) - Required - The ending index of the range (inclusive).
- **Response**: List