解决方案 »

  1.   

    public String delete() {
      if (null != this.id) {
       this.employeeManager.deleteEmployee(this.id);
      } else {
       if (ids.length > 0) {
        for (Long id : ids) {
         this.employeeManager.deleteEmployee(id);
        }
       }
      }
      if (this.employeeManager.listEmployee().size() > 0) {
       return SUCCESS;
      } else {
       return INPUT;
      } }3、列表页面:list.jsphttp://blog.csdn.net/cai5/article/details/6565523查看以上内容
      

  2.   

    给你一个思路:
    jsp页面
     <script> 
    function actions() {
    var   d=0;

        for(var   i=0;i <document.myForm.elements.length;i++) 
        { 
            var   e=document.myForm.elements[i]; 
            if(e.type=='checkbox'&& e.checked) 
            { 
            d=1; 
            break; 
            } 
        } 
        if(d==0) 
        { alert("没有选择");
        }else
      {  if(confirm("您确定要删除这些记录吗?")){
     document.myForm.submit();
    }
     }
     }
       </script> 
    <form action="delNewsBatch.action" name="myForm" method="post">
    <a href="javascript:actions()">
    批量删除</a>
     <input type="checkbox" name="id" value="<%=list.get(i).getId() %>">
    </form>
     
    struts2的action方法
    /**
     * 请求delNewsBatch处理函数 ,批量删除新闻
     * @return
     * @throws Exception
     */
     public String delNewsBatch() throws Exception{  String[] arr =(String [])ActionContext.getContext().getParameters().get("id");
     if(arr!=null){
     int[] arrId = new int[arr.length];
     for (int i = 0; i < arr.length; i++) {
     arrId[i] = Integer.parseInt(arr[i]);
     }
     newsService.delNews(arrId);
     }
     return SUCCESS;
    }spring和hibernat我就不写了,传入参数是一个数组,循环删除就ok了,没什么难度了。
      

  3.   

    for循环吧 hibernate是不是有批量操作的方法
      

  4.   

    request.getReusetValues没用过,它也可以获得值?
      

  5.   

    daoImpl:
    jsp:
    在action里面就是获取不到页面传来的ids,不知道哪里出了毛病
      

  6.   

    有个简单的办法。
    1:在Bean中多加一个属性.Integer [] ids;
    2:页面中 <input type="checkbox" name="bean.ids" value="${bean.id}"/>
    3:action中有bean的成员变量,会自动获得你页面上选中的复选框,封装到ids的数组中
    4:把数组编程字符串 str =“1,2,3”
    5:delete ..... where id in (str).
      

  7.   


    hibernate写下呗。。万分感谢
      

  8.   

    spring的service类的方法   public void delNews(int[] arrId)
    {
                newsDao.delNews(arrId); 

    hibernate的dao类方法 /**
      * 根据新闻id,批量删除新闻
      * @param id
      */ 
     public void delNews(int[] id) {       
                for (int i = 0; i < id.length; i++) {
                    int newsid = id[i];
                    News news=getHibernateTemplate()
    .get(News.class , newsid);   
      if(news!=null)
    getHibernateTemplate().delete(news);}
      
                 }
            
         }   代码写的有点乱,马上要放假回家了,自己随便写的几句,你凑合着看把。主要看思路
      

  9.   

    需要循环吗?循环那不是要执行N条SQL呀?执行效率很低的,就一条语句就行了,WHERE ID IN(...)就行了
      

  10.   

    有个问题没明白。怎么在action里获取由jsp传来的值。
    jsp:<input type="checkbox" name="ids" value="${article.id}">
    action:public String del()
    {
         HttpServletRequest quest =  ServletActionContext.getRequest();
         String[] str = request.getParameterValues(ids);
         System.out.println(str);
    }
    这样写的话,想在action输出ids的值,运行之后页面报错:java.util.Hashtable.get(Hashtable.java:334)
      

  11.   


    页面的checkbox的name 你定义好  在action 定义同样的变量名数组来获取生成setter getter例如: 
    <input type="checkbox" name="ids" value="1" >
    <input type="checkbox" name="ids" value="2" >
    <input type="checkbox" name="ids" value="3" >
    action中:
    private int[] ids;  //setter getterservice:
    直接把数组 传递过去
    void deleteAll(int[] ids );dao:
    StringBuffer sb= new StringBuffer();
    for (int i = 0; i < ids.length; i++) {
    if (i != 0) {
    sb.append(",");
    } sb.append(ids[i]);
    }getHibernateTemplate().bulkUpdate("delete from"+反射得到的表名+ "where id in ("+sb.toString()+")");
      

  12.   

    你的ID是varchar2类型还是number类型,是varchar2类型的话会报错的吧,还有获得的字符串最后一个会不会有个逗号没删去
      

  13.   

    session.connection()得到连接直接删除啊
      

  14.   


    org.springframework.orm.hibernate3.HibernateQueryException: unexpected char: '@' [delete from com.pojo.TArticle01 where id in([I@12c7d13)]; nested exception is org.hibernate.QueryException: unexpected char: '@' [delete from com.pojo.TArticle01 where id in([I@12c7d13)]用您这个方法写的报这个错、。好像是要数据类型转换?具体怎么解决
      

  15.   


    action里输出ids的值为[I@12c7d13
      

  16.   

    public void delAll(int[] ids) {

    StringBuffer sb = new StringBuffer();
    for(int i=0;i<ids.length;i++)
    {
    if(i!=0)
    {
    sb.append(",");
    }
    sb.append(ids[i]);
    }
    System.out.println("-------"+ids);
    getHibernateTemplate().bulkUpdate("delete from TArticle01 where id in("+ids+")");
    System.out.println(ids+"=====");

    }
    这是dao的Impl方法。我试着用了splint分割符,还是不行。
      

  17.   

    .....
    你这拼凑完sb 用得却是 ids。
    public void delAll(int[] ids) {StringBuffer sb = new StringBuffer();
    for(int i=0;i<ids.length;i++)
    {
    if(i!=ids.length-1)
    {
    sb.append(",");
    }
    sb.append(ids[i]);
    }
    String sql = "delete from TArticle01 where id in("+sb.toString()+")";
    getHibernateTemplate().bulkUpdate(sql );
    System.out.println("执行的sql为:"+sql );}
      

  18.   


    Hibernate: delete from comp.dbo.t_ARTICLE_01 where ID in (0)
    执行的sql为delete from TArticle01 where id in(0)
    控制台打印出了这两句话,sql为0,没有接收到?
      

  19.   

    1:在Bean中多加一个属性.Integer [] ids;
     2:页面中 <input type="checkbox" name="bean.ids" value="${bean.id}"/>
     3:action中有bean的成员变量,会自动获得你页面上选中的复选框,封装到ids的数组中
    4:把数组编程字符串 str =“1,2,3”
    public void delAll(int[] ids)
     { 
    String str =null;
    for(int i=0;i<ids.length;i++)
    {
    if(i!=ids.length-1){
    str+=",";
    }
    str+=ids[i].toString();
    }
    String sql = "delete from TArticle01 where id in("+str+")";
    getHibernateTemplate().bulkUpdate(sql );
    System.out.println("执行的sql为:"+sql ); 
    }
    借用了xiaozhongmiaoyun 和sd4000784 的思路。
      

  20.   

    是maosijunzi 的,不是xiaozhongmiaoyun的思路哈