初学ssh框架整合小项目--老师学生成绩管理系统

前天学习了关于三个框架的整合,主要spring-hibernate-struts1,因为没学struts2所以暂时是用1做的

一个很简单的项目---老师学生成绩管理系统

先说三个框架的整合:

1.导入三个框架的jar包;

2.拷贝hibernate.cfg.xml文件到SRC目录下,拷贝spring的配置文件applicationContext.xml和struts1的配置文件放入到WEB-INF目录下 <listener>

3.在web.xml文件里加入下面这个监听器

 

  <listener>
  	<listener-class>
              org.springframework.web.context.ContextLoaderListener
        </listener-class>
  </listener>

 

 下面是我的两个spring配置文件的

这个是applicationContext_dao_service_action导入到applicationContext中

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<beans>
	<bean name="/login" class="com.aowin.action.LoginAction">
		<property name="studentService" ref="studentService"></property>
		<property name="sysuserService" ref="sysuserService"></property>
		<property name="scoreService" ref="scoreService"></property>
	</bean>
	
	<bean id="scoreDAO" class="com.aowin.dao.imp.ScoreDAO">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	
	<bean id="studentDAO" class="com.aowin.dao.imp.StudentDAO">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	
	<bean id="sysuserDAO" class="com.aowin.dao.imp.SysuserDAO">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	
	<bean id="scoreService" class="com.aowin.service.ScoreService">
		<property name="scoreDAO" ref="scoreDAO"></property>
	</bean>
	
	<bean id="studentService" class="com.aowin.service.StudentService">
		<property name="studentDAO" ref="studentDAO"></property>
	</bean>
	
	<bean id="sysuserService" class="com.aowin.service.SysuserService">
		<property name="sysuserDAO" ref="sysuserDAO"></property>
	</bean>
</beans>

 下面是applicationContext

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<beans>
	<import resource="applicationContext_dao_service_action.xml"/>
	
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
	</bean>
	
	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	
	<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
		<property name="transactionManager" ref="transactionManager"></property>
		<property name="transactionAttributes">
			<props>
				<prop key="*add*">PROPAGATION_REQUIRED</prop>
				<prop key="*delete*">PROPAGATION_REQUIRED</prop>
				<prop key="*update*">PROPAGATION_REQUIRED</prop>
				<prop key="*get*">readOnly</prop>
			</props>
		</property>
	</bean>
	
	<bean id="autoProxty" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
		<property name="beanNames" value="*Service"></property>
		<property name="interceptorNames" value="transactionInterceptor"></property>
	</bean>
</beans>

 model类和映射的文件包括hibernate的配置文件都可以自动生成还可以用DB反向生成,这里就不放配置文件了。

注:在struts1中的配置文件路径后的type应该是

 

  <action path="/login" type="org.springframework.web.struts.DelegatingActionProxy"parameter="action">

  <forward name="success" path="/welcome.jsp"></forward>

  <forward name="fail" path="/index.jsp"></forward>

  </action>

接下来就是编写业务的代码:service主要是对业务的逻辑处理  dao层主要处理数据库 比较简单

主要还是action中

 


import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.aowin.model.Score;
import com.aowin.model.Student;
import com.aowin.model.Sysuser;
import com.aowin.service.ScoreService;
import com.aowin.service.StudentService;
import com.aowin.service.SysuserService;
// 在action中调用scoreservice的方法
public class LoginAction extends DispatchAction {

	private StudentService studentService ;
	
	private SysuserService sysuserService;
	
	private ScoreService scoreService;
	
	public ScoreService getScoreService() {
		return scoreService;
	}

	public void setScoreService(ScoreService scoreService) {
		this.scoreService = scoreService;
	}

	public SysuserService getSysuserService() {
		return sysuserService;
	}

	public void setSysuserService(SysuserService sysuserService) {
		this.sysuserService = sysuserService;
	}

	public StudentService getStudentService() {
		return studentService;
	}

	public void setStudentService(StudentService studentService) {
		this.studentService = studentService;
	}
	//检查用户是否在数据库中存在
	public ActionForward checkUser(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		String radio = request.getParameter("aaa");
		request.setAttribute("radio", radio);
		List<Score> list = scoreService.getALLScore();
		request.setAttribute("list", list);
		if("3".equals(radio)){
			Student student = studentService.checkStudent(username, password);
			if(student==null){
				request.setAttribute("usernameerror", "your username is error");//Map key value
				return mapping.findForward("fail");
			}else{
				List<Score> stulist = scoreService.getScoreByStuid(student.getId());
				request.setAttribute("stulist", stulist);
				request.setAttribute("username", username);
				return mapping.findForward("studentView");
			}
		}
		else if("1".equals(radio)){
			Sysuser sysuser = sysuserService.checkSysuserIsExist(username, password);
			if(sysuser==null){
				request.setAttribute("usernameerror", "your username is error");//Map key value
				return mapping.findForward("fail");
			}else{
				request.setAttribute("username", username);
				//老师信息的list
				return mapping.findForward("success");
			}
		}else{
			Sysuser sysuser = sysuserService.checkSysuserIsExist(username, password);
			if(sysuser==null){
				return mapping.findForward("fail");
			}else{
				//显示为老师的信息 管理员管理老师
				System.out.println(radio);
				List<Sysuser> teachers = sysuserService.getSysuserList(1);
				request.setAttribute("teachers", teachers);
				request.setAttribute("username1", username);
				return mapping.findForward("teacherView");
			}
		}
	}
	
