# sqid-spring-boot-starter **Repository Path**: chenfd99_admin/sqid-spring-boot-starter ## Basic Information - **Project Name**: sqid-spring-boot-starter - **Description**: 用于在springboot项目中后端避免暴露数据库自增id给前端 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2024-06-20 - **Last Updated**: 2024-08-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ![Maven Central Version](https://img.shields.io/maven-central/v/io.github.chenfd99/sqid-spring-boot-starter?label=Release) ![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/io.github.chenfd99/sqid-spring-boot-starter?server=https%3A%2F%2Fs01.oss.sonatype.org&label=Snapshot) # 前后端短ID交互实现 本项目使用[Sqids](https://sqids.org/zh/java)实现 用于在`springboot`项目中后端避免暴露数据库自增id给前端,从而返回一个字符串给前端,前后端交互使用字符串, ## 使用 具体使用方法请看[DEMO](https://gitee.com/chenfd99_admin/short-id-demo) ### 加入依赖 ```gradle implementation("io.github.chenfd99:sqid-spring-boot-starter") ``` ```xml io.github.chenfd99 sqid-spring-boot-starter ``` ### 使用`@EnableSqId`启用`SqId`,如: ```java @EnableSqId @SpringBootApplication public class ShortIdApplication { public static void main(String[] args) { SpringApplication.run(ShortIdApplication.class, args); } } ``` #### DTO负责与前端交互,转换SqId。 ```java @Setter @Getter @ToString public class UserDto { private SqId id; private String name; } ``` ### 请求多个数据 `curl localhost:8080/users/list` 返回数据 ```json [ { "id": "JcUu1l", "name": "user1" }, { "id": "GvYlTp", "name": "user2" } ] ``` ### 请求单个数据 `curl localhost:8080/users/get/GvYlTp` 返回数据 ```json { "id": "GvYlTp", "name": "user2" } ```