一般步骤:
1、建数据表(例如:User)
2、建立工程
3、为工程添加Struts
4、为工程添加Spring
5、连接数据库
6、为工程添加Hibernate,Hibernate交由Spring管理
7、把Spring添加到Struts中
(1) 打开struts-config.xml,添加一个插件:选择的类是ContextLoaderPlugIn,
(2)在其中添加属性:contextConfigLocation,对应的value:classpath:applicationContext.xml
8、在struts-config.xml中配一个controller。
<controller>
<set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor" />
</controller>
9、建立包:(最好按层次分)
entity包
数据持久层包
业务逻辑层包
表示层包
10、为数据库对应表设置hibernate,放在entity实体包中,生成对应的userDAO拖到dao的包(数据持久层)中
11、做完了数据持久层,做业务逻辑层,在service包中新建类: UserService(包括注册方法)
12、业务逻辑层做完,做表示层,利用Struts直接生成jsp,action,form,删除Action的type属性(因为前面已经配置了 Controller)
13、做成功页面,为Struts配置页面迁移(在Forward Scope处选择Local Action forward,Action path选
择:/user)
14、编写UserAcion,添加userService,并setter,getter,建立user,得到各属性,用userservice的注册方法注册用 户
15、在applicationContext.xml中注册刚才那些类,用Spring注入
添加Spring Bean,首先添加service:
Bean id:userService
Bean class:userService
需要引用属性(properties)
new property name:UserDAO
Spring type:ref
Reference type:local
Reference name:userDAO
定义Struts,此处不用bean id,用name
name:/user
class:UserAction
需要引用属性(properties)
new property name:userService
Spring type:ref
Reference type:local
Reference name:userService
ssh简单工程笔记
最新推荐文章于 2025-08-06 22:06:43 发布