tailieunhanh - Building Spring 2 Enterprise Applications phần 8

AOP thành phần cốt lõi trong mọi hình thức phân giới cắm mốc giao dịch là . lớp. Đó là một lời khuyên xung quanh thực hiện các giao diện MethodInterceptor (xem Chương 3). | CHAPTER 8 SPRING MVC 231 Table 8-4. Examples of Generated View Names Context Path Servlet URL Mapping Request URI Generated View Name test .html test members .html members test g test app app members test app test app members app members app app members app members .html index But how is the URI of controllers chosen The convention is to use the short name of the controller s class. In this case the class name is AllMembersController. By default the Controller suffix is removed and the remaining string is made lowercase. We are left with allmembers. As you ll recall DispatcherServlet is mapped to app so we can now access AllMembersController with http servletcontext app allmembers. If DispatcherServlet is mapped to .html in we can accessAllMembersControllerwith http servletcontext app . To utilize this convention in your application you must declare a ControllerClassNameHandler Mapping bean in your file. This is because the convention of taking the controller s class name to build the URI mapping is not the default. Fortunately it s very easy to declare. Simply add Listing 8-7 to your file. Listing 8-7. ControllerClassNameHandlerMapping in bean id controllerNameHandlerMapper class Getting back to how the view is chosen if the URI ends with app allmembers the last element is allmembers. The view name therefore is allmembers. Of course if we specified the view name in ModelAndView that would take precedence over this default view name. Caution This convention of automatic view-name generation is new with Spring MVC . It does not work with releases prior to . So to which view does allmembers map For this sample application we are using JSP pages as the view technology and we have placed all JSP pages into the WEB-INF jsp directory. Therefore

TỪ KHÓA LIÊN QUAN