Automate Java CRUD Code Generation with a Free Open‑Source Tool
Tired of manually creating entity classes, CRUD interfaces and SQL for dozens of tables, the author built an open‑source utility that generates complete backend code—including models, DAOs, services and controllers—in a single click, dramatically cutting development time.
Origin
When working on a project that required more than 20 new tables, the author realized that manually creating entity classes, CRUD interfaces and SQL for each table would take over 40 hours, so they built a tool to generate all business code automatically.
Demo
The tool lets you input a table name and its Chinese description, add fields, then click “One‑click generate code”. It produces the SQL for table creation, CRUD SQL, entity classes, DAO interfaces, service implementations and controller classes, which can be copied into a project.
It also supports importing existing CREATE TABLE statements: paste the SQL, the tool parses it, you fill the Chinese name, and it generates the same code.
General Considerations
While the generated code works for the author’s own projects, different companies have different layer structures, so the tool provides a template configuration feature to customize code templates.
Design
The generation principle is simple: a set of code templates containing dynamic parameters and user‑provided values. During generation the tool replaces each dynamic parameter (e.g., $table_name$, $field_name_hump$, $current_time$) with the corresponding value, producing the final source files. In theory any language can be supported by defining appropriate templates.
Templates
Examples of default templates include CREATE TABLE SQL, entity class, DAO interface, CRUD mapper XML, model converter, service implementation and controller. Each template shows how dynamic parameters are used to fill table name, field list, primary key, timestamps, etc.
/**
* $table_desc$Model模型
* Created by 创建人 on $current_time$.
*/
public class $table_name_hump_A$Model extends ToString {
} CREATE TABLE `$table_name$` (
$create_table_field_list$
PRIMARY KEY (`$primary_key$`)
) ENGINE=$db_engine$ DEFAULT CHARSET=$db_encoded$;Dynamic Parameters
Parameters such as $table_name$, $table_name_hump$, $table_desc$, $field_type_java$, $primary_key$, $current_time$, and many others are described, allowing the tool to generate accurate code based on user input.
Dynamic Code Blocks
Users can define custom code blocks for member variables, getter/setter methods, model conversion, and required‑field validation. The tool repeats these blocks for each field, producing complete Java classes.
/** $field_comment$ */
private $field_type_java$ $field_name_hump$; public $field_type_java$ get$field_name_hump_A$() {
return $field_name_hump$;
}
public void set$field_name_hump_A$($field_type_java$ $field_name_hump$) {
this.$field_name_hump$ = $field_name_hump$;
}Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
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.
