studentform.java
来自「java 框架核心技术编程」· Java 代码 · 共 212 行
JAVA
212 行
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package org.lxh.struts.form;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
/**
* MyEclipse Struts Creation date: 06-14-2007
*
* XDoclet definition:
*
* @struts.form name="studentForm"
*/
public class StudentForm extends ActionForm {
/*
* Generated fields
*/
private int type;
/** sex property */
private String sex = "男";
/** age property */
private String age;
/** sid property */
private String sid;
/** name property */
private String name;
/*
* Generated Methods
*/
/**
* Method validate
*
* @param mapping
* @param request
* @return ActionErrors
*/
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
switch (type) {
case 0: {
// type=0:查询全部、模糊查询
break;
}
case 1: {
// type=1:按ID查询、按ID删除 (空或不是数字)
if (sid == null || "".equals(sid)) {
errors.add("sid", new ActionMessage("null.student.sid"));
} else {
if (!sid.matches("\\d*")) {
errors.add("sid", new ActionMessage("err.student.sid"));
}
}
break;
}
case 2: {
// type=2:插入新数据:姓名、年龄(空或不是数字)、性别
if (this.name == null || "".equals(this.name)) {
errors.add("name", new ActionMessage("null.student.name"));
}
if (this.age == null || "".equals(this.age)) {
errors.add("age", new ActionMessage("null.student.age"));
} else {
if (!this.age.matches("\\d*")) {
errors.add("age", new ActionMessage("err.student.age"));
}
}
if (this.sex == null || "".equals(this.sex)) {
errors.add("sex", new ActionMessage("null.student.sex"));
}
break;
}
case 3: {
// type=3:更新数据:ID、姓名、年龄(空或不是数字)、性别
if (sid == null || "".equals(sid)) {
errors.add("sid", new ActionMessage("null.student.sid"));
} else {
if (!sid.matches("\\d*")) {
errors.add("sid", new ActionMessage("err.student.sid"));
}
}
if (this.name == null || "".equals(this.name)) {
errors.add("name", new ActionMessage("null.student.name"));
}
if (this.age == null || "".equals(this.age)) {
errors.add("age", new ActionMessage("null.student.age"));
} else {
if (!this.age.matches("\\d*")) {
errors.add("age", new ActionMessage("err.student.age"));
}
}
if (this.sex == null || "".equals(this.sex)) {
errors.add("sex", new ActionMessage("null.student.sex"));
}
break;
}
default: {
// 表示未知操作
errors.add("unknow", new ActionMessage("err.unknow"));
break;
}
}
return errors;
}
/**
* 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 String
*/
public String getAge() {
return age;
}
/**
* Set the age.
*
* @param age
* The age to set
*/
public void setAge(String age) {
this.age = age;
}
/**
* Returns the sid.
*
* @return String
*/
public String getSid() {
return sid;
}
/**
* Set the sid.
*
* @param sid
* The sid to set
*/
public void setSid(String sid) {
this.sid = sid;
}
/**
* Returns the name.
*
* @return String
*/
public String getName() {
return name;
}
/**
* Set the name.
*
* @param name
* The name to set
*/
public void setName(String name) {
this.name = name;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?