我如何在Spring中验证我的路径变量。 我想要验证id字段,由于它是单个字段,因此我不想转移到Pojo
@RestController
public class MyController {
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public ResponseEntity method_name(@PathVariable String id) {
/// Some code
}
}
我尝试对路径变量添加验证,但仍然无法正常工作。
@RestController
@Validated
public class MyController {
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public ResponseEntity method_name(
@Valid
@Nonnull
@Size(max = 2, min = 1, message = "name should have between 1 and 10 characters")
@PathVariable String id) {
/// Some code
}
}