`
let_wind
  • 浏览: 6373 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

spring+struts2+dwr 2

阅读更多
package org.swj.site.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ExcelUtil
{
    public List<String> readExcel(File excelFile,int sheetNum,int rowNum,int cellNum)
    {
        XSSFWorkbook wb;
        List<String> result = new ArrayList<String>();
        try
        {
            wb = new XSSFWorkbook(new FileInputStream(excelFile));
            XSSFSheet sheet = wb.getSheetAt(sheetNum);
            int totalRows = sheet.getLastRowNum();
            for(int i = rowNum; i <= totalRows; i++) {
                XSSFRow row = sheet.getRow(i);
                if(row == null) {
                    continue;
                }
                int totalCells = row.getLastCellNum();
                System.out.println(totalCells);
                StringBuffer sb = new StringBuffer();
                for(int j=cellNum;j < totalCells;j++){
                    sb.append(row.getCell(j).toString()).append(",");
                }
                result.add(sb.toString());
            }
        }
        catch (FileNotFoundException e)
        {
            e.printStackTrace();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return result;
    }    

}

package org.swj.site.web;

import java.io.File;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.swj.site.domain.Staff;
import org.swj.site.service.StaffService;
import com.opensymphony.xwork2.ActionSupport;

public class StaffAction extends ActionSupport
{
    private static final long serialVersionUID = 1L;

    private File file;
    
    private String sheet;
    
    private String row;
    
    private String cell;
    
    private Staff staff;
    
    private StaffService staffService;
    
    public void setStaff(Staff staff)
    {
        this.staff = staff;
    }
    
    public Staff getStaff()
    {
        return staff;
    }

    public void setStaffService(StaffService staffService)
    {
        this.staffService = staffService;
    }

    public File getFile()
    {
        return file;
    }

    public void setFile(File file)
    {
        this.file = file;
    }
    
    public String getSheet()
    {
        return sheet;
    }

    public void setSheet(String sheet)
    {
        this.sheet = sheet;
    }

    public String getRow()
    {
        return row;
    }

    public void setRow(String row)
    {
        this.row = row;
    }

    public String getCell()
    {
        return cell;
    }

    public void setCell(String cell)
    {
        this.cell = cell;
    }

    public String index() throws Exception
    {
        return SUCCESS;
    }

    public String upload() throws Exception
    {
        if(file == null){
            return INPUT;
        }
        
        int sheetNum = Integer.parseInt(sheet);
        int rowNum = Integer.parseInt(row);
        int cellNum = Integer.parseInt(cell);
        
        staffService.insertStaff(file,sheetNum,rowNum,cellNum);
        
        staff.setStaffNo("");
        staff.setStaffName("");
        staff.setStatus("");
        
        List<Staff> list = staffService.selectAllStaff(staff);
        
        HttpServletRequest request = ServletActionContext.getRequest();
        
        request.setAttribute("staff",list);
        return SUCCESS;
    }
    
    public String list() throws Exception
    {
        HttpServletRequest request = ServletActionContext.getRequest();
        System.out.println("--------"+staff.getStaffNo());
        System.out.println("--------"+staff.getStaffName());
        System.out.println("--------"+staff.getStatus());
        
        String action = request.getParameter("action");
        
        if("renounce".equals(action)){
            String staffNo = request.getParameter("staffNo");
            staff.setStaffNo(staffNo);
            staff.setStatus("none");
            staffService.updateStaff(staff);
            //staff = null;
        }
        
        List<Staff> list = staffService.selectAllStaff(staff);
        
       
        
        request.setAttribute("staff",list);
        return SUCCESS;
    }
    
    public String lottery() throws Exception
    {
        
        return SUCCESS;
    }
    
    
}


<!DOCTYPE struts PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
          "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
	
	<constant name="struts.objectFactory" value="spring"/>
	<constant name="struts.ognl.allowStaticMethodAccess" value="true"/>
	<constant name="struts.i18n.encoding" value="UTF-8"/>
	<constant name="struts.devMode" value="false"/>

	<include file="web-config.xml"></include>

</struts>


<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE sqlMap      
    PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"      
    "http://ibatis.apache.org/dtd/sql-map-2.dtd">

<sqlMap namespace="Staff">

	<typeAlias alias="Staff" type="org.swj.site.domain.Staff"/>

	<resultMap id="staffResult" class="Staff">
		<!-- 
		<result property="staffId" column="STAFFID"/>
		 -->
		<result property="staffNo" column="STAFFNO"/>
		<result property="staffName" column="STAFFNAME"/>
		<result property="staffDepartment" column="STAFFDEPARTMENT"/>
		<result property="status" column="STAFFSTATUS"/>
	</resultMap>

	<parameterMap id="staffParameter" class="Staff">
		<parameter property="staffNo" jdbcType="VARCHAR2"/>
		<parameter property="status" jdbcType="VARCHAR2"/>
	</parameterMap>

	<insert id="insertStaff" parameterClass="Staff">
		INSERT INTO T_STAFF (STAFFNO,STAFFNAME,STAFFDEPARTMENT,STAFFSTATUS) VALUES (#staffNo#,#staffName#,#staffDepartment#,#status#)
	</insert>

	<select id="selectStaff" parameterMap="staffParameter" resultMap="staffResult">
		SELECT STAFFNO,STAFFNAME,STAFFDEPARTMENT,STAFFSTATUS FROM T_STAFF WHERE 1=1 
		<isNotEmpty prepend="AND" property="staffNo">
			STAFFNO = #staffNo#
		</isNotEmpty>
		<isNotEmpty prepend="AND" property="staffName">
			STAFFNAME = #staffName#
		</isNotEmpty>
		<isNotEmpty prepend="AND" property="status">
			STAFFSTATUS = #status#
		</isNotEmpty>
	</select>

	<update id="updateStaff" parameterClass="Staff">
		UPDATE T_STAFF SET STAFFSTATUS = #status# WHERE STAFFNO = #staffNo#
	</update>

</sqlMap>

<!DOCTYPE struts PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
          "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
	
	<package name="default" namespace="/" extends="struts-default">
		
		<action name="index" method="index" class="staffAction">
			<result name="success">page/jsp/index.jsp</result>
		</action>
		
		<action name="upload" method="upload" class="staffAction">
			<interceptor-ref name="fileUpload">  
				<param name="allowedTypes">
					application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel
				</param>
				<param name="maximumSize">10485760</param>
			</interceptor-ref>  
			<interceptor-ref name="defaultStack"></interceptor-ref>
			<result name="input">/page/jsp/fileUpload.jsp</result>
			<result name="success">/page/jsp/display.jsp</result>
		</action>
		
		<action name="list" method="list" class="staffAction">
			<result name="success">/page/jsp/display.jsp</result>
		</action>		
		
		<action name="lottery" method="lottery" class="staffAction">
			<result name="success">/page/jsp/lottery.jsp</result>
		</action>		
	</package>

</struts>


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics