Spring MVC 学习笔记 七 controller中其他可用的annotation
@InitBinder
在controller中注册一个customer protperty editor以解析request中的参数并通过date bind机制与handler method中的参数做绑定。
@InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor( dateFormat, false)); }
@RequestMapping("/databind1") public ModelAndView databind1(Date date) { … }
@ResponseStatus(reason="no reason",value=HttpStatus.BAD_REQUEST) @RequestMapping("/responsestatus") public void responseStatusTest(){ }
@RequestMapping("/exception") public void ExceptionTest() throws Exception{ throw new Exception("i don't know"); } @ExceptionHandler public String handleException(Exception e,HttpServletRequest request){ System.out.println(e.getMessage()); return "helloworld"; }