1. 程式人生 > >struts值crud 兩個action類

struts值crud 兩個action類

1、定義baseAction,存放結果碼常量,請求、響應、上下文、公用的傳值 2、Struts標籤的使用 s:iterator S:action S:url S:form s:textfield S:select S:radio S:param s:textarea

1、不直接跳頁面,跳子控制器,因為路徑問題和*。action配置
2、修改頁面彈棧的問題,load出的結果作為跟,屬性可以直接取值
3、頁面樣式問題	theme

import java.sql.SQLException;

import com.zking.test.dao.ClazzDAO; import com.zking.test.util.BaseAction;

public class ClazzAction extends BaseAction{

public String execute() {
	try {
		this.result=new ClazzDAO().list();
	} catch (InstantiationException | IllegalAccessException | SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
	
}

}

import java.sql.SQLException;

import com.opensymphony.xwork2.ModelDriven; import com.zking.test.dao.StudentDAO; import com.zking.test.entity.Student; import com.zking.test.util.BaseAction; import com.zking.test.util.PageBean;

public class StudentAction extends BaseAction implements ModelDriven{

private Student student=new Student();
private StudentDAO studentDao=new StudentDAO();
/**
 * 查詢方法
 * @return
 */
public String list() {
	try {
		this.result=studentDao.list(student,null);
	} catch (InstantiationException | IllegalAccessException | SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return LIST;
}




/**
 * 新增方法
 * @return
 */
public String add() {
	try {
		this.studentDao.add(student);
	} catch (InstantiationException | IllegalAccessException | NoSuchFieldException | SecurityException
			| SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return SUCCESS;
}
public String toadd() {
	return ADD;
}

/**
 * 修改方法
 * @return
 */
public String edit() {
	try {
		this.studentDao.edit(student);
	} catch (InstantiationException | IllegalAccessException | NoSuchFieldException | SecurityException
			| SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return SUCCESS;
}
public String toedit() {
	try {
		this.result=this.studentDao.load(student);
	} catch (InstantiationException | IllegalAccessException | SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return EDIT;
}


/**
 * 刪除方法
 * @return
 */
public String delete() {
	try {
		this.studentDao.del(student);
	} catch (InstantiationException | IllegalAccessException | NoSuchFieldException | SecurityException
			| SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} 
	return SUCCESS;
}




@Override
public Student getModel() {
	return student;
}

}