使用magic-api实现增删改查分页

创建项目结构

 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>magic-api-demo</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.5</version>
    </parent>

    <properties>
        <java.version>17</java.version>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.ssssssss</groupId>
            <artifactId>magic-api-spring-boot-starter</artifactId>
            <version>2.1.1</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.33</version>
        </dependency>

        <!-- Spring Boot 3.x需要Jakarta EE -->
        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <version>6.0.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <sourceDirectory>src/main/java</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project> 

application.yml

server:
  port: 8080

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/magic_api_demo?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true
    username: root
    password: root
    driver-class-name: com.mysql.cj.jdbc.Driver
    hikari:
      maximum-pool-size: 10
      minimum-idle: 5

magic-api:
  web: /magic/web
  prefix: /magic-api
  page:
    size: size # 页大小的请求参数名称 缺省时为size
    page: page # 页码的请求参数名称 缺省时为page
    default-page: 1 # 自定义默认首页 缺省时为1
    default-size: 10 # 自定义为默认页大小 缺省时为10
  resource:
    type: database
    table-name: magic_api_file
    prefix: /
  swagger-config:
    enabled: true
    title: Magic API 接口
    description: Magic API 接口文档
    version: 1.0
  response-context:
    headers:
      - Access-Control-Allow-Origin=*
      - Access-Control-Allow-Methods=GET,POST,PUT,DELETE,OPTIONS
      - Access-Control-Allow-Headers=Content-Type,Authorization

启动时显示地址:

 创建分组和创建接口

 查询:

 分页

 

 详情

 

 

 

 

posted @ 2024-12-21 23:34  蔡徐坤1987  阅读(3)  评论(0编辑  收藏  举报