![]() |
VOOZH | about |
Spring Boot provides the @Controller annotation to define classes that handle web requests and control the flow of a web application. A controller acts as an intermediary between the user interface and the business layer, processing incoming requests and returning appropriate responses or views.
In an Employee Management System:
Follow these steps to create Controller in spring boot application.
Create a new Spring Boot project using your preferred IDE (Eclipse, IntelliJ IDEA, or Spring Initializr).
If using Spring Initializr, select:
In case your project does not include it by default, add the following dependency to your pom.xml:
This provides the necessary libraries for creating web applications and REST APIs.
Create a package named controller under src/main/java/com/example/demo/. This package will contain the controller class that handles web requests.
👁 ImageInside the controller package, create a file named DemoController.java.
/hello URL to the helloGFG() method.Create a main class DemoApplication.java under the base package com.example.demo.
@SpringBootApplication combines three annotations:
@Service, and @Repository.Run the DemoApplication class as a Java Application. By default, the application starts on port 8080.
Access the endpoint at
http://localhost:8080/hello
If you want to change the port, modify the application.properties file:
👁 Imageserver.port=8989