Spring @RequestParam Annotation
as shown in the above URL if we want to read the eid and ename then we can read them using the @RequestParam annotation
Let's see the example in STS
Directory Structure:
EmployeeController.java
package com.example.demo.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class EmployeeController {
@GetMapping("/get")
public String get(@RequestParam("eid") Integer id,@RequestParam String ename) {
return id+"="+ename;
}
}
Run the application
Test Using the Postaman or browser
@RequestParam("eid") Integer id
above we are taking "eid" in bracket because variable id is different from the url that we are giving in the url "http://localhost:8080/get?eid=1&ename=sam"
@RequestParam String ename
above we are not taking anything after @RequestParam inside bracket because
the variable name is similar to the query parameter.