SSH-BOS项目:取派员管理模块

StaffAction:

package com.xushuai.bos.web.action;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.xushuai.bos.entity.Staff;
import com.xushuai.bos.service.StaffService;
import com.xushuai.bos.utils.BOSUtils;
import com.xushuai.bos.utils.PageBean;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

@Controller("staffAction")
@Scope("prototype")
public class StaffAction extends BaseAction {
	
	@Autowired
	@Qualifier("staffService")
	private StaffService staffService;
	public void setStaffService(StaffService staffService) {
		this.staffService = staffService;
	}
	
	//接收分页参数
	private int page;
	private int rows;
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getRows() {
		return rows;
	}
	public void setRows(int rows) {
		this.rows = rows;
	}
	
	//接收要删除的取派员的ID
	private String ids;
	public String getIds() {
		return ids;
	}
	public void setIds(String ids) {
		this.ids = ids;
	}
	
	/**
	 * 新增取派员
	 * @return
	 */
	public String add(){
		staffService.save(model);
		return LIST;
	}
	
	/**
	 * 分页查询取派员
	 * @return
	 * @throws IOException 
	 */
	public String pageQuery() throws IOException{
		//封装离线查询条件
		DetachedCriteria criteria = DetachedCriteria.forClass(Staff.class);
		//创建分页对象
		PageBean pageBean = new PageBean();
		pageBean.setCriteria(criteria);
		pageBean.setCurrentPage(page);
		pageBean.setPageSize(rows);
		
		//调用service#pageQuery(PageBean)
		staffService.pageQuery(pageBean);
		
		HttpServletResponse response = BOSUtils.getResponse();
		response.setContentType("text/json;charset=UTF-8");
		//将PageBean转换为JSON串,返回给页面
		JsonConfig jsonConfig = new JsonConfig();
		//去除不需要返回的值
		jsonConfig.setExcludes(new String[]{"currentPage","pageSize","criteria"});
		//将查询结果转换为json串
		String json = JSONObject.fromObject(pageBean, jsonConfig).toString();
		//返回json数据
		response.getWriter().print(json);
		
		return NONE;
	}
	
	/**
	 * 删除取派员(假删除)
	 * @return
	 */
	public String delete(){
		String[] strings = ids.split(",");
		staffService.delete(strings);
		
		return LIST;
	}
	
	/**
	 * 修改取派员
	 * @return
	 */
	public String edit(){
		staffService.edit(model);
		return LIST;
	}
}

struts.xml配置:





	
		
		
			
			
				
				login
			
			
			
				
				
			
		
		
		
		
		
			/login.jsp
		
		
		
		
			/WEB-INF/pages/{1}/{2}.jsp
		
		
		
		

		
		
			/login.jsp
			/index.jsp
		
		
		
		
			/WEB-INF/pages/base/staff.jsp
		
		
		
		
			/WEB-INF/pages/base/region.jsp
		
	


StaffService:

package com.xushuai.bos.service;

import com.xushuai.bos.entity.Staff;
import com.xushuai.bos.utils.PageBean;


public interface StaffService {
	
	/**
	 * 保存新增取派员
	 * @param model
	 */
	void save(Staff model);

	/**
	 * 分页查询取派员
	 * @param pageBean
	 */
	void pageQuery(PageBean pageBean);

	/**
	 * 删除指定取派员
	 * @param strings
	 */
	void delete(String[] ids);

	/**
	 * 修改取派员
	 * @param model
	 */
	void edit(Staff model);
	
}

StaffServiceImpl:

package com.xushuai.bos.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xushuai.bos.dao.StaffDao;
import com.xushuai.bos.entity.Staff;
import com.xushuai.bos.service.StaffService;
import com.xushuai.bos.utils.PageBean;

@Service("staffService")
@Transactional
public class StaffServiceImpl implements StaffService {
	
	@Autowired
	@Qualifier("staffDao")
	private StaffDao staffDao;
	public void setStaffDao(StaffDao staffDao) {
		this.staffDao = staffDao;
	}


	@Override
	public void save(Staff staff) {
		staffDao.save(staff);
	}


	@Override
	public void pageQuery(PageBean pageBean) {
		staffDao.findByPage(pageBean);
	}


	@Override
	public void delete(String[] ids) {
		for (String id : ids) {
			staffDao.executeUpdate("staff.delete", id);
		}
	}


	@Override
	public void edit(Staff staff) {
		Staff _staff = staffDao.findById(staff.getId());
		//更新页面传递过来的相关字段,切记,不要直接把staff扔到方法参数上。会造成数据的错误
		_staff.setName(staff.getName());
		_staff.setTelephone(staff.getTelephone());
		_staff.setHaspda(staff.getHaspda());
		_staff.setStation(staff.getStation());
		_staff.setStandard(staff.getStandard());
		
		staffDao.update(_staff);
	}

}

StaffDao、StaffDaoImpl:

package com.xushuai.bos.dao;

import com.xushuai.bos.entity.Staff;

public interface StaffDao extends BaseDao {

}

package com.xushuai.bos.dao.impl;

import org.springframework.stereotype.Repository;

import com.xushuai.bos.dao.StaffDao;
import com.xushuai.bos.entity.Staff;

@Repository("staffDao")
public class StaffDaoImpl extends BaseDaoImpl implements StaffDao {
	
}

在Staff.hbm.xml中的hibernate-mapping下配置:

    
    	UPDATE Staff SET deltag = '1' WHERE id = ?
    

页面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




Insert title here






	




	


	
收派员信息
姓名
手机
单位
是否有PDA
取派标准
收派员信息
姓名
手机
单位
是否有PDA
取派标准
 查询条件
取派员编号
姓名
手机
单位
取派标准

遗留:取派员查询

取派员查询(新增代码)

StaffAction(只需修改pageQuery方法):修改后的pageQuery代码如下

	/**
	 * 分页查询取派员
	 * @return
	 * @throws IOException 
	 */
	public String pageQuery() throws IOException{
		//获取离线查询条件
		DetachedCriteria dc = pageBean.getCriteria();
		//健壮性判断
		String name = model.getName();
		String standard = model.getStandard();
		String station = model.getStation();
		String telephone = model.getTelephone();
		//只要输入的条件不为空,将值赋给离线查询对象
		if(StringUtils.isNotBlank(name)){
			dc.add(Restrictions.like("name", "%"+name+"%"));
		}
		if(StringUtils.isNotBlank(standard)){
			dc.add(Restrictions.like("standard", "%"+standard+"%"));
		}
		if(StringUtils.isNotBlank(station)){
			dc.add(Restrictions.eq("station", station));
		}
		if(StringUtils.isNotBlank(telephone)){
			dc.add(Restrictions.like("telephone", "%"+telephone+"%"));
		}
		
		
		//调用service#pageQuery(PageBean)
		staffService.pageQuery(pageBean);
		//将pageBean转换为json字符串回写到页面
		BOSUtils.writerJson(pageBean, new String[]{"currentPage","pageSize","criteria"});
		
		return NONE;
	}

页面修改(为sel的按钮绑定单击事件):

                //查询窗口中,查询按钮
		$("#sel").click(function(){
			//将form中的表单数据转换为json,用于提交
			var params = $("#selStaffForm").serializeJson();
			//提交参数,加载数据,关闭查询窗口
			$("#grid").datagrid('load',params);
			$("#selStaffWindow").window("close");
		});

你可能感兴趣的:(个人成长,实战项目)