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

spring+struts2+dwr

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

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

import org.springframework.orm.ibatis.SqlMapClientCallback;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.swj.site.domain.Staff;
import org.swj.site.util.ExcelUtil;

import com.ibatis.sqlmap.client.SqlMapExecutor;

public class StaffDao extends SqlMapClientDaoSupport
{
    private ExcelUtil excelUtil;
    private Staff staff;
    
    public void setStaff(Staff staff)
    {
        this.staff = staff;
    }
    public void setExcelUtil(ExcelUtil excelUtil)
    {
        this.excelUtil = excelUtil;
    }
    
    @SuppressWarnings("unchecked")
    public void insertStaff(File file,int sheetNum,int rowNum,int cellNum){
        
        final List<String> result = excelUtil.readExcel(file,sheetNum,rowNum,cellNum);
        getSqlMapClientTemplate().execute(new SqlMapClientCallback(){
            public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException
            {
                executor.startBatch();
                for(int i=0;i<result.size();i++){
                    String[] strs = result.get(i).split(",");
                    staff.setStaffNo(strs[0]);
                    staff.setStaffName(strs[1]);
                    staff.setStaffDepartment(strs[2]);
                    staff.setStatus(strs[3]);
                    executor.insert("insertStaff",staff);
                }
                executor.executeBatch();
                return null;
            }
        });
    }
    
    public void updateStaff(Staff staff){
        getSqlMapClientTemplate().update("updateStaff",staff);
    }
    
    @SuppressWarnings("unchecked")
    public List<Staff> selectAllStaff(Staff staff){
        return getSqlMapClientTemplate().queryForList("selectStaff",staff);
    }
    
    public Staff selectStaffByNo(Staff staff){
        return (Staff)getSqlMapClientTemplate().queryForObject("selectStaff",staff);
    }
}

package org.swj.site.service;

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

import org.swj.site.dao.StaffDao;
import org.swj.site.domain.Staff;

public class StaffService
{
    private StaffDao staffDao;
    
    public void setStaffDao(StaffDao staffDao)
    {
        this.staffDao = staffDao;
    }
    public void insertStaff(File file,int sheetNum,int rowNum,int cellNum){
        staffDao.insertStaff(file,sheetNum,rowNum,cellNum);
    }
    
    public void updateStaff(Staff staff){
        staffDao.updateStaff(staff);
    }

    public List<Staff> selectAllStaff(Staff staff){
        
        List<Staff> staffList = staffDao.selectAllStaff(staff);
        
        return staffList;
    }
    
    public Staff selectStaffByNo(Staff staff){
        return staffDao.selectStaffByNo(staff);
    }
    
}

package org.swj.site.util;

import org.displaytag.decorator.TableDecorator;
import org.swj.site.domain.Staff;

public class Wrapper extends TableDecorator
{

    public String getLink(){
        StringBuffer htmlStr = new StringBuffer();
        Staff staff = (Staff)getCurrentRowObject();

        htmlStr.append("<a href=\"list.action?staffNo=");
        htmlStr.append(staff.getStaffNo());
        htmlStr.append("&amp;action=renounce\">Renounce</a>");
        return htmlStr.toString();
        
    }
    
}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics