有没有办法可以使用@Valid
注释验证String类型的函数参数?
我一直试图这样做,但却无法做到。 这是我的代码: -
@Controller
public class GameController {
@Autowired
private HeaderValidator headerValidator;
@InitBinder
private void initBinder(WebDataBinder binder) {
binder.setValidator(new CompoundValidator(headerValidator));
}
@RequestMapping(value = "game", method = RequestMethod.GET)
public @ResponseBody Game getGame(
@Valid @RequestHeader(value = "header", required = true) String header) {
return new Game(1, "Baddy");
}
}