📄 deptaction.java
字号:
package com.wygl.xtgl.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.condition.DeptCondition;
import com.wygl.xtgl.domain.Department;
import com.wygl.xtgl.service.DeptService;
public class DeptAction extends AbstractAction implements ModelDriven {
private List DepartmentList;
private DeptService deptService;//服务
private DeptCondition condition;
private Department dept = new Department();//对象
private List selectedDepartmentIds=new XWorkList(String.class);
protected void initModel() throws Exception { }
public Object getModel(){
try{
condition = (DeptCondition) get("condition");
}catch (Exception e){
condition = new DeptCondition();
}
if(condition == null){
condition = new DeptCondition();
}
return condition;
}
/**初始化服务*/
public void initService() {
if(deptService == null){
deptService = (DeptService) this.getServiceBean("deptService");
}
}
public String query() throws Exception {
try{
initService();
DepartmentList = deptService.queryList();//查询结果集
dept = new Department();
return "query";
}catch (HibernateException e) {
e.printStackTrace();
return ERROR;
}
}
/**查询具体对象信息*/
public String queryById() throws Exception{
try{
initService();
if (condition.getDwdm() != null && !condition.getDwdm().equals("")){
dept = (Department)deptService.queryById(condition.getDwdm());//从数据库中查出此修改对象
}else{
dept = new Department();
}
DepartmentList = deptService.queryList();//查询结果集
return "queryById";
}catch (HibernateException e) {
e.printStackTrace();
return ERROR;
}
}
/**保存对象*/
public String save() throws Exception{
try{
initService();
String rtn = deptService.save(dept);
condition.setDwdm(dept.getDwdm());
if (rtn.equals("false")){
this.addActionError("输入的部门已存在,请重新输入!");
return ERROR;
}else if (rtn.equals("error")){
this.addActionError("保存失败!");
return ERROR;
}
return "queryById";
}catch (HibernateException e) {
e.printStackTrace();
return ERROR;
}
}
/**删除对象*/
public String delete() throws Exception {
try{
initService();
if(deptService.delete(selectedDepartmentIds).equals("false")){
this.addActionError("有人任职于该部门不能删除!");
return ERROR;
}
return "delete";
}catch (HibernateException e) {
e.printStackTrace();
return ERROR;
}
}
public List getDepartmentList() {
return DepartmentList;
}
public void setDepartmentList(List departmentList) {
DepartmentList = departmentList;
}
public Department getDept() {
return dept;
}
public void setDept(Department dept) {
this.dept = dept;
}
public DeptService getDeptService() {
return deptService;
}
public void setDeptService(DeptService deptService) {
this.deptService = deptService;
}
public List getSelectedDepartmentIds() {
return selectedDepartmentIds;
}
public void setSelectedDepartmentIds(List selectedDepartmentIds) {
this.selectedDepartmentIds = selectedDepartmentIds;
}
public DeptCondition getCondition() {
return condition;
}
public void setCondition(DeptCondition condition) {
this.condition = condition;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -