繁体   English   中英

在 Springboot 中修剪 @RequestParam

[英]Trim @RequestParam in Springboot

有没有办法在 springboot 中修剪@RequestParam 例如:

@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

根据我的理解,即使它包含空格,您也需要获得输出

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

所以我建议你可以使用“Map<String,String>”而不是String。 下面的代码是我的示例代码,您可以参考它并相应地使用

@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;
    }
}

更改将是@RequestParam Map<String,String> name - 我已经更改并引入了一个条件来检查if((name.get("g") !=null) || (name.get("g ")) !=null)

谢谢 :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM