📄 studentcourseaction.java
字号:
package com.tech.action;
import java.net.URLEncoder;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.common.Config;
import com.common.action.BaseAction;
import com.common.dao.DaoHelper;
import com.common.hibernate.IdGenerator;
import com.common.util.PaginationSupport;
import com.tech.model.Studentcourse;
import com.tech.model.query.Column4;
import com.tech.model.query.Option;
import com.tech.service.StudentCourseService;
public class StudentcourseAction extends BaseAction {
private Log log = LogFactory.getLog(StudentcourseAction.class);
private Studentcourse studentCourse;
private List list;
private PaginationSupport page;
private StudentCourseService studentCourseService;
private DaoHelper daoHelper;
private List<Option> studentList;
private List<Option> coursesList;
public Studentcourse getStudentCourse() {
return studentCourse;
}
public void setStudentCourse(Studentcourse studentCourse) {
this.studentCourse = studentCourse;
}
public List getList() {
return list;
}
public PaginationSupport getPage() {
return page;
}
public void setDaoHelper(DaoHelper daoHelper) {
this.daoHelper = daoHelper;
}
public void setStudentCourseService(StudentCourseService studentCourseService) {
this.studentCourseService = studentCourseService;
}
/**
* @return
*/
public String add(){
this.setActionName(Config.ADD);
try {
if (studentCourse == null) {
studentCourse = new Studentcourse();
}
page = new PaginationSupport(getMap());
page.setContextPath(this.getContextPath());
this.setUrlParams(page.getParams());
String sql="";
sql="select t.id {t.value},t.name {t.name} from course t order by t.id asc";
coursesList=daoHelper.findBySQL(sql, "t", Option.class, null, false, -1, -1);
coursesList.add(0,new Option("","请选择课程"));
sql="select t.id {t.value},t.name {t.name} from student t order by t.id asc";
studentList=daoHelper.findBySQL(sql, "t", Option.class, null, false, -1, -1);
studentList.add(0,new Option("","请选择学生"));
return INPUT;
} catch (Exception e) {
log.error("add " + e.toString());
if(e.getMessage() == null){
setErrMessage(e.toString());
} else {
setErrMessage(e.getMessage());
}
return LIST;
}
}
public String remove(){
try {
if (studentCourse == null || studentCourse.getId() == null) {
setErrMessage("修改对象的ID为空!");
return ERROR;
}
studentCourseService.removeEntity(studentCourse);
setActionMessage(Config.DELETE_SUCCESS_MESSAGE);
page = new PaginationSupport(getMap());
page.setContextPath(this.getContextPath());
this.setUrlParams(page.getParams()+"&actionMessage="+URLEncoder.encode(Config.DELETE_SUCCESS_MESSAGE,"GBK"));
return LIST;
} catch (Exception e) {
log.error("remove " + e.toString());
if(e.getMessage() == null){
setErrMessage(e.toString());
} else {
setErrMessage(e.getMessage());
}
return LIST;
}
}
public String save(){
try {
this.setAction(this.ACTION_ADD);
this.setActionName(Config.ADD);
studentCourse.setId(new Long(IdGenerator.getId()));
studentCourseService.saveEntity(studentCourse);
setActionMessage(Config.ADD_SUCCESS_MESSAGE);
page = new PaginationSupport(getMap());
page.setContextPath(this.getContextPath());
this.setUrlParams(page.getParams()+"&actionMessage="+URLEncoder.encode(Config.ADD_SUCCESS_MESSAGE,"GBK"));
return LIST;
} catch (Exception e) {
log.error("save " + e.toString());
if(e.getMessage() == null){
setErrMessage(e.toString());
} else {
setErrMessage(e.getMessage());
}
if(this.getAction().equals(this.ACTION_ADD)){
//当前的操作异常时添加异常
studentCourse.setId(null);
}
return INPUT;
}
}
public String detail(){
try {
setStudentCourse(studentCourseService.getEntity(getStudentCourse().getId()));
try {
getStudentCourse().getId();
} catch (Exception ex) {
throw new Exception("此信息已经不存在,请刷新数据");
}
return INPUT;
} catch (Exception e) {
log.error("detail " + e.toString());
if(e.getMessage() == null){
setErrMessage(e.toString());
} else {
setErrMessage(e.getMessage());
}
return LIST;
}
}
public String list(){
try {
page = new PaginationSupport(getMap());
page.setUrl(this.getUrl());
page.setContextPath(this.getContextPath());
page.setParam("pageSize","15");
this.setUrlParams(page.getParams());
String countSQL="select count(t.id) count FROM studentcourse as t " +
"INNER JOIN course AS p ON t.courseid = p.id " +
"inner join student as s on t.studentid = s.id";
String countAlias="count";
String sql="SELECT t.id {t.id},p.name {t.column1},s.name {t.column2},t.courseid {t.column3},t.studentid {t.column4} FROM studentcourse as t " +
"INNER JOIN course AS p ON t.courseid = p.id " +
"inner join student as s on t.studentid = s.id order by t.id desc";
String sqlAlias="t";
page=daoHelper.findBySQL(page, countSQL, countAlias, sql, sqlAlias,null,Column4.class, false);
list=page.getItems();
this.setRecordCount(page.getTotalCount());
return this.SUCCESS;
} catch (Exception e) {
log.error("list : " + e.toString());
if(e.getMessage() == null){
setErrMessage(e.toString());
} else {
setErrMessage(e.getMessage());
}
return LIST;
}
}
public List<Option> getStudentList() {
return studentList;
}
public List<Option> getCoursesList() {
return coursesList;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -