龙卷风驿站

初生牛犊

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  15 Posts :: 0 Stories :: 8 Comments :: 0 Trackbacks

2006年5月5日 #

开发环境:eclipse3.1.2  myeclipse4.1.1   Tomcat5.0.28   Mysql5.0
dwr类包版本是1.1
步骤一:配置web.xml
 <?xml version="1.0" encoding="UTF-8"?>
<web-app>
    <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</param-value>
        </init-param>
        <init-param>
            <param-name>debug</param-name>
            <param-value>3</param-value>
        </init-param>
        <init-param>
            <param-name>detail</param-name>
            <param-value>3</param-value>
        </init-param>
        <load-on-startup>0</load-on-startup>
    </servlet>


    <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <servlet>
        <servlet-name>dwr-invoker</servlet-name>
        <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>true</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>dwr-invoker</servlet-name>
        <url-pattern>/dwr/*</url-pattern>
    </servlet-mapping>
    
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml
        </param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener> 
     
    <filter>
        <filter-name>EncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            `
            <param-value>UTF-8</param-value>
        </init-param>

    </filter>
    <filter-mapping>
        <filter-name>EncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

      <error-page>
        <error-code>404</error-code>
        <location>/404.jsp</location>
    </error-page>

    <error-page>
        <error-code>500</error-code>
        <location>/500.jsp</location>
    </error-page>

    <taglib>
        <taglib-uri>/WEB-INF/struts-bean</taglib-uri>
        <taglib-location>/WEB-INF/tld/struts-bean.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>/WEB-INF/struts-logic</taglib-uri>
        <taglib-location>/WEB-INF/tld/struts-logic.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>/WEB-INF/struts-html</taglib-uri>
        <taglib-location>/WEB-INF/tld/struts-html.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>/WEB-INF/struts-tiles</taglib-uri>
        <taglib-location>/WEB-INF/tld/struts-tiles.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>/WEB-INF/ntu</taglib-uri>
        <taglib-location>/WEB-INF/tld/ntu.tld</taglib-location>
    </taglib>

</web-app>

二:spring中注入相关service
<bean id="ajaxTestService" class="com.lion.cms.domain.service.AjaxTestServiceImp">
        <property name="commonDAO">
            <ref bean="commonDAO" />
        </property>
    </bean>

三: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配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN" "http://www.getahead.ltd.uk/dwr/dwr10.dtd">

<dwr>
 <allow>
  <create creator="spring" javascript="ajaxTestService">
   <param name="beanName" value="ajaxTestService" />
   <include method="getEmployeeById" />
  </create>
        <convert converter="bean" match="com.lion.cms.domain.pojo.Employee" />
        <param name="exclude" value="com.lion.cms.domain.pojo.Dept"/>
 </allow>
</dwr>

五:jsp页面
<html:select styleId="deptid" property="deptid" onchange="loadEmployList(this.value)">
                <html:optionsCollection name="deptlist" label="deptname" value="id"/>
            </html:select>
            <html:select property="employee" styleId="employee">
            <html:option value="" >请选择</html:option>
            </html:select>    

<script type="text/javascript">
<!--
    // 加载employee下拉列表。
    function loadEmployList(deptid){
        if(deptid==null||deptid==''){
        clearEmployeeSel();
        return;
        }
        ajaxTestService.getEmployeeById(loadEmployListCallback,deptid);
    }
    var loadEmployListCallback=function(items){
        clearEmployeeSel();
        DWRUtil.addOptions("employee",items,"id","truename");
    }
    function clearEmployeeSel(){
        DWRUtil.removeAllOptions("employee");
        DWRUtil.addOptions("employee",[{label:'请选择',value:''}],"value","label");
    }
//-->
</script>


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


dept.hbm.xml代码如下:
<hibernate-mapping package="com.lion.cms.domain.pojo">
 <class
   name="Dept"
  table="dept"
 >
 <meta attribute="sync-DAO">false</meta>
   <id
   name="id"
   type="string"
   column="id"
  >
   <generator class="uuid.hex"/>
  </id>

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


 </class> 
</hibernate-mapping>


employee.hbm.xml代码如下:

<hibernate-mapping package="com.lion.cms.domain.pojo">
 <class
  name="Employee"
  table="employee"
 >
  <meta attribute="sync-DAO">false</meta>
  <id
   name="id"
   type="string"
   column="Id"
  >
   <generator class="uuid.hex"/>
  </id>

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


 </class> 
</hibernate-mapping>

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

 

posted @ 2006-07-05 11:06 龙卷风驿站 阅读(5760) | 评论 (3)编辑 收藏

明天下午系统演示,14号论文答辩,希望早点拿好毕业证和学位证走人。
posted @ 2006-06-01 18:48 龙卷风驿站 阅读(156) | 评论 (0)编辑 收藏

这一个月在公司其他事没做,天天做毕业设计,前几天终于完工了。毕业设计做的是计量局的管理系统,采用struts+spring+hibernate完成,运行良好,遗憾的是业务层没有分离,因为时间紧加上系统不是很大,所以都写在action中了,存在部分代码重写,下次改进,呵呵。
   

    系统js代码写了不少,因为某些功能必须要这样来实现。

    论文写了1w多字了,早日做好,公司还有事要做。

    做项目的过程中得到了公司不少高人的指点,尤其是我师父colky,让我少走了很多弯路,好多东西也更清晰,谢谢他们。
posted @ 2006-05-17 11:01 龙卷风驿站 阅读(283) | 评论 (0)编辑 收藏

嘿嘿,好开心哦,好多人,不知道会不会是同学当中最早的,还有一个多月就正式毕业了,开心ing~

路过的就顶一个吧,你也会很幸福的

posted @ 2006-05-05 18:32 龙卷风驿站 阅读(310) | 评论 (1)编辑 收藏