	//增加学生信息时做的操作的action
	public ActionForward addScoreMessage(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception { 
		Integer stuid = Integer.valueOf(request.getParameter("stuid"));
		Integer couid = Integer.valueOf(request.getParameter("couid"));
		String score = request.getParameter("score");
		if(scoreService.IsNotExist(stuid, couid)){
			scoreService.addScore(stuid, couid, score);
			List<Score> list = scoreService.getALLScore();
			request.setAttribute("list", list);
			return mapping.findForward("success");
		}else{
			return mapping.findForward("error");
		}
	}
	//更新学生的信息
	public ActionForward updateScoreMessage(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception { 
		Integer id = Integer.valueOf(request.getParameter("scoreid"));
		Integer stuid = Integer.valueOf(request.getParameter("stuid"));
		Integer couid = Integer.valueOf(request.getParameter("couid"));
		String score = request.getParameter("score");
		scoreService.updateScore(id, stuid, couid, score);
		List<Score> list = scoreService.getALLScore();
		request.setAttribute("list", list);
		return mapping.findForward("success");
	}
	//删除学生的信息
	public ActionForward delScore(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception { 
		
		String id = request.getParameter("id");
		int scoreId = Integer.valueOf(id);
		System.out.println(scoreId);
		scoreService.deleteScore(scoreId);
		List<Score> list = scoreService.getALLScore();
		request.setAttribute("list", list);
		return mapping.findForward("success");
	}
	//点击增加时先进入这个action 在通过addInput转到增加的界面上
	public ActionForward addInput(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception { 
		System.out.println("done");
		return mapping.findForward("addInput");
	}
	
	//增加老师的信息的action    跳转到的时候直接跳到jsp
	public ActionForward addTeacher(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception { 
		Integer type = Integer.valueOf(request.getParameter("type"));
		String username = request.getParameter("username");
		String logonname = request.getParameter("logonname");
		String password = request.getParameter("password");
		sysuserService.saveSysuser(type, username, logonname, password);
		List<Sysuser> teachers = sysuserService.getSysuserList(1);
		request.setAttribute("teachers", teachers);
		return mapping.findForward("teacherView");
		//如果这个老师已经存在的话就不能添加了 这个暂时不管先
	}
	
	public ActionForward delTeacher(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception { 
		Integer id = Integer.valueOf(request.getParameter("id"));
		sysuserService.delTeacherMessageById(id);
		List<Sysuser> teachers = sysuserService.getSysuserList(1);
		request.setAttribute("teachers", teachers);
		return mapping.findForward("teacherView");
	}
	
	public ActionForward updateTeacher(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception { 
		Integer sysuserid = Integer.valueOf(request.getParameter("sysuserid"));
		String username = request.getParameter("username");
		String logonname = request.getParameter("logonname");
		sysuserService.updateTeacherMessage(sysuserid, username, logonname);
		List<Sysuser> teachers = sysuserService.getSysuserList(1);
		request.setAttribute("teachers", teachers);
		return mapping.findForward("teacherView");
	}
}	

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
基于SSH(struts-spring-hibernate)开发的学生成绩管理系统,附完整报告,SQL文件,环境为:eclipse+mysql+jdk1.8+tomcate8。运行均能通过,可以作为期末大作业。亲测好用,如果调不通的话,可以私信我~~ 该软件的主要功能是,可以选择多门课程学习,课程类别是必修课或选修课,每门课程由一位专业教师授课,学期末教师给出学生成绩,成绩由平时成绩、实验成绩、理论成绩组成。 (1)学生基本情况录入模块: 主要功能用来对学生的基本信息进行收集和录入。在学生信息保存在系统中的前提下,成绩录入需要输入学生资料,比如班级,学号,姓名。 (2)课程基本情况录入模块: 主要功能用来对课程的基本信息进行收集和录入。在课程信息保存在系统中的前提下,成绩录入需要输入课程资料,比如课程号,学时,学分。 (3)成绩基本情况录入模块: 主要功能用来对学生的成绩进行收集和录入。在准确录入学生资料后,就可以对该学生的各科成绩进行录入。 (4)按学生学号查找并显示学生资料模块: 主要功能是用来查找学生资料。在系统保存了某学生资料的前提下,想要查找该学生资料,可以输入该学生姓名,这样系统就会显示该学生资料信息 。 (5)按课程号查找并显示学生资料模块: 主要功能是用来查找课程资料。在系统保存了某课程资料的前提下,想要查找该课程资料,可以输入该课程号,这样系统就会显示该课程信息 。 (6)修改删除该学生资料模块 主要功能是用来删除学生资料,在系统保存学生资料的前提下,想删除某学生的资料,可以输入学生姓名,系统查找该学生资料后,就可以删除了。由于学生辍学,毕业等原因,及时对系统进行更新,删除一些没用的信息,可以使系统更加优化。 (7)修改删除课程资料模块 主要功能是用来修改删除课程资料,在系统保存课程资料的前提下,想修改删除某课程的资料,可以直接点击删除,系统查找该课程资料后,就可以删除了。 (8)删除成绩资料模块 主要功能是用来删除成绩资料,在系统保存课程资料的前提下,想删除某项成绩的资料,可以直接点击删除,系统查找该项成绩后,就可以删除了。 (9)用户更改密码 主要功能是用来对管理员用户提供密码修改操作.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值