📄 addemployeesform.java
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.liu.ems.struts.form;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.util.LabelValueBean;
import org.apache.struts.validator.ValidatorForm;
import org.hibernate.Session;
import com.liu.ems.hibernate.Employees;
import com.liu.ems.hibernate.Roles;
import com.liu.ems.hibernate.Departments;
import com.liu.ems.hibernate.HibernateSessionFactory;
/**
* MyEclipse Struts
* Creation date: 11-21-2007
*
* XDoclet definition:
* @struts.form name="addEmployeesForm"
*/
public class AddEmployeesForm extends ValidatorForm {
/*
* Generated fields
*/
/** sex property */
private String sex;
/** age property */
private int age;
/** empname property */
private String empname;
/** roleids property */
private String[] roleids;
/** hiredate property */
private String hiredate;
/** note property */
private String note;
/** depid property */
private String depid;
/** empid property */
private String empid;
public void toThis(Employees emp)
{
this.empid=emp.getEmpid().toString();
this.empname=emp.getEmpName();
this.age=emp.getAge();
this.sex=emp.getSex();
this.hiredate=emp.getHireDate().toString();
this.depid=emp.getDepartments().getDepid().toString();
this.roleids=emp.getRoleids().split(";");
this.note=emp.getNote();
System.out.println("名字"+this.empname);
}
/**
* 查询部门(Departments)表,取出所有对象
* @return
*/
public List<LabelValueBean> getDepartments()
{
List list=new ArrayList<LabelValueBean>();
Session ses=null;
try {
ses=HibernateSessionFactory.getSession();
String hql="from Departments";
List<Departments> list2= ses.createQuery(hql).list();
for(Departments dep:list2){
list.add(new LabelValueBean(dep.getDepname(),dep.getDepid().toString()));
//System.out.println(dep.getDepid());
}
} catch (Exception e) {
e.printStackTrace();
}finally{
HibernateSessionFactory.closeSession();
}
return list;
}
/**
* 查询角色(Roles)表,取出所有角色对象
* @return
*/
public List getRoles()
{
List list=new ArrayList<LabelValueBean>();
Session ses=null;
try {
ses=HibernateSessionFactory.getSession();
String hql="from Roles";
List<Roles> list2= ses.createQuery(hql).list();
for(Roles role:list2){
list.add(new LabelValueBean(role.getRolename(),role.getRoleid().toString()));
//System.out.println(dep.getDepid());
}
} catch (Exception e) {
e.printStackTrace();
}finally{
HibernateSessionFactory.closeSession();
}
return list;
}
/*
* Generated Methods
*/
/**
* Method validate
* @param mapping
* @param request
* @return ActionErrors
*/
// public ActionErrors validate(ActionMapping mapping,
// HttpServletRequest request) {
// // TODO Auto-generated method stub
// //创建一个错误集合对象
//// ActionErrors errors=new ActionErrors();
////
//// if(empname==null || "".equals(empname) ){
//// errors.add("empname",new ActionError("error.empnmae.null"));
//// }
////
//// if(age==0 || "".equals(age)){
//// errors.add("age",new ActionError("error.age.null"));
////
//// }
//// if(sex==null || "".equals(sex)){
////
//// errors.add("sex",new ActionError("error.sex.null"));
//// }
//// if(hiredate==null || "".equals(hiredate)){
////
//// errors.add("hiredate",new ActionError("error.hiredate.null"));
//// }
//// if(roleids==null || "".equals(roleids)){
////
//// errors.add("roleids",new ActionError("error.roleids.null"));
//// }
//// return errors;
// return null;
// }
/**
* Method reset
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
}
/**
* Returns the sex.
* @return String
*/
public String getSex() {
return sex;
}
/**
* Set the sex.
* @param sex The sex to set
*/
public void setSex(String sex) {
this.sex = sex;
}
/**
* Returns the age.
* @return int
*/
public int getAge() {
return age;
}
/**
* Set the age.
* @param age The age to set
*/
public void setAge(int age) {
this.age = age;
}
/**
* Returns the empname.
* @return String
*/
public String getEmpname() {
return empname;
}
/**
* Set the empname.
* @param empname The empname to set
*/
public void setEmpname(String empname) {
this.empname = empname;
}
/**
* Returns the roleids.
* @return String
*/
public String[] getRoleids() {
return roleids;
}
/**
* Set the roleids.
* @param roleids The roleids to set
*/
public void setRoleids(String[] roleids) {
this.roleids = roleids;
}
/**
* Returns the hiredate.
* @return Date
*/
/**
* Returns the note.
* @return String
*/
public String getNote() {
return note;
}
/**
* Set the note.
* @param note The note to set
*/
public void setNote(String note) {
this.note = note;
}
/**
* Returns the depid.
* @return String
*/
public String getDepid() {
return depid;
}
/**
* Set the depid.
* @param depid The depid to set
*/
public void setDepid(String depid) {
this.depid = depid;
}
/**
* Returns the empid.
* @return String
*/
public String getEmpid() {
return empid;
}
/**
* Set the empid.
* @param empid The empid to set
*/
public void setEmpid(String empid) {
this.empid = empid;
}
public String getHiredate() {
return hiredate;
}
public void setHiredate(String hiredate) {
this.hiredate = hiredate;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -