SSH Sprong配置 Action 中应用的接口

SSH Sprong配置 Action 中应用的接口,bean中配置class属性应为Action中国你调用接口的实现类:

例如:

 接口:

   //----------------------------------

package com.action.service;

import java.io.IOException;
import java.util.List;

public interface WorkService {
 public void WorkZipService(String newpath,String cid,String urlfilename,String zipname,String zippwd)  throws Exception ;
 public boolean  WorkMapCopyService(String oldpath,List<String> sattachmentname,String newp,String cid,List<String> nname) throws Exception;
}
//--------------------------------

接口实现类:

//--------------------------------------

package com.action.serviceimpl;

import java.io.IOException;
import java.util.List;

import com.action.service.WorkService;
import com.bean.Sattachment;
import com.dao.SattachmentDAO;
import com.util.OneUtil;
import com.util.ThreeUtil;
import com.util.TwoUtil;

public class WorkServiceImple implements WorkService {
 private SattachmentDAO sattachmentDAO;
 public SattachmentDAO getSattachmentDAO() {
  return sattachmentDAO;
 }

 public void setSattachmentDAO(SattachmentDAO sattachmentDAO) {
  this.sattachmentDAO = sattachmentDAO;
 }

 public void WorkZipService(String newpath,String cid, String urlfilename,
   String zipname,String zippwd) throws Exception {
  // TODO Auto-generated method stub
  String pathcid=newpath+"\\"+cid.trim()+"\\";
  new ThreeUtil().creatTex(pathcid.trim()+"\\"+urlfilename,pathcid);//pathcid,urlfilename,
  new TwoUtil().encryptZip(pathcid,newpath+"\\"+zipname,zippwd);
 }

 public boolean WorkMapCopyService(String oldpath,
   List<String> sattachmentname, String newp, String cid,
   List<String> nname) throws Exception {
  System.out.println("WorkMapCopyService ");
      OneUtil oneutil=new OneUtil();
      boolean sn=oneutil.checkMapBeforueZip(oldpath);
   System.out.println("checkMapBeforueZip "+sn);
   if(sn)
   {
    if(nname!=null && nname.size()>0)
    {
     for(int j=0;j<nname.size();j++)
     {
      List<Sattachment> listsattachment=sattachmentDAO.findAllByNodeName(nname.get(j));
      if(listsattachment!=null && listsattachment.size()>0)
      {
       for(int k=0;k<listsattachment.size();k++)
       {
        Sattachment sattachment=listsattachment.get(k);
        System.out.println("sattachment.getName() "+sattachment.getName());
        if(sattachment.getName()!=null && !sattachment.getName().equals(""))
        {
         sattachmentname.add(sattachment.getName());
        }
       }
      }
     }
    }
    oneutil.copyMap(sattachmentname,oldpath, newp, cid);
    return true;
   }
   return false;
 }

}

//---------------------------------------

Action:

//-------------------------------------------

 

package com.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.action.service.WorkService;
import com.bean.Node;
import com.bean.Sattachment;
import com.dao.CourseDAO;
import com.dao.NodeDAO;
import com.dao.SattachmentDAO;
import com.opensymphony.xwork2.ActionSupport;
import com.util.OneUtil;
import com.util.ThreeUtil;
import com.util.TwoUtil;

public class WorkAction extends ActionSupport {
 private WorkService workService;

 public WorkService getWorkService() {
  return workService;
 }

 public void setWorkService(WorkService workService) {
  this.workService = workService;
 }

 public String workCrouse() throws IOException {
  HttpServletRequest request = ServletActionContext.getRequest();
  OneUtil oneutil = new OneUtil();
  String cid = request.getParameter("cid");
  String oldpath = request.getRealPath("Uploadfiles");
  String newp = request.getRealPath("czip");
  List<Node> node = new ArrayList<Node>();
  List<String> nid = new ArrayList<String>();
  List<String> nname = new ArrayList<String>();
  List<String> sattachmentname=new ArrayList<String>();
  String msg="";
  boolean sign=true;
  
  if(workService.WorkCheckStr(cid))
  {
   try
   {
  node = workService.WorkGetNodeByCid(cid);
  for (int i = 0; i < node.size(); i++) {
   Node n = node.get(i);
   if (n.getCourseid() != null) {
    nid.add(n.getId().toString());
    if(n.getName()!=null && !n.getName().equals(""))
    {
     nname.add(n.getName().trim());
    }
   }
  }
  sign = workService.WorkCheckCid(newp, cid);
  if (sign) {
       workService.WorkeCopyCouseMesgge(oldpath, newp, cid, nid);
    workService.WorkMapCopyService(oldpath, sattachmentname, newp, cid, nname);
       sign = workService.WorkCheckCidBeforueZip(newp,cid);
    if(sign)
    {
    workService.WorkZipService(newp,cid.trim(), "url.txt", cid.trim()+".zip", "12345");
        msg="压缩成功!";
    }else
    {
     msg="该课程没有资源信息!";
    }
  }
  else
  {
   workService.WorkCreaCidFoloder(newp, cid);
   workService.WorkeCopyCouseMesgge(oldpath, newp, cid, nid);
   workService.WorkMapCopyService(oldpath, sattachmentname, newp, cid, nname);
   sign = workService.WorkCheckCidBeforueZip(newp,cid);
   if(sign)
   {
    workService.WorkZipService(newp,cid.trim(), "url.txt", cid.trim()+".zip", "12345");
   msg="压缩成功!";
   }
   else
   {
    msg="该课程没有资源信息!";
   }
  }

   }
   catch(Exception e)
   {
    msg="该课程没有章节信息!";
    node=new ArrayList<Node>();
   }
  }
  else
  {
   msg="传入参数错误!";
  }
   request.setAttribute("msg",msg);
  return SUCCESS;
 }
}

//----------------------------------------

spring xml:

//-------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

............................省略
<bean id="SattachmentDAO" class="com.dao.SattachmentDAO">
  <property name="sessionFactory">
   <ref bean="sessionFactory" />
  </property>
 </bean>

 <bean id="WorkService" class="com.action.serviceimpl.WorkServiceImple">
  <property name="sattachmentDAO">
   <ref bean="SattachmentDAO"/>
  </property>
 </bean>

 <bean id="workAction" class="com.action.WorkAction">
  <property name="workService">
   <ref bean="WorkService"/>
  </property>
 </bean>


</beans>

//-------------------------------------------

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

spjhandsomeman

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值