15 Star 37 Fork 0

huao / relax

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

logo

Relax

基于SpringBoot的快速CRUD工具。

快速开始

Relax对API接口中的CRUD(创建、读取、更新、删除)场景进行了丰富的封装,大幅减少了开发人员在这方面的编码工作。

引入

<dependency>
    <groupId>io.github.shenjingwaa</groupId>
    <artifactId>relax-spring-boot-starter</artifactId>
    <version>${latest-version}</version>
</dependency>

开启

@EnableRelax
@SpringBootApplication
public class RelaxApplication {
    public static void main(String[] args) {
        SpringApplication.run(RelaxApplication.class, args);
    }
}

配置

# 当前配置文件为 application.yml 文件
relax:
    auto-create-table: true  # 开启自动表创建
    entity-locations: com.app.entity.**  # relax实体扫描位置(默认为springboot启动类所在文件夹及子文件夹)

注:

如果需要开启自动表创建,需在application配置文件中增加配置relax.auto-create-table: true

该配置默认关闭,建议在dev环境开启,prod环境关闭该功能!

创建表 & 参数格式 & 返回值格式

//关于@RelaxEntity,如果您的auto-create-table配置为true,那么将会自动创建表.
//为false,则只会用于接口的生成
@RelaxEntity(tableName = "relax_user") 
public class RelaxUser {

    // 必须有且仅有一个属性通过 @RelaxId 显示指定表的主键,
    // 自动创建表字段会根据 @RelaxColumn 标注的属性,并且能够作为增删改查条件使用.

    @RelaxId
    @RelaxColumn
    private Long id;

    @RelaxColumn
    private String username;
    
    @RelaxColumn
    private String avatar;

    @RelaxColumn
    private LocalDate birthday;

    @RelaxColumn
    private Integer userType;

    @RelaxColumn
    private Integer status;
    
    // 此处省略get,set等方法...

}

创建API接口

@RelaxClass(entityType = RelaxUser.class)
@RestController
@RequestMapping("/relaxUser")
public class RelaxUserController {

}

此时您已经成功创建了接口创建,下面即可进入测试步骤

使用接口

根据以上示例生成的接口应为:

新增数据

POST /relaxUser/add

字段名 字段值 所在位置 是否必填
id 1 RequestBody
username sili RequestBody
avatar https://avatars.githubusercontent.com/u/112607471?v=4 RequestBody
birthday 1989-03-27 RequestBody
userType 00 RequestBody
status 0 RequestBody

更新数据

POST /relaxUser/update

字段名 字段值 所在位置 是否必填
id 1 RequestBody
username sili2 RequestBody
avatar https://avatars.githubusercontent.com/u/112607471?v=4 RequestBody
birthday 1989-03-27 RequestBody
userType 00 RequestBody
status 0 RequestBody

删除数据

POST /relaxUser/delete

字段名 字段值 所在位置 是否必填
id 1 RequestBody

根据ID查看详情

GET /relaxUser/info

字段名 字段值 所在位置 是否必填
id 1 param

列表查询

POST /relaxUser/list

字段名 字段值 所在位置 是否必填
id 1 RequestBody
username sili RequestBody
avatar https://avatars.githubusercontent.com/u/112607471?v=4 RequestBody
birthday 1989-03-27 RequestBody
userType 00 RequestBody
status 0 RequestBody

分页查询

POST /relaxUser/page

字段名 字段值 所在位置 是否必填
id 1 RequestBody
username sili RequestBody
avatar https://avatars.githubusercontent.com/u/112607471?v=4 RequestBody
birthday 1989-03-27 RequestBody
userType 00 RequestBody
status 0 RequestBody
pageSize 1 param 否(默认1)
pageNum 10 param 否(默认10)
MIT License Copyright (c) 2024 relax Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

使用注解开发接口,大幅减少开发人员在编码方面的工作。快速开发的同时又提供了很强的灵活性,能够自定义各种前后置逻辑。 展开 收起
取消

发行版 (1)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/hu_ao/relax.git
git@gitee.com:hu_ao/relax.git
hu_ao
relax
relax
master

搜索帮助