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("&action=renounce\">Renounce</a>");
return htmlStr.toString();
}
}
spring+struts2+dwr
最新推荐文章于 2024-08-16 23:08:28 发布