Đối với các mục đích của cuốn sách này, chuyên trong các ứng dụng web, chúng tôi đã nâng cao giao diện người sử dụng một lớp chính thức bởi vì nó đã thiết lập riêng của mình các mối quan tâm và các chi tiết thực giao diện người dùng thường là lớp trên cùng. Về mặt khái niệm, | CHAPTER 4 JUMP INTO SPRING MVC 67 Summary Command beans are POJOs that encapsulate the data from a form submission. Command bean classes must have getters and setters whose property names match the names of the form fields. Spring MVC uses PropertyEditors to help convert String values from the request into the expected types of the properties of the command bean class. SearchFlightsController With the service layer and the SearchFlights class already created we can quickly build the SearchFlightsController shown in Listing 4-16. Listing 4-16. SearchFlightsController Class public class SearchFlightsController extends SimpleFormController private FlightService flights public SearchFlightsController setCommandName searchFlights setCommandClass setFormView beginSearch setSuccessView listFlights public void setFlightService FlightService flights flights @Override protected void initBinder HttpServletRequest req ServletRequestDataBinder binder throws Exception new CustomDateEditor new SimpleDateFormat yyyy-MM-dd HH true @Override protected ModelAndView onSubmit Object command throws Exception SearchFlights search SearchFlights command ModelAndView mav new ModelAndView getSuccessView flights search searchFlights search return mav 68 CHAPTER 4 JUMP INTO SPRING MVC The constructor is used to declaratively configure the class defining the command bean the command name and the view names for the form work flow. setCommandName defines the name of the command bean when referenced by the view page. You will see this name referenced with the spring nestedPath tag in the JSP in Listing 4-8 defining the bean to be used for the entire XHTML form. setCommandClass defines the class to be used for the command bean. This can be any POJO with getters and setters and it can include both simple and complex types for properties. setFormView defines the logical name for the