Create Project: springboot_endpoint_annotation_pathvariable (add Spring Boot Starters from the table)
Create Package: controllers (inside main package)
– Create Class: MyController.java (inside package controllers)
MyController.java
package com.ivoronline.springboot_endpoint_annotation_pathvariable.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MyController {
@ResponseBody
@GetMapping("/Hello/{FirstName}/{age}")
public String hello(
@PathVariable("FirstName") String name, //IF NAMES ARE DIFFERENT
@PathVariable String age //IF NAMES ARE THE SAME
) {
return name + " is " + age + " years old";
}
}