courseinfocontroller.java

来自「Spring+hibernate学生在线选课系统」· Java 代码 · 共 179 行

JAVA
179
字号
/*
 * Created on 2005-10-15
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.mmxbb.schoolelective.mvc.course;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
import org.springframework.web.servlet.view.RedirectView;

import org.mmxbb.schoolelective.model.Courseinfo;
import org.mmxbb.schoolelective.model.ShopCartInfo;

import org.mmxbb.schoolelective.service.CourseinfoService;
import org.mmxbb.schoolelective.service.CategoryService;
import org.mmxbb.schoolelective.util.StaticData;



/**
 * @Teacher Administrator
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class CourseinfoController extends MultiActionController {

	  	    
	private CourseinfoService courseinfoService;
	  
    public CourseinfoService getCourseinfoService() {
        return  courseinfoService;	
    }  

    public void setCourseinfoService(CourseinfoService courseinfoService){
    	this.courseinfoService=courseinfoService;   
    }
    private CategoryService categoryService;
    
    public void setCategoryService(CategoryService categoryService){
        this.categoryService = categoryService;
    }
    
    public CategoryService getCategoryService(){
        return this.categoryService;
    }
    
    

    public ModelAndView courseListHandler(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    	List ls=getCourseinfoService().getAllCourseinfo();
    	HashMap result_map=new HashMap();
    	result_map.put("courseList",ls);
    	return new ModelAndView("admin/course/list",result_map);
    }
    public ModelAndView latestcourseHandler(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    	List ls=getCourseinfoService().getAllCourseinfo();
    	HashMap result_map=new HashMap();
    	result_map.put("courseList",ls);
    	return new ModelAndView("web/course/latestcourse",result_map);
    }
    
    public ModelAndView cateCourseListHandler(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    	Integer cate_id =Integer.valueOf(request.getParameter("cate_id"));
        String query="from Courseinfo b where b.categoryid="+cate_id+" order by b.regdate desc";
    	List ls =getCourseinfoService().getSpecCourseinfo(query);
    	
    	HashMap result_map=new HashMap();
    	result_map.put("courseList",ls);
    	return new ModelAndView("admin/course/list",result_map);
    }

    public ModelAndView delCourseHandler(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        Integer course_id =Integer.valueOf(request.getParameter("course_id"));
        Courseinfo courseinfo = getCourseinfoService().getCourseinfo(course_id);
        Integer cate_id=courseinfo.getCategoryid();
        
        getCourseinfoService().deleteCourseinfo(course_id);
          
        return new ModelAndView(new RedirectView("cateCourse.do?cate_id="+cate_id));
    }
    
    public ModelAndView showUpdateCourseinfoHandler(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        Integer course_id =Integer.valueOf(request.getParameter("course_id"));
        
        Courseinfo course=getCourseinfoService().getCourseinfo(course_id);
        List ls=getCategoryService().getAllCategory();
        HashMap result=new HashMap();
        result.put("courseinfo",course);
        result.put("cate",ls);
        
        return new ModelAndView("admin/course/update",result);
    }
    
    public ModelAndView showAddCourseinfoHandler(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        
        List ls=getCategoryService().getAllCategory();
    	        
        return new ModelAndView("admin/course/add","cate",ls);
    }
    
    public ModelAndView detailCourseinfoHandler(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        Integer course_id=Integer.valueOf(request.getParameter("course_id"));
        Courseinfo course=getCourseinfoService().getCourseinfo(course_id);
            	        
        return new ModelAndView("web/course/detail","courseinfo",course);
    }
    
    public ModelAndView buyCourseHandler(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
            Integer course_id=Integer.valueOf(request.getParameter("course_id"));
            ShopCartInfo shopCartInfo=new ShopCartInfo();
            ArrayList shopCartList=(ArrayList)request.getSession().getAttribute(StaticData.SHOPCART_KEY);
            if(shopCartList==null){
            	shopCartList=new ArrayList();
            	
            }
//            if(true){
//            	return new ModelAndView("web/elective/addShopCartFailed");
//            }else 
            String  sessionloginname=(String)request.getSession().getAttribute("loginname");	
          if(sessionloginname==null){
          	return new ModelAndView("web/elective/pleaseLogin");
          }else{
            
            if(!getCourseinfoService().hasTheCourseinfo(shopCartList,course_id))
            { Courseinfo tempcourse=getCourseinfoService().getCourseinfo(course_id);
        	shopCartInfo.setId(tempcourse.getId());
        	shopCartInfo.setName(tempcourse.getName());
        	shopCartInfo.setTeacher(tempcourse.getTeacher());
        	shopCartInfo.setDepartment(tempcourse.getDepartment());
        	shopCartInfo.setCredit(tempcourse.getCredit());
        	shopCartInfo.setAmount(tempcourse.getAmount());
        	//shopCartInfo.setCount(new Integer(1));
        	shopCartList.add(shopCartInfo);
        	request.getSession().setAttribute(StaticData.SHOPCART_KEY,shopCartList);
            
        	return new ModelAndView("web/elective/shopCart");
            }else return new ModelAndView("web/elective/addShopCartFailed");
                	        
          }
        }
    public ModelAndView delShopCartHandler(HttpServletRequest request,
        HttpServletResponse response) throws Exception {
        Integer course_id=Integer.valueOf(request.getParameter("course_id"));
        ArrayList shopCartList=(ArrayList)request.getSession().getAttribute(StaticData.SHOPCART_KEY);   	        
    
        for(int i=shopCartList.size()-1;i>=0;i--){
        	ShopCartInfo sci=(ShopCartInfo)shopCartList.get(i);
        	if(sci.getId().intValue()==course_id.intValue()){
        		shopCartList.remove(i);
        	     break;
        	     }
        }
        request.getSession().setAttribute(StaticData.SHOPCART_KEY,shopCartList); 

        return new ModelAndView("/web/elective/shopCart");
    }
    
}
		
		
		
	

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?