Skip to content

Generating Spring RESTController Templates #30078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

VINAYAK28x
Copy link

Feature: Add Spring Boot REST Controller Generator (spring-controller)

Summary

This PR introduces a new Yeoman sub-generator named spring-controller that allows users to scaffold a basic Spring Boot REST controller with minimal input.

Features

Prompts the user for:

Java package name (e.g., com.example.app)

Controller class name (e.g., GreetingController)

Base endpoint (e.g., /api/greeting)

HTTP method (GET, POST, PUT, DELETE)

Java method name (e.g., sayHello)

Generates a complete controller in the appropriate directory structure:

src/main/java//web/rest/.java

Automatically formats the correct Spring annotation:

@GetMapping, @PostMapping, etc.

Simple and clean generated output:

@RestController
@RequestMapping("/api/greeting")
public class GreetingController {

@GetMapping
public String sayHello() {
    return "Hello from GreetingController";
}

}


Manual Testing

Verified on a fresh JHipster monolith project

Output controller compiles and runs successfully

Prompts behave as expected

File Structure

Added in:

generators/spring-controller/
├── index.js
└── templates/
└── Controller.java.ejs

Future Improvements

Support method parameters (@RequestBody, @PathVariable)

Add unit test scaffolding

Integrate with service layer

Add automated tests for the generator

Why This Is Useful

This generator speeds up development by automating the creation of REST endpoints — especially helpful for beginners and rapid prototyping.

@github-actions github-actions bot added theme: java theme: dependencies Pull requests that update a dependency file labels Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: dependencies Pull requests that update a dependency file theme: java
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant