【发布时间】:2016-10-17 09:04:33
【问题描述】:
@Controller
@EnableWebMvc
@Validated
public class ChildController extends ParentController<InterfaceController> implements InterfaceController{
@Override
@RequestMapping(value = "/map/{name}", produces = "application/json; charset=UTF-8", method = RequestMethod.GET)
@ResponseStatus( HttpStatus.OK)
@ResponseBody
public List<Friends> getAllFriendsByName(
@Valid
@Size(max = 2, min = 1, message = "name should have between 1 and 10 characters")
@PathVariable("name") String name,
@RequestParam(value="pageSize", required=false) String pageSize,
@RequestParam(value="pageNumber", required=false) String pageNumber,
HttpServletRequest request) throws BasicException {
//Some logic over here;
return results;
}
@ExceptionHandler(value = { ConstraintViolationException.class })
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public String handleResourceNotFoundException(ConstraintViolationException e) {
Set<ConstraintViolation<?>> violations = e.getConstraintViolations();
StringBuilder strBuilder = new StringBuilder();
for (ConstraintViolation<?> violation : violations ) {
strBuilder.append(violation.getMessage() + "\n");
}
return strBuilder.toString();
}
您好,我正在尝试对 spring 请求参数进行非常基本的验证,但它似乎没有调用异常处理程序,有人可以指出我正确的方向
附:我不断收到 NoHandlerFoundException
【问题讨论】:
标签: spring rest validation