Stack Exchange
Trim @RequestParam in Springboot
Is there a way to trim @RequestParam in springboot.
For example:
@RestController
public class Controller{
  @GetMapping(value = "/v1/test/", produces = "application/json")
  public Response getTest(
    @RequestParam(name = "name") String name){
  }
}

GET: localhost:8080/v1/test/?name =test
GET: localhost:8080/v1/test/?name=test


Probably this can help by retrieving all params, and trimming afterwards: https://stackoverflow.com/questions/7312436/spring-mvc-how-to-get-all-request-params-in-a-map-in-spring-controller

So for example if a user tries localhost:8080/v1/test/?name =test, it should trim "name " ==> "name"

As per my understanding you need to get output even it contains whitespaces
GET: localhost:8080/v1/test/?name =test
GET: localhost:8080/v1/test/?name=test

so i suggest you can use, "Map<String,String>" instead of String.
Below code is my sample code you can refer it and you can use accordingly
@RequestMapping("/api")
public class DemoController {
    
    @GetMapping("/person/id")
    private String getStudent(@RequestParam Map<String,String> name) throws Exception {
        String value = null;
        if((name.get("g") !=null) || (name.get("g ")) !=null) 
        {
            value = "even";
        }
        else {
            value ="odd";
        }
        return value;
    }
}

changes would be
@RequestParam Map<String,String> name - i have changed
and introduced a condition to check if((name.get("g") !=null) || (name.get("g ")) !=null)
Thanks :)
