2012年3月26日
摘要: 1.@Controller level Annotate a separate method in your @Controller as a @ExceptionHandler simply catch the Exception yourself in your handler method2. DispatcherServlet level Rely on the DefaultHandlerExceptionResolver:Maps common exceptions to appropriate status codes Supplement with your own c... 阅读全文
posted @ 2012-03-26 23:45 leaving 阅读(256) 评论(0) 推荐(0)
摘要: Get a new form Export a JavaBean to the view as the “form bean” or “form backing object” Can pre-populate form using initial bean property values or client queryparameters Convenient form tags/macros exist to simplify rendering form fields1.Invoked on every request@ModelAttribute public void a... 阅读全文
posted @ 2012-03-26 23:42 leaving 阅读(796) 评论(0) 推荐(0)
摘要: Trigger validation by marking a JavaBean parameter as @Valid The JavaBean will be passed to a Validator for validation The JavaBean will be passed to a Validator for validationBinding and validation errors can be trapped and introspected bydeclaring a BindingResult parameter Must follow the JavaB... 阅读全文
posted @ 2012-03-26 23:34 leaving 阅读(924) 评论(0) 推荐(0)
摘要: Type conversion happens automaticallyA common “ConversionService” underpins the places where typeconversion is required Always used with @RequestParam, JavaBean, @PathVariable, and@RequestHeader, and @CookieValue HttpMessageConverter may use when reading and writing objects:for @RequestBody, @Resp.. 阅读全文
posted @ 2012-03-26 23:30 leaving 阅读(1010) 评论(0) 推荐(0)
摘要: 1.Two different systems exist for rendering responses ViewResolver + View HttpMessageConverter2.Triggered in different ways Render a view by returning a String Write a message by returning a @ResponseBody Object or ResponseEntity3.Which one do I use? Use views to generate documents for display ... 阅读全文
posted @ 2012-03-26 23:17 leaving 阅读(238) 评论(0) 推荐(0)
摘要: Behind the scenes, a HttpMessageConverter underpins reading therequest body and generating the responseMultiple converters may be registered for different content typesFor @RequestBody, the first converter that can read the POSTed "Content-Type" into the desired method parameter type is us 阅读全文
posted @ 2012-03-26 23:10 leaving 阅读(2906) 评论(0) 推荐(1)
摘要: 1.Return a POJO annotated with @ResponseBody:POJO marshaled as the body of the response @RequestMapping(value="/response/annotation", method=RequestMethod.GET) public @ResponseBody String responseBody() { return "The String ResponseBody"; } @RequestMapping(value="/response/c 阅读全文
posted @ 2012-03-26 22:53 leaving 阅读(262) 评论(0) 推荐(0)
摘要: 1.HttpServletRequest (or its more portable WebRequest wrapper)、Principal、Locale@RequestMapping(value="/data/standard/request", method=RequestMethod.GET)public @ResponseBody String standardRequestArgs(HttpServletRequest request, Principal user, Locale locale) { StringBuilder buffer = new St 阅读全文
posted @ 2012-03-26 22:43 leaving 阅读(538) 评论(0) 推荐(0)
摘要: 1. a query parameter value@RequestParam("name")2.a group of query parameter values//A custom JavaBean with a getName()/setName() pair for each parameter@RequestMapping(value="group")public @ResponseBody String withParamGroup(JavaBean bean) { return "Obtained parameter group 阅读全文
posted @ 2012-03-26 22:37 leaving 阅读(651) 评论(0) 推荐(0)
摘要: 1. by path@RequestMapping("path")2. by http method@RequestMapping("path", method=RequestMethod.GET)3. by presence of query parameter@RequestMapping("path", method=RequestMethod.GET, params="foo")Negation also supported: params={ "foo", "!bar&quo 阅读全文
posted @ 2012-03-26 22:28 leaving 阅读(476) 评论(0) 推荐(0)
摘要: 1. DispatcherServlet render Views Alternative to having a HttpMessageConverter write the response body Designed for generating text/* content from a template @RequestMapping(value="html", method=RequestMethod.GET) public String prepare(Model model) { model.addAttribute("foo", &qu 阅读全文
posted @ 2012-03-26 01:14 leaving 阅读(362) 评论(0) 推荐(0)
摘要: <%@ page isELIgnored="false" %> 阅读全文
posted @ 2012-03-26 01:05 leaving 阅读(244) 评论(0) 推荐(0)