240 likes | 480 Views
OOT 实习指南. 顾天晓 ktxjoro@gmail.com. 内容提要. 运行起 Jpetstore Jpetstore 源码解析 Spring IoC Spring MVC 实习项目分析. 运行 Jpetstore. 搭建环境 下载安装 jdk 下载安装 SpringSource Tool Suite 下载 subversion 插件 下载 Jpetstore 源码 编译、打包、部署. 下载 subversion 插件. Eclipse Plugin http://www.eclipse.org/subversive/downloads.php
E N D
OOT实习指南 顾天晓 ktxjoro@gmail.com
内容提要 • 运行起Jpetstore • Jpetstore源码解析 • SpringIoC • Spring MVC • 实习项目分析
运行Jpetstore • 搭建环境 • 下载安装jdk • 下载安装SpringSourceTool Suite • 下载subversion插件 • 下载Jpetstore源码 • 编译、打包、部署
下载subversion插件 • Eclipse Plugin • http://www.eclipse.org/subversive/downloads.php • Help->Install New Software • Update site • http://download.eclipse.org/technology/subversive/0.7/update-site/ • SpringByExample
下载jpetstore源码 • SpringSource.org • https://src.springsource.org/svn/spring-samples/ • svn co https://src.springsource.org/svn/spring-samples/jpetstore/trunk/org.springframework.samples.jpetstore/jpetstore • Use subversion plugin • SpringByExample
编译、打包源码 • Maven • http://maven.apache.org/ • STS已经集成Maven插件 • Project Object Model • pom.xml • validate, compile, test, package, integration-test, verify, install, deploy
编译、打包源码 • pom.xml • <properties> • <dependencies> • <repositories> • <plugins>
编译、打包源码 • Jpetstore readme.txt • 1. Run "mvn package" to generate the WAR file • 2. Copy the generated "target/org.springframework.samples.jpetstore-1.0.0-SNAPSHOT.war" to “<TOMCAT_HOME>/webapps/jpetstore.war" • 3. Start HSQLDB via "db/hsqldb/server.bat" or "db/hsqldb/server.sh" • 4. Start Tomcat (default port will be 8080) • 5. Open "http://localhost:8080/jpetstore" in an Internet browser
编译、打包源码 • 修改pom.xml • <spring.version>3.0.4.RELEASE</spring.version> • 添加slf4j-nop-1.5.2.jar运行依赖支持 <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-nop</artifactId> <version>1.5.2</version> <scope>runtime</scope> </dependency>
编译、打包源码 • 启动数据库hsqldb • windows:server.bat • Linux:server.sh • Server.bat • mvn -f %~dp0pom.xml -Ddb.file=%~dp0jpetstore exec:java
编译、打包源码 • 拷贝target/目录下的war文件至tomcat下的webapps文件夹下 • 重命名为jpetstore • http://localhost:8080/jpetstore
Spring 源码分析 • SpringSource Tool中演示
Spring IoC • Inversion of Control • dependency injection • It is a process whereby objects define their dependencies, that is, the other objects they work with, only through constructorarguments, arguments to a factory method, or properties that are set on the object instance after it is constructed or returned from a factory method.
Spring IoC • PetStore <bean id="petStore" class="org.springframework.samples.jpetstore.domain.logic.PetStoreImpl"> <property name="accountDao" ref="accountDao"/> <property name="categoryDao" ref="categoryDao"/> <property name="productDao" ref="productDao"/> <property name="itemDao" ref="itemDao"/> <property name="orderDao" ref="orderDao"/> </bean>
Spring IoC • org.springframework.samples.jpetstore.domain.logic.PetStoreImpl public class PetStoreImpl implements PetStoreFacade, OrderService { private AccountDaoaccountDao; private CategoryDaocategoryDao; private ProductDaoproductDao; private ItemDaoitemDao; private OrderDaoorderDao; … }
Jpetstore源码解析 • Java package • dao.* 数据层 • domain.* 逻辑层 • web.* 表现层
Spring MVC • Model-View-Controller • The Spring Web model-view-controller (MVC) framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler mappings, view resolution, locale and theme resolution as well as support for uploading files.
Spring MVC • Controller • Synchronize changes between model and view Action model view Controller
Spring MVC • web.xml – entry-point for use spring in tomcat <servlet> <servlet-name>petstore</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>2</load-on-startup> </servlet> • Action –Views are modified by Actions and controllers receive the modification, then reflect it to model <servlet-mapping> <servlet-name>petstore</servlet-name> <!-- <servlet-name>action</servlet-name> --> <url-pattern>*.do</url-pattern> </servlet-mapping>
Spring MVC • petstore-servlet.xmlmap action to controller <bean id="defaultHandlerMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/> <bean name="/shop/addItemToCart.do" class="org.springframework.samples.jpetstore.web.spring.AddItemToCartController"> <property name="petStore" ref="petStore"/> </bean> • product.jsp action definition <td><a href="<c:url value="/shop/addItemToCart.do"><c:param name="workingItemId" value="${item.itemId}"/></c:url>"> <img border="0" src="../images/button_add_to_cart.gif"/> </a></td>
实习题目介绍 • 医院挂号系统 • 通过网页访问某医院的预约挂号系统(普通号、专家号、特需号),用户需实名注册,预约成功后得到预约号,在规定时间前不去医院实际挂号则取消预约号。 • 预约不成功则进入等待序列,当有空余号时,挂号系统将自动发送短信或EMAIL将预约号通知用户,用户确认后生效,预约成功。
医院挂号系统 • 用户系统 • 注册与登录 • 挂号系统 • 挂号成功 • 挂号失败 • EMAIL通知
谢谢 顾天晓 ktxjoro@gmail.com