Generate Zero‑Code Backend APIs with APIJSON and Spring Boot
This guide shows how to use Tencent's open‑source APIJSON library with a Spring Boot demo to automatically generate full‑stack CRUD REST endpoints from database tables, covering project setup, configuration, table creation, and example requests for querying, adding, updating, deleting, and paginating product brand data.
Introduction
APIJSON is a Tencent open‑source real‑time zero‑code, full‑function ORM library that automatically provides universal CRUD interfaces for any database table. It has over 17k stars on GitHub and offers features such as automatic API generation, cross‑table joins, documentation, permission validation, version management, SQL‑injection protection, and customizable JSON responses.
Universal backend interface generated automatically from database tables.
Zero‑code support for CRUD, cross‑database joins, nested queries.
Automatic documentation generation.
Built‑in permission validation, version management, SQL‑injection defense.
Customizable JSON data and structure.
Preparation
Download the
APIJSON-Demosource code ( https://github.com/APIJSON/APIJSON-Demo ) and import the
APIJSONDemomodule into IDEA. Create a MySQL database named
apijson_sysand place the required tables in the
MySQL/singledirectory.
After importing, modify the
DemoSQLConfigclass to set the database connection parameters (DEFAULT_SCHEMA, DBVersion, DBUri, DBAccount, DBPassword) and run the
DemoApplicationclass to start the project.
<code>public class DemoSQLConfig extends APIJSONSQLConfig<Long, JSONObject, JSONArray> {
static {
DEFAULT_DATABASE = DATABASE_MYSQL;
DEFAULT_SCHEMA = "apijson_sys";
TABLE_KEY_MAP.put("User", "apijson_user");
TABLE_KEY_MAP.put("Privacy", "apijson_privacy");
}
@Override
public String gainDBVersion() { return "5.7.19"; }
@JSONField(serialize = false)
@Override
public String gainDBUri() { return "jdbc:mysql://localhost:3306?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8"; }
@JSONField(serialize = false)
@Override
public String gainDBAccount() { return "root"; }
@JSONField(serialize = false)
@Override
public String gainDBPassword() { return "root"; }
}
</code>Usage
Using APIJSON, we develop backend interfaces for the
malle‑commerce project's brand management feature.
The
mallproject is a SpringBoot3 + Vue e‑commerce system (≈60 K stars) with micro‑service architecture, Docker and K8s deployment, covering product, order, cart, permission, coupon, member, payment, etc.
Boot project: https://github.com/macrozheng/mall
Cloud project: https://github.com/macrozheng/mall-swarm
Documentation site: https://www.macrozheng.com
Create a business database
mall_apiand the APIJSON system database
apijson_sys. Add a
pms_brandtable with the following structure:
<code>CREATE TABLE `pms_brand` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(64) DEFAULT NULL,
`first_letter` varchar(8) DEFAULT NULL COMMENT '首字母',
`sort` int(11) DEFAULT NULL,
`factory_status` int(1) DEFAULT NULL COMMENT '是否为品牌制造商:0->不是;1->是',
`show_status` int(1) DEFAULT NULL,
`product_count` int(11) DEFAULT NULL,
`product_comment_count` int(11) DEFAULT NULL,
`logo` varchar(255) DEFAULT NULL COMMENT '品牌logo',
`big_pic` varchar(255) DEFAULT NULL COMMENT '专区大图',
`brand_story` text COMMENT '品牌故事',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1747297739014 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='品牌表';
</code>Register the table in the
accesstable with alias
PmsBrand:
<code>INSERT INTO `apijson_sys`.`access` (id, debug, schema, name, alias, `get`, head, gets, heads, post, put, `delete`, date, detail)
VALUES (NULL, 0, 'mall_api', 'pms_brand', 'PmsBrand', '["UNKNOWN", "LOGIN", "CONTACT", "CIRCLE", "OWNER", "ADMIN"]', '["UNKNOWN", "LOGIN", "CONTACT", "CIRCLE", "OWNER", "ADMIN"]', '["LOGIN", "CONTACT", "CIRCLE", "OWNER", "ADMIN"]', '["LOGIN", "CONTACT", "CIRCLE", "OWNER", "ADMIN"]', '["OWNER", "ADMIN"]', '["LOGIN", "CONTACT", "CIRCLE", "OWNER", "ADMIN"]', '["OWNER", "ADMIN"]', '2018-11-29 00:29:19', NULL);
</code>Now the universal API for
PmsBrandis available. Example operations:
Query brand by ID:
<code>{
"PmsBrand": {
"id": 6
}
}
</code>Result:
Add a new brand:
<code>{
"PmsBrand": {
"name": "新增品牌",
"first_letter": "M",
"sort": 500,
"factory_status": 1,
"show_status": 1,
"product_count": 100,
"product_comment_count": 100,
"logo": "http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/images/20180518/5a912944N474afb7a.png",
"big_pic": "http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/images/20180518/5afd7778Nf7800b75.jpg",
"brand_story": "新增品牌的故事"
}
}
</code>Result:
Update a brand:
<code>{
"PmsBrand": {
"id": "1747300320185",
"name": "修改品牌",
"brand_story": "修改新增品牌的故事"
}
}
</code>Result:
Delete a brand:
<code>{
"PmsBrand": {
"id": 1747300320185
}
}
</code>Result:
Paginated query sorted by
sortdescending:
<code>{
"[]": {
"PmsBrand": {
"@column": "id,name,first_letter,brand_story,sort",
"@order": "sort-"
},
"page": 0,
"count": 5
}
}
</code>Result:
Conclusion
By creating database tables, APIJSON can automatically generate backend API interfaces, dramatically simplifying development cycles. Explore its additional features for more advanced use cases.
Project Link
https://github.com/Tencent/APIJSON
macrozheng
Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.