`
ibvjc36f
  • 浏览: 12958 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

MyEclipse for Spring 8.6: Spring MVC Scaffolding

 
阅读更多

  Scaffolding consists of single-pass generation of full or major portions of an application by applying standard application patterns from a minimal set of inputs provided by the developer. In some cases the scaffolded applications are used as-is, but in other cases the scaffolded artifacts are used as a starting point for additional customization by a developer. In either case scaffolding, originally popularized by the RAILS and GRAILS frameworks, is very effective at jump-starting application development. Spring MVC is a web framework from the creators of the Spring. While it isn't the only Spring-based web framework, it is one of the mostly commonly used web frameworks. This scaffolding tutorial is going to focus on generating a ready-to-run application based on the Spring MVC web framework. Since Spring MVC is just a web framework and the goal is to generate a ready-to-run application, the other layers of the application will also be scaffolded, including the service layer, data access layer, and in some cases even the domain layer. 
  
  Application Architecture: Spring MVC - Annotation-based Programming Model Spring MVC supports multiple approaches for implementing the web layer, and Spring 2.5 added support for an annotation-based programming model. The annotation-based approach has quickly become the predominant way of using Spring MVC, and it's generally regarded as the best practice in Spring MVC development. The scaffolding functions of MyEclipse for Spring will generate the web layer using the annotation-based programming model. What about other web technologies? This tutorial is focused on Spring MVC, but the scaffolding wizard can also generate the web layer implementation for Spring Web Flow, Adobe Flex, GWT and iPhone. 
  
  MyEclipse for Spring uses the Create-Read-Update-Delete (CRUD) application pattern for generating applications that allows the end-user to manage application data. While CRUD isn't the only application pattern, it's a fairly typical application pattern. While not all web applications are satisfied solely by the CRUD application pattern, developers find that the resulting generated application artifacts lend themselves to being easily re-used, customized and extended. CRUD applications are tied to an application domain model that is used as the input into the scaffolding engine. The domain model can exist in many forms, and the MyEclipse for Spring scaffolding functionality supports the use of Java beans, JPA entities, or database tables as inputs. This tutorial is going to walk you through producing a ready-to-run Spring MVC application that implements the CRUD application pattern for a domain model. MyEclipse for Spring will be used to generate the entire application within a matter of minutes that includes:  A JPA entity corresponding to domain model (CUSTOMERS) A DAO for managing the JPA entity, Finder methods (JPA named queries) in the DAO based on domain model fields, A Service with fully implemented CRUD operations for managing domain model, A Controller with fully implemented request handlers for supporting web application, All the necessary Spring annotations and configuration files for a Spring MVC app, CRUD JSP pages using Spring Form tag library and JSTL Layout managed user interface using Sitemesh, Client-side validation implemented Spring JS with DOJO, CSS for UI styling JUnits for every Service and Controller, SpringSource certified code and configuration files, Generated code that follows Spring Recipes, The prerequisites needed to complete this tutorial are:  It's now time to automatically generate all the necessary Java/Spring code and configuration files to implement the CRUD application.  Right-click on the CustomersApp project, and choose MyEclipse > Scaffold CRUD application from... 
  
  The first step is to select the type of artifact you want to scaffold from. As mentioned in the introduction there are a variety of possible inputs into scaffolding. For this tutorial we're going to scaffold from a preexisting database table that comes with MyEclipse Derby database. Choose the Database Schema option on the Select Artifact Type(s) panel. Click the Next button. 
  
  The next step is to select the DB connection for accessing the MyEclipse Derby database. This panel will show you all configured DB connections in the MyEclipse workspace, and you must select the MyEclipse Derby connection, which is a preconfigured DB connection in MyEclipse. Click the Next button. 
  
  The next step is to select the desired schema and database table(s) that should be used for scaffolding. When the CLASSICCARS schema is selected the tables list will be populated with a list of all the available tables. The CUSTOMER table should be added to the scaffolding list. Click the Next button. 
  
  The next panel will prompt you to select parent objects, and this panel also lets you override the derived name of the Java Object that will be created from the database table. Since we're only scaffolding from a single database table, the Customer Java object must be the parent. For this tutorial there's nothing that needs to be changed on this panel. Just click the Next button. 
  
  Note: Java Object names are automatically derived from table names, but the name can be overridden by double-clicking on the name and typing a new name. The next step is to specify which layers of the application should be scaffolded and which package names should be used for each layer. All the layers are enabled by default. Enter org.customerapp as the base package. The package names for the different layers will be automatically derived from the base package. A sub-package (i.e. web, service, DAO, and domain) will be added to the end of the base package. 
  
  The next step is to specify which web clients should be generated for the web layer. As you can see, there are a variety of different web clients available, including Spring MVC, Spring Web Flow, Adobe Flex, GWT, and iPhone. This tutorial is focused on Spring MVC, so click on the Generate checkbox for Spring MVC. 
  
  The next step is in an optional step to customize the UI. For this tutorial we'll go with the defaults. 
  
  The final configuration step is to specify where the application (source code, configuration files, JSP, etc...) should be generated to. For this panel the defaults are fine. Click the Next button. 
  
  The final panel will give you a summary of everything that will be generated for you. Click the Finish button to scaffold the application from the information you provided in the wizard. 
  
  That's it. Once the wizard is complete you have a ready-to-run Spring MVC application that implements the CRUD application pattern for the domain model (CUSTOMERS DB table). Scaffold Spring DSL If you also want to scaffold Spring DSL artifacts for further maintenance and enhancement using Spring DSL Editors, then you should run the Add Spring Code Generation Capabilities wizard first, which will enable the Spring DSL for your project and add the Spring DSL view to your project. The scaffolding wizard will then add corresponding Spring DSL artifacts (model packages, controllers, services, etc...) for all scaffolded application components. You will see them all in the Spring DSL view of your project, and you can maintain and enhance the scaffolded artifacts using the Spring DSL and Spring Editors. To deploy the application, right-click on the CustomersApp project and select Run As --> MyEclipse Server Application. 
  
  MyEclipse Tomcat will start up. The first page will be a dashboard for accessing all scaffolded web clients. Since this tutorial only scaffolded a single database table for Spring MVC, the only option under Spring MVC is View Customers. Click on it to see generated Spring MVC application in operation. 
  
  The Spring MVC application can be used to (a) list all customers, (b) view a customer, (c) edit a customer, (d) delete customers and (e) add new customers. The following screen shots show some of the views. 
  
  
  Now that you have a running Spring MVC application, you may want re-run the tutorial and scaffold different web clients, including Spring Web Flow, Adobe Flex, GWT, and iPhone. You may also want to try the Spring Annotator and JAX-WS Annotator tutorials which are available in the Eclipse help system and online (see Additional Developer Resources). What was your experience with this tutorial? Share your experience with us by completing a very brief survey. Thank you for you interest in MyEclipse for Spring. If you are interested in learning more, the following developer resources are available: Developer Resources Reference - Eclipse Help (MyEclipse for Spring 8.6 --> MyEclipse for Spring Reference) or Education Materials (online) Tutorials - Eclipse Help (MyEclipse for Spring 8.6 --> Tutorials) or Education Materials (online) Screencasts - MyEclipse for Spring YouTube Channel (online) Support Forums - MyEclipse for Spring Forums (online) Blog - MyEclipse for Spring Posts (online)
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics