Atharva Siddhabhatti
Atharva Siddhabhatti's Blog

Atharva Siddhabhatti's Blog

Hello World in Spring Boot

Hello World in Spring Boot

Atharva Siddhabhatti's photo
Atharva Siddhabhatti
·Oct 12, 2021·

1 min read

Installation

Clone the repository from here Click Here

Import Maven based project in any of your Favourite IDE.

Execute the following command in terminal.

./mvnw spring-boot:run

Output

Open in Browser

http://localhost:5000/hello-world
http://localhost:5000/helloworld-bean

Usage

HelloWorldController.java

helloWorld() method returning a string "Hello World".

@GetMapping("/hello-world")
    public String helloWorld() {
        return "Hello World";
    }

helloWorldBean() method returning a bean.

@GetMapping("/helloworld-bean")
    public HelloWorldBean helloWorldBean() {
        return new HelloWorldBean("Hello World");
    }

helloWorld1() method printing Hello World, 'name' using @PathVariable annotation

@GetMapping("/helloworld/{name}")
    public HelloWorldBean helloWorl1(@PathVariable String name) {
        return new HelloWorldBean(String.format("Hello World, %s", name));
    }

Credits

in28Minutes

 
Share this