Assistant Assistant
首页
  • 快速入门
  • 核心功能
  • 使用配置
生态
问答
💖支持
🚀起飞诶~~起飞
更新日志 (opens new window)
GitHub (opens new window)
首页
  • 快速入门
  • 核心功能
  • 使用配置
生态
问答
💖支持
🚀起飞诶~~起飞
更新日志 (opens new window)
GitHub (opens new window)
  • 快速入门

    • 简介
    • 快速开始
      • 初始化工程
      • 添加依赖
      • 配置
      • 开始使用
      • 小结
    • 安装
    • 配置
    • 注解
    • 快速测试
  • 核心功能

    • 热身模块

      • 代码生成器
    • 工具类

      • Token工具类
      • 正则工具类
      • 加密算法工具类
    • 业务类

      • 超级业务链
      • ID生成器
      • 统一异常处理中心
目录

快速开始

我们将通过一个简单的 Demo 来阐述 Assistant 的强大功能,在此之前,我们假设您已经:

  • 拥有 Java 开发环境以及相应 IDE
  • 熟悉 Spring Boot
  • 熟悉 Maven

# 初始化工程

创建一个空的 Spring Boot 工程

提示

可以使用 Spring Initializer (opens new window) 快速初始化一个 Spring Boot 工程

# 添加依赖

引入 Spring Boot Starter 父工程:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5+ 版本</version>
    <relativePath/>
</parent>
1
2
3
4
5
6

引入 spring-boot-starter、spring-boot-starter-test、assistant 依赖:


















<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.github.geniusay</groupId>
        <artifactId>assistant-boot-start</artifactId>
        <version>1.1.1</version>
    </dependency>
</dependencies>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# 配置

编写一个controller测试类 HelloController

@RestController
@RequestMapping("/hello")
public class HelloController {

    @GetMapping("/helloGet")
    public void hello(){
        System.out.println("hello");
    }

    @PostMapping("/helloPost")
    public void helloPost(@RequestBody String body){
        System.out.println("helloPost");
    }

    @GetMapping("/helloGet/{id}/{name}")
    public void helloGetById(@PathVariable("id") String id,@PathVariable("name") String name){
        System.out.println("helloGet");
    }

    @GetMapping("/helloNotRestful")
    public void helloNotRestful(@RequestParam("id") String id,@RequestParam("name") String name){
        System.out.println("helloNotRestful");
    }

    @RequestMapping(value = "/helloRequest",method = {RequestMethod.GET,RequestMethod.POST})
    public void helloRequest(){
        System.out.println("helloRequest");
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

编写SpringBoot启动类


 







@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}
1
2
3
4
5
6
7
8

# 开始使用

添加测试类,进行功能测试:

@SpringBootTest
public class SampleTest {

    @Autowired
    AutoApiJsGenerate autoApiJsGenerate;

    @Test
    public void testGenerateJS(){
        autoApiJsGenerate
                .setIsJsMoodleGenerated(true)
                .setFileSavePath("你生成的文件想要保存的位置"). //文件保存区域
                generate();
    }

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

提示

如果你不填写生成文件的保存路径位置的话,他将默认生成在\src\main\resources\static\js\

控制台输出:

-----生成文件-----:\src\main\resources\static\js\HelloController.js
1

在你保存的路径下就会有自动生成的文件,我们来打开看看

import request from 'axios';


export function hello() {
     return request({
        url: '/hello/helloGet/',
        method: get,
        params: {
        }
     });
}
export function helloRequestGET() {
     return request({
        url: '/hello/helloRequest/',
        method: get,
        params: {
        }
     });
}
export function helloRequestPOST() {
     return request({
        url: '/hello/helloRequest/',
        method: post,
        data: {
        }
     });
}

//.........省略后续代码..........
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

# 小结

通过以上几个简单的步骤,我们就可以一键生成前端apiJs文件,只需一行代码,短短1秒内就可以生成一堆apiJs文件,不仅节省了大部分时间还免去了对着接口一个个写出错的风险,这实在是太方便了!!

但 Assistant 的强大远不止这些功能,想要详细了解 Assistant 的强大功能?那就继续往下看吧!

帮助我们改善此页面! (opens new window)
上次更新: 2024/06/22, 16:36:11
简介
安装

← 简介 安装→

Theme by Vdoing | Copyright © 2016-2024 TimeMachine Lab | Sponsored by JetBrains | 渝ICP备2021000141号-1

友情链接:GeniusBlog

  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式