dwr使用实例

来源:百度文库 编辑:神马文学网 时间:2024/06/13 09:40:38
开发环境:eclipse3.1.2  myeclipse4.1.1   Tomcat5.0.28   Mysql5.0
dwr类包版本是1.1
步骤一:配置web.xml



action
org.apache.struts.action.ActionServlet

config
/WEB-INF/struts-config.xml


debug
3


detail
3

0


action
*.do


dwr-invoker
uk.ltd.getahead.dwr.DWRServlet

debug
true



dwr-invoker
/dwr/*


contextConfigLocation
/WEB-INF/applicationContext.xml



org.springframework.web.context.ContextLoaderListener


EncodingFilter
org.springframework.web.filter.CharacterEncodingFilter

encoding
`
UTF-8



EncodingFilter
/*


404
/404.jsp


500
/500.jsp


/WEB-INF/struts-bean
/WEB-INF/tld/struts-bean.tld


/WEB-INF/struts-logic
/WEB-INF/tld/struts-logic.tld


/WEB-INF/struts-html
/WEB-INF/tld/struts-html.tld


/WEB-INF/struts-tiles
/WEB-INF/tld/struts-tiles.tld


/WEB-INF/ntu
/WEB-INF/tld/ntu.tld


二:spring中注入相关service





三:AjaxTestServiceImp代码
public class AjaxTestServiceImp implements IAjaxTestService {
private ICommonDAO commonDAO;
public void setCommonDAO(ICommonDAO commonDAO) {
this.commonDAO = commonDAO;
}
public List getEmployeeById(String deptid) {
DetachedCriteria detachedCriteria=DetachedCriteria.forClass(Employee.class);
detachedCriteria.setFetchMode(Employee.PROP_DEPTID,FetchMode.JOIN);
detachedCriteria.add(Restrictions.eq(Employee.PROP_DEPTID+".id",deptid));
List result=commonDAO.findByCriteria(detachedCriteria);
return result;
}
}
四:dwr.xml配置












五:jsp页面




请选择


职工和部门是多对一关系,例子简单,不详细叙述了
dwr中spring和hibernate的配置相关帮助文档:
http://getahead.ltd.uk/dwr/server/spring
http://getahead.ltd.uk/dwr/server/hibernate
dept.hbm.xml代码如下:

name="Dept"
table="dept"
>
false
name="id"
type="string"
column="id"
>


name="deptname"
column="deptname"
type="string"
not-null="true"
length="12"
/>
name="creattime"
column="creattime"
type="java.lang.Long"
not-null="false"
length="20"
/>


employee.hbm.xml代码如下:

name="Employee"
table="employee"
>
false
name="id"
type="string"
column="Id"
>


name="username"
column="username"
type="string"
not-null="true"
length="20"
/>
name="password"
column="password"
type="string"
not-null="false"
length="20"
/>
name="truename"
column="truename"
type="string"
not-null="false"
length="11"
/>
name="sex"
column="sex"
type="string"
not-null="false"
length="2"
/>
name="intro"
column="intro"
type="string"
not-null="false"
/>
name="deptid"
column="deptid"
class="Dept"
not-null="true"
>



用hibernate同步插件可以快速生成po