1.准备开发环境
在MyEclipse中新建一个Web Project,名称为ItcastHR,设置工程的默认编码为utf-8 。
创建数据库itcastHR,注意编码要支持中文,比如设定为utf8。
2.添加框架的开发环境
Junit
struts2.3
配置struts.xml
在web.xml中配置核心过滤器
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
hibernate3
配置hibernate.cfg.xml
spring3.2.5
配置applicationContext.xml
3.整合ssh
(1)添加jar包
struts2-spring-plugin-2.3.4.1.jar
用于整合ss
(2)在web.xml中配置
配置Spring的用于初始化容器对象的监听器
<listenler>
<listenler-class>org.springframework.web.context.ContextLoaderListener</listenler-class>
</listenlet>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext*.xml
</param-value>
</context-param>
注意:param-value的值与配置文件的名字要一致
4.给工程中的资源文件分类
源码文件夹
src 项目源代码
config 配置文件
test 单元测试
WebRoot文件夹
script JavaScript脚本文件
style CSS样式文件
WEB-INF/jsp jsp页面(再创建子文件夹分类存放)
5.设计baseDao与他的实现类:主要用于抽取公共接口与实现公共的方法
6.遇到的问题以及经验
1.导入jar包时遇到过冲突与重复或者版本冲突的原因,所以最好用maven管理jar包坚持用什么导什么。
2.完成一个小模块或者功能及时测试
3.action层调用service层再调用dao层。也就是我们可以按照这个顺序先写action的代码看需要什么功能再写后两个
4.一般将接口的实现类放入ioc容器中,我们调用接口中的方法会调用实现类的方法,因为容器实例化的是实现类接口不能实例化。
5.在使用注解的方式从容器获取实例时最好自己给一个value值即@Component(“”value“”),这个值和你的实例化的属性名字一致,不写的话默认要与类名一致,然后首字母小写。
6.公共的方法和接口抽取出来。
7.配置文件一般核心包里面有模板,或者去一个叫simple的文件夹或者官网上去找。