该模块的主要功能如下:
先看看结果怎样,一睹为快
示例程序(学生选课)代码:
#数据模型层
package com.east.entity;
import java.io.Serializable;
public class Subject implements Serializable {
private Integer subject_id; //课题ID
private String subject_title; //课题名称
private String subject_condition; //课题要求
private String tea_name; //导师名称
private String degree; //导师职称
private String stu_name; //选课学生
private String status; //论文状态
private String audit; //编辑状态
private String AuditSituation; //审核情况
public Integer getSubject_id() {
return subject_id;
}
public void setSubject_id(Integer subject_id) {
this.subject_id = subject_id;
}
public String getSubject_title() {
return subject_title;
}
public void setSubject_title(String subject_title) {
this.subject_title = subject_title;
}
public String getSubject_condition() {
return subject_condition;
}
public void setSubject_condition(String subject_condition) {
this.subject_condition = subject_condition;
}
public String getTea_name() {
return tea_name;
}
public void setTea_name(String tea_name) {
this.tea_name = tea_name;
}
public String getDegree() {
return degree;
}
public void setDegree(String degree) {
this.degree = degree;
}
public String getStu_name() {
return stu_name;
}
public void setStu_name(String stu_name) {
this.stu_name = stu_name;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getAudit() {
return audit;
}
public void setAudit(String audit) {
this.audit = audit;
}
public String getAuditSituation() {
return AuditSituation;
}
public void setAuditSituation(String auditSituation) {
AuditSituation = auditSituation;
}
@Override
public String toString() {
return "Subject [subject_id=" + subject_id + ", subject_title=" + subject_title + ", subject_condition="
+ subject_condition + ", tea_name=" + tea_name + ", degree=" + degree + ", stu_name=" + stu_name
+ ", status=" + status + ", audit=" + audit + ", AuditSituation=" + AuditSituation + "]";
}
}
package com.east.dao;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import com.east.entity.Subject;
public interface SubjectDao {
/*
* 查询所有课题
*/
@Select("select * from subject where status = #{status}")
List findByStatus(Subject subject);
/*
* 查询某个学生的课题
*/
@Select("select * from subject where stu_name = #{stu_name}")
Subject findByStuName(String stu_name);
/*
* 学生选题
*/
@Update("update subject set stu_name =#{stu_name} ,status=#{status} where subject_id = #{subject_id}")
void UpdateSub(Subject subject);
/*
* 教师出题
*/
@Insert("insert into subject(subject_title,subject_condition,tea_name,degree) "
+ " values(#{subject_title},#{subject_condition},#{tea_name},#{degree})")
@Options(useGeneratedKeys = true,keyProperty="subject_id")
void AddSubjet(Subject subject);
/*
* 查询某个老师出的题
*/
@Select("select * from subject where tea_name = #{tea_name}")
Subject findByTeaName(String tea_name);
/*
* 删除某个教师的课题
*/
@Delete("delete from subject where tea_name = #{tea_name}")
void DeleteSub(Subject subject);
/*
* 获取所有课题
*/
@Select("select * from subject")
List findAll();
}
package com.east.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.east.dao.SubjectDao;
import com.east.entity.Subject;
@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.DEFAULT)
@Service("subjectBiz")
public class SubjectBiz {
/*
* 自动注入SubjectBiz
*/
@Autowired
private SubjectDao subjectDao;
/*
* 查询所有课题
*/
public List findByStatus(Subject subject){
return subjectDao.findByStatus(subject);
}
/*
* 查询某个学生的课题
*/
public Subject findByStuName(String stu_name){
return subjectDao.findByStuName(stu_name);
}
/*
* 学生选题
*/
public void UpdateSub(Subject subject){
subjectDao.UpdateSub(subject);
}
/*
* 教师出题
*/
public void AddSubjet(Subject subject){
subjectDao.AddSubjet(subject);
}
/*
* 查询某个老师出的题
*/
public Subject findByTeaName(String tea_name){
return subjectDao.findByTeaName(tea_name);
}
/*
* 删除某个教师的课题
*/
public void DeleteSub(Subject subject){
subjectDao.DeleteSub(subject);
}
/*
* 获取所有课题
*/
public List findAll(){
return subjectDao.findAll();
}
}
package com.east.action;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.data.general.DefaultPieDataset;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.east.entity.Student;
import com.east.entity.Subject;
import com.east.entity.Teacher;
import com.east.service.SubjectBiz;
//import com.east.util.JFreeUtil;
import com.east.util.JFreeUtil;
/*
* 处理用户请求的控制器
*/
@Controller
public class SubjectAction {
//自动注入UserService
@Autowired
@Qualifier("subjectBiz")
private SubjectBiz subjectBiz;
/*
* 学生选题
*/
@RequestMapping(value="/SelectSub")
public ModelAndView SelectSub(String id,ModelAndView mv,HttpSession session){
int subject_id = Integer.parseInt(id);
Student stu = (Student) session.getAttribute("user");
String stu_name = stu.getStu_name();
String status = "已选";
Subject sub = new Subject();
sub.setSubject_id(subject_id);
sub.setStu_name(stu_name);
sub.setStatus(status);
subjectBiz.UpdateSub(sub);
mv.setViewName("/student/MySubject");
return mv;
}
/*
* 学生退选课题
*/
@RequestMapping(value="/Chosen")
public ModelAndView Chosen(String id,ModelAndView mv,HttpSession session){
int subject_id = Integer.parseInt(id);
String stu_name = "无";
String status = "未选";
Subject sub = new Subject();
sub.setSubject_id(subject_id);
sub.setStu_name(stu_name);
sub.setStatus(status);
subjectBiz.UpdateSub(sub);
mv.setViewName("/student/MySubject");
return mv;
}
}
<%@page import="java.util.List"%>
<%@page import="com.east.entity.Student"%>
<%@page import="com.east.entity.Subject"%>
<%@page import="com.east.service.SubjectBiz"%>
<%@page import="org.springframework.context.support.ClassPathXmlApplicationContext"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
我的课题
我的课题
<%
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
SubjectBiz subjectBiz = (SubjectBiz) ctx.getBean("subjectBiz");
Subject sub = new Subject();
Student student = (Student) session.getAttribute("user");
String stu_name = student.getStu_name();
sub.setStu_name(stu_name);
Subject subject = subjectBiz.findByStuName(stu_name);
%>
<%
if(subject !=null){
%>
<%
}else{
%>
我要选题
<%
}
%>