projectGuidex

batterycopperInternet and Web Development

Nov 12, 2013 (3 years and 8 months ago)

122 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.ph
p


Help
-
>Install
N
ew 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.sa
mples.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
constructor

arguments
,
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.PetSt
oreImpl
">


<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.domai
n.logic.PetStoreImpl

public class
PetStoreImpl

implements
PetStoreFacade
,
OrderService

{


private
AccountDao

accountDao
;


private
CategoryDao

categoryDao
;


private
ProductDao

productDao
;


private
ItemDao

itemDao
;


private
OrderDao

orderDao
;




}

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

Spring MVC


Controller


Synchronize changes between model and view


model

Controller

view

Action

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.xml

map

action to
controller

<bean id=
"
defaultHandlerMapping
"
class="
org.springframework.web.servlet.handler.BeanNameUrlHandl
erMapping
"/>


<bean name=
"
/shop/
addItemToCart.do
"
class="org.springframework.samples.jpetstore.web.spring.AddItem
ToCartController">


<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