xsi="http:
//www.w3.org/2001/XMLSchema-instance"
xmlns="
xmlns:
web="
xsi:
schemaLocation="
id="WebApp_ID"
version="2.5">
--加载所有的配置文件-->
contextConfigLocation
classpath*:
config/spring-*.xml
--配置Spring监听-->
org.springframework.web.context.ContextLoaderListener
--配置字符集-->
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
forceEncoding
true
encodingFilter
/*
--配置SpringMVC-->
student
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath*:
config/spring-mvc.xml
--指定当web应用启动时,装载servlet的次序。
当值为0或正数时,servlet容器先加载;
如果值为负数或者没有设定,那么servlet容器将在web客户首次访问这个servlet时加载它。
-->
1
student
/
--引用js,如果无此配置,则无法对js进行加载-->
default
*.js
第六步:
创建package和java文件,目录如下:
下来就是根据具体的要求编写代码了,现在将详细的代码罗列出来哦
Student.java
packagecom.app.entity;
importjava.io.Serializable;
importjavax.persistence.Column;
importjavax.persistence.Entity;
importjavax.persistence.GeneratedValue;
importjavax.persistence.Id;
importjavax.persistence.Table;
importorg.hibernate.annotations.GenericGenerator;
@Entity
@Table(name="student_info")
publicclassStudentimplementsSerializable{
@Id
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid",strategy="uuid")
@Column(length=32)
privateStringid;
@Column(length=5)
privateStringname;
@Column(length=2)
privateIntegerage;
@Column(length=2)
privateStringsex;
@Column(length=5)
privateStringnum;
publicStringgetId(){
returnid;
}
publicvoidsetId(Stringid){
this.id=id;
}
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicIntegergetAge(){
returnage;
}
publicvoidsetAge(Integerage){
this.age=age;
}
publicStringgetSex(){
returnsex;
}
publicvoidsetSex(Stringsex){
this.sex=sex;
}
publicStringgetNum(){
returnnum;
}
publicvoidsetNum(Stringnum){
this.num=num;
}
}
StudentDAO.java
packagecom.app.dao;
importjava.util.List;
importorg.springframework.stereotype.Repository;
importcom.app.entity.Student;
publicinterfaceStudentDAO{
publicListallStudent(Stringpage);
publicStudentfindById(Stringid);
publicvoidaddStudent(Studentstudent);
publicbooleandeleteStudent(Stringid);
publicbooleanupdateStudent(Studentstudent);
publicListqueryStudent(Studentstudent);
publicintgetPageNum();
}
StudentDAOimpl.java
packagecom.app.dao.impl;
importjava.util.List;
importorg.hibernate.Query;
importorg.hibernate.SessionFactory;
importcom.app.dao.StudentDAO;
importcom.app.entity.Student;
publicclassStudentDAOimplimplementsStudentDAO{
privateSessionFactorysessionFactory;
privateintpageSize=10;
publicvoidsetSessionFactory(SessionFactorysessionFactory){
this.sessionFactory=sessionFactory;
}
publicvoidaddStudent(Studentstudent){
sessionFactory.getCurrentSession().save(student);
}
/**
*获取所有学生
*/
publicListallStudent(Stringpage){
Stringhql="fromStudent";
Queryquery=sessionFactory.getCurrentSession().createQuery(hql);
query.setFirstResult((Integer.parseInt(page)-1)*pageSize);
query.setMaxResults(pageSize);
returnquery.list();
}
/**
*根据id删除学生
*/
publicbooleandeleteStudent(Stringid){
Stringhql="deleteStudentswheres.id=?
";
Queryquery=sessionFactory.getCurrentSession().createQuery(hql);
query.setString(0,id);
return(query.executeUpdate()>0);
}
/**
*根据id查找学生
*/
publicStudentfindById(Stringid){
Stringhql="fromStudentswheres.id=?
"