Skip to content

Commit faa06f7

Browse files
committed
学生修改操作完成
1 parent 03eb3da commit faa06f7

File tree

9 files changed

+206
-21
lines changed

9 files changed

+206
-21
lines changed

imoocSSHStudentManagementSystem/WebRoot/jsp/index.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
<%
33
String path = request.getContextPath();
44
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
5-
response.sendRedirect(path+"/users/Users_login.jsp");
5+
response.sendRedirect(path+"/jsp/users/Users_login.jsp");
66
%>

imoocSSHStudentManagementSystem/WebRoot/jsp/students/Students_query_success.jsp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
77
<!DOCTYPE html>
88
<html>
99
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
10-
<link rel="stylesheet" type="text/css" href="../css/default.css" />
10+
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/default.css" />
1111
<style type="text/css">
1212
* {
1313
background: none repeat scroll 0 0 transparent;
@@ -80,13 +80,13 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
8080
<div id="navi">
8181
<div id='naviDiv'>
8282
<span><img src="../images/arror.gif" width="7" height="11" border="0" alt=""></span>&nbsp;学生管理<span>&nbsp;
83-
<span><img src="../images/arror.gif" width="7" height="11" border="0" alt=""></span>&nbsp;<a href="<%=path%>/students/Students_query.action">学生列表</a><span>&nbsp;
83+
<span><img src="../images/arror.gif" width="7" height="11" border="0" alt=""></span>&nbsp;<a href="<%=path%>/jsp/students/Students_query.action">学生列表</a><span>&nbsp;
8484
</div>
8585
</div>
8686
<div id="tips">
8787
<div id="buttonGroup">
8888
<div class="button" onmouseout="this.style.backgroundColor='';this.style.fontWeight='normal'" onmouseover="this.style.backgroundColor='#77D1F6';this.style.fontWeight='bold'">
89-
<a href="<%=path%>/students/Students_add.jsp">添加学生</a>
89+
<a href="<%=path%>/jsp/students/Students_add.jsp">添加学生</a>
9090
</div>
9191
<div class="button" onmouseout="this.style.backgroundColor='';this.style.fontWeight='normal'" onmouseover="this.style.backgroundColor='#77D1F6';this.style.fontWeight='bold'">
9292
<a>查找学生</a>

imoocSSHStudentManagementSystem/WebRoot/jsp/tree.jsp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,21 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
88
<head>
99
<title>导航树</title>
1010
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
11-
<style type="text/css">@import url('components/dtree/dtree.css');</style>
12-
<script type="text/javascript">var dtreeIconBasePath = "components/dtree";</script>
13-
<script type="text/javascript" src="components/dtree/dtree.js"></script>
11+
<style type="text/css">@import url('${pageContext.request.contextPath}/components/dtree/dtree.css');</style>
12+
<script type="text/javascript">var dtreeIconBasePath = "${pageContext.request.contextPath}/components/dtree";</script>
13+
<script type="text/javascript" src="${pageContext.request.contextPath}/components/dtree/dtree.js"></script>
1414
</head>
1515
<body>
1616
<script type="text/javascript">
1717
var treeMenu = [
1818
{ level:1, name:"学生管理"},
19-
{ level:2, name:"学生列表", ico:"images/icon_default.gif",link:"students/Students_query.action"},
20-
{ level:1, name:"教师管理"},
21-
{ level:2, name:"教师列表", ico:"images/icon_default.gif",link:"role_list.html"},
19+
{ level:2, name:"学生列表", ico:"${pageContext.request.contextPath}/images/icon_default.gif",link:"Students_query.action"},
20+
{ level:2, name:"教师列表", ico:"${pageContext.request.contextPath}/images/icon_default.gif",link:"role_list.html"},
2221
{ level:1, name:"信息管理"},
23-
{ level:2, name:"新闻管理", ico:"images/icon_default.gif",link:"news_list.html"},
24-
{ level:2, name:"公告管理", ico:"images/icon_default.gif",link:"bulletin_list.html"},
25-
{ level:1, name:"系统邮件", ico:"images/icon_default.gif"},
26-
{ level:1, name:"网络文件", ico:"images/icon_default.gif",link:"complaint_list.html"}
22+
{ level:2, name:"新闻管理", ico:"${pageContext.request.contextPath}/images/icon_default.gif",link:"news_list.html"},
23+
{ level:2, name:"公告管理", ico:"${pageContext.request.contextPath}/images/icon_default.gif",link:"bulletin_list.html"},
24+
{ level:1, name:"系统邮件", ico:"${pageContext.request.contextPath}/images/icon_default.gif"},
25+
{ level:1, name:"网络文件", ico:"${pageContext.request.contextPath}/images/icon_default.gif",link:"complaint_list.html"}
2726
];
2827
</script>
2928
<style>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.southeast.iLoveMasami.action;
2+
3+
import java.util.List;
4+
5+
import com.southeast.iLoveMasami.entity.Students;
6+
import com.southeast.iLoveMasami.service.StudentsDao;
7+
import com.southeast.iLoveMasami.serviceimpl.StudentsDaoImpl;
8+
9+
/**
10+
* 学生的动作类
11+
* @author iLoveMasami
12+
* @date 2018年1月11日 下午1:35:38
13+
*/
14+
public class StudentsAction extends SuperAction{
15+
16+
private static final long serialVersionUID = 1L;
17+
18+
//查询所有学生
19+
public String query()
20+
{
21+
StudentsDao sdao = new StudentsDaoImpl();
22+
List<Students> list = sdao.queryAllStudents();
23+
//放进session中
24+
if(list!=null&&list.size()>0)
25+
{
26+
session.setAttribute("students_list", list);
27+
}
28+
return "query_success";
29+
}
30+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.southeast.iLoveMasami.service;
2+
3+
import java.util.List;
4+
5+
import com.southeast.iLoveMasami.entity.Students;
6+
7+
/**
8+
* 学生的业务逻辑接口
9+
*
10+
* @author iLoveMasami
11+
* @date 2018年1月11日 上午11:55:46
12+
*/
13+
public interface StudentsDao {
14+
// 查询所有学生
15+
public List<Students> queryAllStudents();
16+
17+
// 根据学生编号查询学生资料
18+
public Students queryStudentsBySid(String sid);
19+
20+
// 添加学生资料
21+
public boolean addStudents(Students s);
22+
23+
// 修改学生资料
24+
public boolean updateStudents(Students s);
25+
26+
// 删除学生资料
27+
public boolean deleteStudents(String sid);
28+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.southeast.iLoveMasami.serviceimpl;
2+
3+
import java.util.List;
4+
5+
import org.hibernate.Query;
6+
import org.hibernate.Session;
7+
import org.hibernate.Transaction;
8+
9+
import com.southeast.iLoveMasami.db.MyHibernateSessionFactory;
10+
import com.southeast.iLoveMasami.entity.Students;
11+
import com.southeast.iLoveMasami.service.StudentsDao;
12+
/**
13+
* 学生业务逻辑接口实现类
14+
* @author iLoveMasami
15+
* @date 2018年1月11日 下午12:01:17
16+
*/
17+
public class StudentsDaoImpl implements StudentsDao {
18+
19+
@Override
20+
public List<Students> queryAllStudents() {
21+
Transaction tx=null;
22+
List<Students> list=null;
23+
String hql="";
24+
try{
25+
Session session=MyHibernateSessionFactory.getSessionFactory().getCurrentSession();
26+
session.beginTransaction();
27+
hql="from Students";
28+
Query query=session.createQuery(hql);
29+
list=query.list();
30+
//tx.commit();
31+
return list;
32+
}
33+
catch(Exception ex){
34+
ex.printStackTrace();
35+
//tx.commit();
36+
return list;
37+
}
38+
finally{
39+
if(tx!=null)
40+
{
41+
tx = null;
42+
}
43+
}
44+
}
45+
46+
@Override
47+
public Students queryStudentsBySid(String sid) {
48+
49+
return null;
50+
}
51+
52+
@Override
53+
public boolean addStudents(Students s) {
54+
55+
return false;
56+
}
57+
58+
@Override
59+
public boolean updateStudents(Students s) {
60+
61+
return false;
62+
}
63+
64+
@Override
65+
public boolean deleteStudents(String sid) {
66+
67+
return false;
68+
}
69+
70+
}

imoocSSHStudentManagementSystem/src/struts.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@
1212
<result name="login_failure">/jsp/users/Users_login.jsp</result>
1313
<result name="logout_success">/jsp/users/Users_login.jsp</result>
1414
<result name="input">/jsp/users/Users_login.jsp</result>
15-
</action>
16-
17-
15+
</action>
1816
</package>
17+
<package name="students" namespace="/" extends="default">
18+
<action name="*_*" class="com.southeast.iLoveMasami.action.{1}Action" method="{2}">
19+
<result name="query_success">/jsp/students/Students_query_success.jsp</result>
20+
<result name="input">/jsp/students/Students_query_success.jsp</result>
21+
22+
</action>
23+
</package>
24+
1925
</struts>
Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package com.southeast.iLoveMasami.entitytest;
22

3+
import java.util.Date;
4+
35
import org.hibernate.Session;
46
import org.hibernate.SessionFactory;
7+
import org.hibernate.Transaction;
58
import org.hibernate.cfg.Configuration;
69
import org.hibernate.service.ServiceRegistry;
710
import org.hibernate.service.ServiceRegistryBuilder;
811
import org.hibernate.tool.hbm2ddl.SchemaExport;
912
import org.junit.Test;
1013

14+
import com.southeast.iLoveMasami.entity.Students;
15+
1116
public class TestStudents {
1217
@Test
1318
public void testSchemaExport() {
@@ -18,11 +23,37 @@ public void testSchemaExport() {
1823
.buildServiceRegistry();
1924
// 创建sessionFactory
2025
SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
21-
//创建session对象
22-
Session session=sessionFactory.getCurrentSession();
23-
//创建SchemaExport对象
24-
SchemaExport export=new SchemaExport(config);
26+
// 创建session对象
27+
Session session = sessionFactory.getCurrentSession();
28+
// 创建SchemaExport对象
29+
SchemaExport export = new SchemaExport(config);
2530
export.create(true, true);
31+
}
32+
33+
/**
34+
* 添加测试数据
35+
*/
36+
@Test
37+
public void testSaveStudents() {
38+
// 创建配置对象
39+
Configuration config = new Configuration().configure();
40+
// 创建服务注册对象
41+
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties())
42+
.buildServiceRegistry();
43+
// 创建sessionFactory
44+
SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
45+
// 创建session对象
46+
Session session = sessionFactory.getCurrentSession();
47+
//创建事务对象
48+
Transaction tx=session.beginTransaction();
2649

50+
Students s1=new Students("S001","张三丰","男",new Date(),"武当山");
51+
Students s2=new Students("S002","郭靖","男",new Date(),"内蒙");
52+
Students s3=new Students("S003","黄蓉","女",new Date(),"桃花岛");
53+
session.save(s1);
54+
session.save(s2);
55+
session.save(s3);
56+
tx.commit();
57+
sessionFactory.close();
2758
}
2859
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.southeast.iLoveMasami.servicetest;
2+
3+
import java.util.List;
4+
5+
import org.junit.Test;
6+
7+
import com.southeast.iLoveMasami.entity.Students;
8+
import com.southeast.iLoveMasami.service.StudentsDao;
9+
import com.southeast.iLoveMasami.serviceimpl.StudentsDaoImpl;
10+
11+
public class TestStudentsDaoImpl {
12+
@Test
13+
public void testqueryAllStudents(){
14+
StudentsDao sDao = new StudentsDaoImpl();
15+
List<Students> list = sDao.queryAllStudents();
16+
for(Students students : list){
17+
System.out.println(students);
18+
}
19+
}
20+
21+
}

0 commit comments

Comments
 (0)