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;
public Session sessionHibernate;
public Session getSessionHibernate() {
return sessionHibernate;
}
public void setSessionHibernate(Session sessionHibernate) {
this.sessionHibernate = sessionHibernate;
}
@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();
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;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Java Web轻量级开发全体验光盘源码(ch2-ch15) 注明:本资源为原版光盘的完整版。全书共有18章,光盘共115M。由于CSND对文件大小的限制,这里只包含ch16-ch18章的光盘源码以及数据库。剩余的ch2-ch15你可以在本人资源处找到下载。 同时,如果您绝对文件太大不喜欢完整版,您可以在本人资源处下载《Java Web轻量级开发全体验光盘源码(无jar文件)》版本。 绝对源码,不喜勿下,下了勿喷。
资源推荐
资源详情
资源评论
收起资源包目录
Java Web轻量级开发全体验光盘源码(ch16-ch18以及数据库) (314个子文件)
MatriAction.class 6KB
MatriAction.class 6KB
ClassAdminAction.class 5KB
BedAction.class 5KB
ClassAdminAction.class 5KB
BedAction.class 5KB
AcceptMoneyAction.class 4KB
AcceptMoneyAction.class 4KB
AdminUserAction.class 4KB
AdminUserAction.class 4KB
BedchamberAction.class 3KB
SpecialityAction.class 3KB
ClassAction.class 3KB
BedchamberAction.class 3KB
SpecialityAction.class 3KB
ClassAction.class 3KB
RegStatusAction.class 3KB
ClassViewAction.class 3KB
ClassViewAction.class 3KB
LoginAction.class 3KB
RegStatusAction.class 3KB
Student.class 3KB
Student.class 3KB
LoginAction.class 2KB
LoginAction.class 2KB
HibernateUtil.class 2KB
HibernateUtil.class 2KB
HibernateUtil.class 2KB
LoginBusiness.class 1KB
Bedchamber.class 1KB
Speciality.class 1KB
Speciality.class 1KB
Bedchamber.class 1KB
ClassTa.class 1KB
ClassTa.class 1KB
AdminUser.class 1004B
AdminUser.class 1004B
SysUser.class 931B
Student1.class 748B
Student2.class 417B
.classpath 834B
.classpath 834B
.classpath 834B
org.eclipse.wst.common.component 442B
org.eclipse.wst.common.component 442B
org.eclipse.wst.common.component 442B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.container 49B
banner.html 248B
banner.html 248B
hibernate-core-4.0.0.CR1.jar 4.01MB
hibernate-core-4.0.0.CR1.jar 4.01MB
hibernate-core-4.0.0.CR1.jar 4.01MB
freemarker-2.3.16.jar 860KB
freemarker-2.3.16.jar 860KB
freemarker-2.3.16.jar 860KB
struts2-core-2.2.3.jar 756KB
struts2-core-2.2.3.jar 756KB
struts2-core-2.2.3.jar 756KB
org.springframework.context-3.0.5.RELEASE.jar 653KB
org.springframework.context-3.0.5.RELEASE.jar 653KB
javassist-3.12.0.GA.jar 618KB
javassist-3.12.0.GA.jar 618KB
javassist-3.12.0.GA.jar 618KB
xwork-core-2.2.3.jar 602KB
xwork-core-2.2.3.jar 602KB
xwork-core-2.2.3.jar 602KB
commons-collections-3.1.jar 546KB
commons-collections-3.1.jar 546KB
commons-collections-3.1.jar 546KB
org.springframework.beans-3.0.5.RELEASE.jar 542KB
org.springframework.beans-3.0.5.RELEASE.jar 542KB
sqljdbc4.jar 525KB
sqljdbc4.jar 525KB
sqljdbc4.jar 525KB
log4j-1.2.16.jar 470KB
log4j-1.2.16.jar 470KB
log4j-1.2.16.jar 470KB
antlr-2.7.7.jar 435KB
antlr-2.7.7.jar 435KB
antlr-2.7.7.jar 435KB
org.springframework.web.servlet-3.0.5.RELEASE.jar 409KB
org.springframework.web.servlet-3.0.5.RELEASE.jar 409KB
org.springframework.web-3.0.5.RELEASE.jar 386KB
org.springframework.web-3.0.5.RELEASE.jar 386KB
standard.jar 384KB
standard.jar 384KB
standard.jar 384KB
org.springframework.jdbc-3.0.5.RELEASE.jar 377KB
org.springframework.jdbc-3.0.5.RELEASE.jar 377KB
org.springframework.core-3.0.5.RELEASE.jar 373KB
org.springframework.core-3.0.5.RELEASE.jar 373KB
org.springframework.orm-3.0.5.RELEASE.jar 326KB
org.springframework.orm-3.0.5.RELEASE.jar 326KB
org.springframework.aop-3.0.5.RELEASE.jar 314KB
org.springframework.aop-3.0.5.RELEASE.jar 314KB
dom4j-1.6.1.jar 307KB
dom4j-1.6.1.jar 307KB
dom4j-1.6.1.jar 307KB
共 314 条
- 1
- 2
- 3
- 4
yali24
- 粉丝: 5
- 资源: 63
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页