一、开发环境及已有CVS项目加载方法
1、开发环境:
jdk-1_5_0-windows-i586.exe;
Eclipse3.2.exe;
eclipse3.2andmyeclipse5.0(MyEclipseEnterpriseWorkbenchInstaller_5.0.1GA_E3.2.exe);
jakarta-tomcat-5.0.28;
备注:先安装jdk-1_5_0-windows-i586.exe,然后安装Eclipse3.2.exe(如果是绿化版,则不需要安装)。
在安装MyEclipseEnterpriseWorkbenchInstaller_5.0.1GA_E3.2.exe时,工作路径指向Eclipse的安装主目录。
2、CVS项目加载:
1)先创建一个CVS库的链接。
2)Check Out(或者Check Out AS)
3) 然后转到“MyEclipse J2EE Development”.
4)JDK和 tomcat 服务配置。
二、O/R 映射方法
3、建立一个J2EE web project;
4、打开MyEclipse DataBase Explorer,创建一个ORACLE数据库连接;
3、搭建Hibernate 框架:"选择工程(第一步创建的)根目录"---"右键"---"MyEclipse"---"add hibernate capabilities"
4、打开MyEclipse DataBase Explorer,“选择对应的数据库表”—“右键”—“hibernate reverse--engineering”
该步骤会生成两类文件*.java 和*.xml文件,需要修改XML文件:
修改:
<hibernate-mapping>
<class name="VO.EamCompanies" table="EAM_COMPANIES" schema="EAIS_UPDATE">
<id name="companyId" type="java.lang.Long">
为:
<hibernate-mapping>
<class name="com.enstrong.mis.resource.companies.vo.EamCompanies" table="EAM_COMPANIES">
<id name="companyId" type="java.lang.Long">
修改:
<set name="eamCompcontacts" inverse="true">
<key>
<column name="COMPANY_ID" precision="22" scale="0" />
</key>
<one-to-many class="VO.EamCompcontact" />
</set>
</class>
</hibernate-mapping>
为:
<set name="eamCompcontacts" inverse="true">
<key>
<column name="COMPANY_ID" precision="22" scale="0" />
</key>
<one-to-many class="com.enstrong.mis.resource.companies.vo.EamCompcontact" />
</set>
</class>
</hibernate-mapping>
然后把修改后的*.xml文件和*.java文件 拷贝的MyEclipse Web Project 的 src的VO包中;O/R映射就结束;
二、后台框架搭建
1、按框架的目录结构建立4个包:vo、dao、service、actionform(只是查询数据时不需要)、action;
2、vo部分,在第一部分中,已经实现;
3、dao部分,主要实现数据的持久化的操作,通过接口和接口实现(类)模式处理;
4、service 业务逻辑处理层,Service也是控制器层(Action)和模型(VO,DAO)交互的中间桥梁;同时和Action一起来处理业务逻辑;
注意:在创建Service时,要进行Struts和Hibernate的配置:
Spring Service配置:applicationContext-service.xml :
<!-- 公司信息service -->
<bean id="EamCompaniesServiceImp" parent="txProxyTemplate">
<property name="target">
<bean class="com.enstrong.mis.resource.companies.service.EamCompaniesServiceImp">
<property name="companiesDao" ref="companiesDao"></property>
</bean>
</property>
</bean>
<!-- 公司联系人信息service -->
<bean id="EamCompcontactServiceImp" parent="txProxyTemplate">
<property name="target">
<bean class="com.enstrong.mis.resource.companies.service.EamCompcontactServiceImp">
<property name="compcontactDao" ref="compcontactDao"></property>
<property name="companiesDao" ref="companiesDao"></property>
</bean>
</property>
</bean>class="com.enstrong.mis.resource.companies.dao.EamCompcontactImp">
<property name="sessionFactory">
<ref bean="mySessionFactory" />
</property>
</bean>
Hibernate配置:applicationContext-hibernate.xml :
<!-- 公司信息 -->
<bean id="companiesDao" class="com.enstrong.mis.resource.companies.dao.EamCompaniesDaoImp">
<property name="sessionFactory">
<ref bean="mySessionFactory" />
</property>
</bean>
<!-- 公司联系人信息 -->
<bean id="compcontactDao" class="com.enstrong.mis.resource.companies.dao.EamCompcontactImp">
<property name="sessionFactory">
<ref bean="mySessionFactory" />
</property>
</bean>
另外,在Service创建dao对象时要注意get 和 set 方法;
5、ActionForm 可以直接拷贝VO对象,把VO中的复杂数据类型,都改成String类型,同时要注意类的继承发生变化;
public class EamCompaniesForm extends ActionForm implements java.io.Serializable
6、Action是控制器成,与前台JSP交互,也是控制业务流转的关键层;
三、前台JSP开发
1、前台Struts配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<form-beans>
<form-bean name="companyBean" type="com.enstrong.mis.resource.companies.actionform.EamCompaniesForm"></form-bean>
</form-beans>
<action-mappings>
<action name="companyBean" path="/eamCompaniesAction" validate="false" parameter="method" scope="request" type="com.enstrong.mis.resource.companies.action.EamCompaniesAction">
<forward name="forwardMain" path="/pages/resource/companies/main_companies.jsp" />
<forward name="forwardGrid_companies" path="/pages/resource/companies/grid_companies.jsp" />
<forward name="forwardTab_companies" path="/pages/resource/companies/tab_companies.jsp" />
<forward name="forwardTab_compcontact" path="/pages/resource/companies/tab_companies_contact.jsp" />
</action>
</action-mappings>
<message-resources parameter="ApplicationResources" />
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
</plug-in>
</struts-config>
假如上面创建的配置文件的名称是“struts-config-resource.xml”,需要在工程的web.xml中增加 Action servlet 配置
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>
/WEB-INF/struts-config.xml,/WEB-INF/struts-config-sysinit.xml,/WEB-INF/struts-config-ranliao.xml,/WEB-INF/struts-config-sampling.xml,/WEB-INF/struts-config-equipment.xml,/WEB-INF/struts-config-runmanager.xml,
/WEB-INF/struts-config-sampling.xml,/WEB-INF/struts-config-material.xml,/WEB-INF/struts-config-pm-ht.xml,/WEB-INF/struts-config-produce.xml,/WEB-INF/struts-config-hr.xml,
/WEB-INF/struts-config-planmanager.xml, /WEB-INF/struts-config-overhaul.xml,/WEB-INF/struts-config-workflow.xml,/WEB-INF/struts-config-resource.xml
</param-value>主页面DoSearch方法:
function doSearch(page) {
cur_page = (page==undefined)?1:page;
companyName = dojo.byId("companiesName").value;
companyCode = dojo.byId("companiesCode").value;
dojo.io.bind({
url: "<%=request.getContextPath()%>/eamCompaniesAction.do",
encoding: 'UTF-8',
method: 'post',
content: {
method: 'getCompainesListByPage',
cur_page: cur_page,
companyName: companyName,
companyCode: companyCode
},
load: function(type, data, evt) {
resetAll();
//dojo.debug('success!!!!!' );
dojo.widget.byId("main").setContent(data);
//alert(data);
fixdg();
},
error: function(type, error) {
dlgShow('搜索失败!!!!');
},
mimetype: "text/plain"
});
}