⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 classaction.java

📁 本源码为教学管理信息系统
💻 JAVA
字号:
package com.xm.xjgl.classmanage.action;

import java.util.List;

import net.sf.hibernate.HibernateException;

import com.hibernate.action.AbstractAction;
import com.opensymphony.xwork.ModelDriven;
import com.opensymphony.xwork.util.XWorkList;
import com.wygl.xtgl.service.DeptService;
import com.xm.xjgl.classmanage.condition.ClassCondition;
import com.xm.xjgl.classmanage.domain.ClassEntity;
import com.xm.xjgl.classmanage.service.ClassService;
import com.xm.xjgl.majormanage.service.MajorService;

public class ClassAction extends AbstractAction implements ModelDriven{

	private static final long serialVersionUID = 1L;
	private ClassService classService ;
	private DeptService deptService ;    //用于提取部门列表,放如下拉菜单
	private MajorService majorService ;  //用于提取专业列表
	private ClassCondition condition ;
	private List classList ;             //装载班级集合
	private List deptList ;              //系部集合
	private List majorList ;		     //专业集合
	private ClassEntity classEntity ;
	private String classId ;             //用于查一条记录ID
	private List selectedClass =  new XWorkList(String.class);       //删除ID集合
	

	/**初始化服务*/
	public void initService() {
		if(classService == null){
			classService = (ClassService) this.getServiceBean("classService");	
		}
		if(deptService == null){
			deptService = (DeptService) this.getServiceBean("deptService");	
		}
		if(majorService == null){
			majorService = (MajorService) this.getServiceBean("majorService");	
		}
	}
	
	public Object getModel() {
		try{
		    condition = (ClassCondition) get("condition");
		}catch (Exception e){
		    condition = new ClassCondition();
		}
		if(condition == null){
			condition = new ClassCondition();
		}
		return condition;
	}
	
	/**查询列表信息
	 * @throws Exception */
	public String showList() throws Exception
	{
		try{
			initService();
			classService.setCondition(condition);//传入condition条件
			classService.creatHquery();//构建hql
			condition = (ClassCondition) classService.getCondition();//获得设置完的condition
			classList = classService.queryList();  //查询班级结果集
			deptList = deptService.queryList();    //查询系部结果集
			majorList = majorService.queryList();  //查询专业结果集
			set("condition",condition);
			return "query";
		}catch (HibernateException e) {
			e.printStackTrace();
			return ERROR;
		}
	}
	
	/**转到添加页
	 * @throws Exception */
	public String toAddPage() throws Exception
	{
		initService();
		deptList = deptService.queryList();    //查询系部结果集
		majorList = majorService.queryList();  //查询专业结果集
		return "toAddPage";
	}
	
	/**添加班级信息*/
	public String add()
	{
		initService();
		classService.add(classEntity);
		return "add";
	}
	
	/**根据ID查询实体*/
	public String queryById() throws Exception
	{
		initService();
		deptList = deptService.queryList();    //查询系部结果集
		majorList = majorService.queryList();  //查询专业结果集
		classEntity = (ClassEntity) classService.queryById(classId);
		return "queryById";
	}
	
	/**保存修改后实体
	 * @throws Exception */
	public String save() throws Exception
	{
		initService();
		classService.saveObject(classEntity);
		return "save";
	}
	
	/**批量删除记录*/
	public String delete()
	{
		initService();
		String rtn =classService.delete(selectedClass);
		if(rtn.equals("false")){
			this.addActionError("没有可以删除的信息!");
			return ERROR;
		}else if (rtn.equals("error")){
			this.addActionError("删除失败!");
			return ERROR;
		}
		return "delete";
	}
	
	public ClassService getClassService() {
		return classService;
	}
	public void setClassService(ClassService classService) {
		this.classService = classService;
	}
	public ClassCondition getCondition() {
		return condition;
	}
	public void setCondition(ClassCondition condition) {
		this.condition = condition;
	}
	public List getClassList() {
		return classList;
	}
	public void setClassList(List classList) {
		this.classList = classList;
	}
	public DeptService getDeptService() {
		return deptService;
	}
	public void setDeptService(DeptService deptService) {
		this.deptService = deptService;
	}
	public List getDeptList() {
		return deptList;
	}
	public void setDeptList(List deptList) {
		this.deptList = deptList;
	}
	public List getMajorList() {
		return majorList;
	}
	public void setMajorList(List majorList) {
		this.majorList = majorList;
	}
	public MajorService getMajorService() {
		return majorService;
	}
	public void setMajorService(MajorService majorService) {
		this.majorService = majorService;
	}
	public ClassEntity getClassEntity() {
		return classEntity;
	}
	public void setClassEntity(ClassEntity classEntity) {
		this.classEntity = classEntity;
	}
	public String getClassId() {
		return classId;
	}
	public void setClassId(String classId) {
		this.classId = classId;
	}

	public List getSelectedClass() {
		return selectedClass;
	}

	public void setSelectedClass(List selectedClass) {
		this.selectedClass = selectedClass;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -