How APIJSON Cuts SpringBoot CRUD Boilerplate to Just 3 Lines

This article explains why traditional SpringBoot CRUD endpoints require dozens of lines of code and how APIJSON lets you perform all create, read, update, delete, and statistical operations on any table with only a few lines of configuration and a single generic interface.

Programmer DD
Programmer DD
Programmer DD
How APIJSON Cuts SpringBoot CRUD Boilerplate to Just 3 Lines

Many developers wonder how it is possible to avoid writing dozens of lines for a simple SpringBoot CRUD API. Even with almost zero configuration, a minimal endpoint needs three lines of code, and eight "Hello World" endpoints already require 24 lines, not counting SQL, JDBC, ORM, or XML configuration.

Traditionally, each operation (getting a single user, a user list, a comment, a comment list, etc.) needs a separate URL such as base_url/get/user, base_url/get/user/list, base_url/get/comment, and so on, quickly ballooning the number of interfaces.

Unified Interface Strategy

APIJSON solves this by using a single interface for each request type:

增  base_url/post
删(包括批量)  base_url/delete
改(包括批量)  base_url/put
查(包括列表)  base_url/get
统计  base_url/head

For example, querying a user can be done with just base_url/get/ regardless of whether you need a single record or a list.

Example: Managing a User Table with Only Three Lines

Define the table with minimal code:

@MethodAccess
public class User {
    // field comments are optional for the server side
}

// Add permission for POST requests
accessMap.put(User.class.getSimpleName(), getAccessMap(User.class.getAnnotation(MethodAccess.class)));

You can also customize role permissions for POST:

@MethodAccess(
  POST = {UNKNOWN, ADMIN} // only allow unauthenticated and admin roles to add User; default is {LOGIN, ADMIN}
)
public class User {}

After starting the server, a request like the following retrieves a user:

URL: http://apijson.cn:8080/get
{ "User": { "id": 82001 } }

The response contains the full user object with fields such as id, sex, name, tag, head, etc.

Advanced Queries

To fetch only female users and select specific columns:

{ "[]": { "User": { "sex": 1, "@column": "id,name" } } }

To extract just the names:

{ "User-name[]": { "User": { "sex": 1, "@column": "name" } } }

Multi‑table joins are also supported. For example, fetching comments together with the commenting user:

{ "[]": { "Comment": {}, "User": { "id@": "/Comment/userId" } } }

The response includes both Comment and the associated User objects.

Similar patterns handle Moments, their praise‑user lists, pagination, ordering, and grouping.

Generic Query Syntax

APIJSON provides a rich set of operators such as key[] for array queries, key{} for range matching, key@ for reference assignment, @column for field selection, @order for sorting, and many others, allowing any JSON structure to be fully customized.

CRUD Operations

Creating a comment:

{ "Comment": { "userId": 82001, "momentId": 15, "content": "测试新增评论" }, "tag": "Comment" }

Deleting a comment:

{ "Comment": { "id": 1510394480987 }, "tag": "Comment" }

Updating a comment:

{ "Comment": { "id": 22, "content": "测试修改评论" }, "tag": "Comment" }

Batch delete and batch update use the id{} syntax, and statistical queries are sent to /head with filter conditions.

Permission Management

Only three lines of code are needed to configure permissions; after logging in, the role automatically becomes LOGIN (or a custom @role), satisfying the POST permission for Comment and allowing the operation to succeed.

In summary, APIJSON eliminates the need to write individual interfaces; with a few configuration lines you get eight CRUD endpoints, complex queries, batch operations, and statistics, all without writing additional code.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaBackend DevelopmentJSONSpringBootCRUDAPIJSON
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.