Spring 应为带“的请求参数”;“异或”;验证
我在SpringMVC控制器中有一个简单的请求调用Spring 应为带“的请求参数”;“异或”;验证,spring,spring-mvc,Spring,Spring Mvc,我在SpringMVC控制器中有一个简单的请求调用 @ResponseBody @RequestMapping(value = "/url", method = RequestMethod.GET) public SomeDTO getSth(@RequestParam("paramA") Integer paramA, @RequestParam("paramB") Integer paramB) { // ... } 我想让paramA或paramB都有一个正常的http响应,如果
@ResponseBody
@RequestMapping(value = "/url", method = RequestMethod.GET)
public SomeDTO getSth(@RequestParam("paramA") Integer paramA, @RequestParam("paramB") Integer paramB) {
// ...
}
我想让paramA或paramB都有一个正常的http响应,如果我不同时提供这两个参数的话
我知道有一个必需的参数可用,但我看不到连接这两个参数的方法。有什么想法吗?我想不出一个很好的解决方案,但直截了当的解决方案似乎很正常,不是吗
@ResponseBody
@RequestMapping(value = "/url", method = RequestMethod.GET)
public String getSth(@RequestParam(value = "paramA", required = false) Integer paramA,
@RequestParam(value = "paramB", required = false) Integer paramB) {
if (paramA == null ^ paramB == null) {
return "body";
} else {
throw new BadRequestException();
}
}
@ResponseStatus(value = HttpStatus.NOT_FOUND)
public static class BadRequestException extends RuntimeException {
private static final long serialVersionUID = 1L;
}