Boost Java Backend Productivity with the Java CG IDEA Code‑Generation Plugin

This article introduces a lightweight IntelliJ IDEA plugin that automatically generates database‑related Java code—including entities, DTOs, controllers, and service layers—based on a simple configuration file, while also offering design‑pattern template generation to accelerate backend development.

Java Backend Technology
Java Backend Technology
Java Backend Technology
Boost Java Backend Productivity with the Java CG IDEA Code‑Generation Plugin

Introduction

With modern ORM frameworks reducing the need for manual Entity and Controller code, many developers rely on code‑generation tools. Existing solutions often require server resources or lack offline support, so this article presents an IntelliJ IDEA plugin that generates code directly within the IDE, eliminating extra copying and adding design‑pattern templates.

Database Code Generation

Installation: Search for Java CG in the IDEA plugin marketplace (case‑insensitive).

Usage: In the project’s resource directory, add a cg_config.properties file with the following content:

# Database name
database=book_manager
# Database URL
url=jdbc:mysql://localhost:3306/book_manager?useUnicode=true&characterEncoding=UTF-8
# Username
username=root
# Password
password=root
# Package name for generated files
packageName=com.cqry
# Name of the result object returned by controllers
resultName=Json
# Package of the result object
resultPackage=com.cqry.utils
# Name of the return code field
returnCodeName=ReturnCode
# Success code name
successCodeName=ReturnCode.OK
# Package of the return code enum
returnCodePackage=com.cqry.utils.enumeration

After adding the file, select File → New in IDEA to see the generation options.

Click “Generate Code” to open the basic information dialog, fill in the details, and submit.

The project refreshes automatically, producing a directory structure like the following:

The generated entity package includes:

bo: business request objects containing all table fields, customizable.

enums: enum representations of database enum columns extracted from column comments.

query: query request objects extending a custom PageParam with pagination validation.

The vo package holds view objects for front‑end rendering, and the base entity extends EntityBase with common fields such as ID, creator, timestamps, and deletion status.

The generated mapper, service, and controller classes feature:

CRUD methods plus a paginated query.

Parameter validation using Spring Validation.

Duplicate‑submission protection via a custom PreventRepeat annotation backed by Redis.

Uniform JSON response objects configurable in cg_config.properties.

Standardized return codes via a configurable ReturnCode enum.

Design‑Pattern Template Generation

The plugin also supports generating common design‑pattern code templates. Currently available patterns include:

Singleton (enum, constant, double‑checked locking)

Strategy (enum, functional, factory with template)

Decorator

For example, generating an enum‑based strategy yields the following code:

Conclusion

Interested readers can download and try the plugin, customize it for their own projects, or even develop their own IDEA plugins. Adding such a plugin to your résumé demonstrates practical experience with IDEA plugin development, giving you an edge in the job market.

Plugin source:

https://github.com/jekran/code_generate
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.

Backend DevelopmentCRUDIDEA Plugin
Java Backend Technology
Written by

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!

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.