package com.csai.action;
import java.util.ArrayList;
import java.util.Map;
import org.hibernate.Query;
import org.hibernate.Session;
import com.csai.POJO.Speciality;
import com.csai.POJO.Student;
import com.csai.db.HibernateUtil;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class MatriAction extends ActionSupport {
private static final long serialVersionUID = 1L;
public String action;
public Integer specialityid;
public String matrino;
public String studentname;
public Integer currentpage=1;
public Long studentid;
@Override
public String execute() throws Exception {
if(studentname!=null&&studentname.length()!=0)
studentname=studentname.trim();
if(action!=null&&action.length()!=0)
action=action.trim();
if(matrino!=null&&matrino.length()!=0)
matrino=matrino.trim();
Session sessionHibernate=HibernateUtil.getSession();
sessionHibernate.beginTransaction();
Map request = (Map)ActionContext.getContext().get("request");
//----如果是要增加一个学生---
if("add".equals(action)){
String hsql="from Student where matriNo=? and studentName=?"+
" and speciality.specialityId=?";
Query query=sessionHibernate.createQuery(hsql);
query.setString(0,matrino);
query.setString(1,studentname);
query.setInteger(2,specialityid);
ArrayList<Student> stuArray =(ArrayList<Student>)query.list();
if(stuArray.size()<=0){//没有此学生
Student stu=new Student();
stu.setMatriNo(matrino);
stu.setStudentName(studentname);
hsql="from Speciality where specialityId="+specialityid;
Query query1=sessionHibernate.createQuery(hsql);
Speciality spec=((ArrayList<Speciality>)query1.list()).get(0);
stu.setSpeciality(spec);
sessionHibernate.save(stu);
}
}
//----如果是要删除一个学生---
if("del".equals(action)){
String hsql="from Student where studentId="+studentid;
Query query=sessionHibernate.createQuery(hsql);
ArrayList<Student> stuArray =(ArrayList<Student>)query.list();
if(stuArray.size()==1)
sessionHibernate.delete(stuArray.get(0));
}
//----如果是要查询数据----
int pagesize=5;//每页记录条数
int pagecount=0;//总页数
int recount=0;//总记录条数
if("select".equals(action)){
String hsql=null;
String hsqlwhere=" where 1=1 ";//where子句
if(studentname!=null&&studentname.length()>=1)
hsqlwhere+=" and s.studentName like '%"+studentname+"%'";
if(specialityid!=null&&specialityid.intValue()!=0)
hsqlwhere+=" and s.speciality.specialityId="+specialityid;
String hsqlcount="select count(*) from Student s "+hsqlwhere;
recount = ((Long)sessionHibernate.createQuery(hsqlcount).uniqueResult()).intValue();
//----得到总页数----
if(recount%pagesize==0)//能整除
pagecount=recount/pagesize;
else//不能整除
pagecount=(int)(recount/pagesize)+1;
hsql="from Student s "+hsqlwhere+" order by s.studentId desc";
System.out.println("****"+hsql);
Query query=sessionHibernate.createQuery(hsql);
query.setFirstResult((currentpage-1)*pagesize);
query.setMaxResults(pagesize);
ArrayList<Student> stuArray =(ArrayList<Student>)query.list();
request.put("stuArray", stuArray);
}
//----查询出专业数据----
String hsql="from Speciality";
Query query=sessionHibernate.createQuery(hsql);
ArrayList<Speciality> specialityArray =(ArrayList<Speciality>)query.list();
request.put("specialityArray", specialityArray);
//----将数据放入request----
request.put("pagesize",pagesize);
request.put("pagecount",pagecount);
request.put("currentpage",currentpage);
request.put("recount",recount);
sessionHibernate.getTransaction().commit();
return SUCCESS;
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public int getSpecialityid() {
return specialityid;
}
public void setSpecialityid(int specialityid) {
this.specialityid = specialityid;
}
public String getMatrino() {
return matrino;
}
public void setMatrino(String matrino) {
this.matrino = matrino;
}
public String getStudentname() {
return studentname;
}
public void setStudentname(String studentname) {
this.studentname = studentname;
}
public int getCurrentpage() {
return currentpage;
}
public void setCurrentpage(int currentpage) {
this.currentpage = currentpage;
}
public long getStudentid() {
return studentid;
}
public void setStudentid(long studentid) {
this.studentid = studentid;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于Struts2+Hibernate4实现报道管理系统
共102个文件
jar:26个
xml:18个
java:17个
3星 · 超过75%的资源 需积分: 9 10 下载量 127 浏览量
2013-12-17
17:17:54
上传
评论 1
收藏 9.68MB ZIP 举报
温馨提示
基于Struts2+Hibernate4实现报道管理系统,包含源代码和sqlserver数据库文件
资源推荐
资源详情
资源评论
收起资源包目录
基于Struts2+Hibernate4实现报道管理系统 (102个子文件)
MatriAction.class 6KB
ClassAdminAction.class 5KB
BedAction.class 5KB
AcceptMoneyAction.class 4KB
AdminUserAction.class 4KB
BedchamberAction.class 3KB
SpecialityAction.class 3KB
ClassAction.class 3KB
ClassViewAction.class 3KB
RegStatusAction.class 3KB
Student.class 3KB
LoginAction.class 2KB
HibernateUtil.class 2KB
Speciality.class 1KB
Bedchamber.class 1KB
ClassTa.class 1KB
AdminUser.class 1004B
.classpath 834B
org.eclipse.wst.common.component 442B
org.eclipse.wst.jsdt.ui.superType.container 49B
banner.html 248B
hibernate-core-4.0.0.CR1.jar 4.01MB
freemarker-2.3.16.jar 860KB
struts2-core-2.2.3.jar 756KB
javassist-3.12.0.GA.jar 618KB
xwork-core-2.2.3.jar 602KB
commons-collections-3.1.jar 546KB
sqljdbc4.jar 525KB
log4j-1.2.16.jar 470KB
antlr-2.7.7.jar 435KB
standard.jar 384KB
dom4j-1.6.1.jar 307KB
commons-lang-2.5.jar 273KB
ognl-3.0.1.jar 224KB
commons-io-2.0.1.jar 156KB
hibernate-jpa-2.0-api-1.0.1.Final.jar 100KB
hibernate-commons-annotations-3.2.0.Final.jar 70KB
jandex-1.0.0.Beta7.jar 69KB
commons-logging-1.1.1.jar 59KB
commons-fileupload-1.2.2.jar 58KB
classmate-0.5.4.jar 57KB
jboss-logging-3.0.0.Beta5.jar 46KB
commons-logging-api-1.1.jar 44KB
slf4j-api-1.5.8.jar 23KB
jstl.jar 20KB
jta-1.1.jar 15KB
slf4j-log4j12-1.5.2.jar 9KB
MatriAction.java 5KB
BedAction.java 3KB
ClassAdminAction.java 3KB
AcceptMoneyAction.java 3KB
AdminUserAction.java 3KB
BedchamberAction.java 2KB
SpecialityAction.java 2KB
ClassAction.java 2KB
LoginAction.java 2KB
ClassViewAction.java 2KB
Student.java 1KB
RegStatusAction.java 1KB
HibernateUtil.java 954B
Bedchamber.java 681B
Speciality.java 675B
AdminUser.java 659B
ClassTa.java 607B
.jsdtscope 503B
matri.jsp 4KB
bedchamber.jsp 3KB
left.jsp 3KB
acceptmoney.jsp 3KB
classview.jsp 3KB
regstatus.jsp 2KB
adminuser.jsp 2KB
classadmin.jsp 2KB
specialityadmin.jsp 1KB
bedchamber.jsp 1KB
class.jsp 1KB
login.jsp 915B
index.jsp 743B
MANIFEST.MF 39B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.jdt.core.prefs 395B
.project 1KB
struts.properties 45B
struts.properties 45B
struts.xml 2KB
struts.xml 2KB
hibernate.cfg.xml 1KB
hibernate.cfg.xml 1KB
Student.hbm.xml 1KB
Student.hbm.xml 1KB
web.xml 994B
Bedchamber.hbm.xml 685B
Speciality.hbm.xml 685B
Speciality.hbm.xml 685B
Bedchamber.hbm.xml 685B
ClassTa.hbm.xml 671B
ClassTa.hbm.xml 671B
LoginAction-validation.xml 614B
LoginAction-validation.xml 614B
AdminUser.hbm.xml 554B
共 102 条
- 1
- 2
资源评论
- Jekris2014-10-26很不错,看得也很明白
- 蛋蛋の忧伤2015-04-24写的太简单,并且struts 框架有的太差了,
小海低
- 粉丝: 0
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功