首页>代码>ssm+layui+freemarker开发学生成绩管理系统>/xueshengguanli/src/com/cms/controller/BaseCourseController.java
package com.cms.controller;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.cms.entity.BaseCourse;
import com.cms.service.BaseCourseService;
import com.cms.utils.StrUtil;
import com.cms.utils.page.Pagination;

@Controller
@RequestMapping(value="/basecourse")
public class BaseCourseController {
	
	@Autowired
	private BaseCourseService baseCourseService;
	
	@ResponseBody
	@RequestMapping(value="/list")
	public String getBaseCourseList(@RequestParam(defaultValue="0")int curr,@RequestParam(defaultValue="10")int nums,
			@RequestParam(defaultValue="")String searchKey) {
		Pagination<BaseCourse> page = new Pagination<BaseCourse>();
		
		page.setTotalItemsCount(baseCourseService.getTotalItemsCount(searchKey));
		page.setPageSize(nums);
		page.setPageNum(curr);
		List<BaseCourse> list = baseCourseService.getBaseCourse(page, searchKey);
		
		
		String jsonStr = StrUtil.RETURN_JONS_PRE_STR + page.getTotalItemsCount() 
				+ StrUtil.RETURN_JONS_MID_STR
				+ JSON.toJSONString(list) + StrUtil.RETURN_JONS_END_STR;
		
		System.out.println(jsonStr);
		return jsonStr;
	}
	
	@ResponseBody
	@RequestMapping(value="/listForSelect")
	public String getBaseCourseListForSelect(@RequestParam(defaultValue="") String searchKey) {
		List<BaseCourse> list = baseCourseService.getBaseCourseForSelect(searchKey);
		String jsonStr = StrUtil.RETURN_JONS_PRE_STR + list.size() 
				+ StrUtil.RETURN_JONS_MID_STR
				+ JSON.toJSONString(list) + StrUtil.RETURN_JONS_END_STR;
		return jsonStr;
	}
    
	@RequestMapping(value="/addPage")
	public ModelAndView toAddPage() {
		return new ModelAndView("/baseCourseAdd");
	}
	
	/**
	 * 增加,或者修改BaseCourse
	 * @param BaseCourse
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/add")
	public String addBaseCourse(BaseCourse baseCourse) {
		int res = 0;
		if (baseCourse.getId() == null || baseCourse.getId().equals("")) {
			try {
				res = baseCourseService.addBaseCourse(baseCourse);
			} catch (Exception e) {
				System.out.println("添加失败!");
				return "添加失败!";
			}
			if (res > 0)
				return StrUtil.RESULT_TRUE;
			return "添加失败";
		} else {
			res = baseCourseService.updateBaseCourse(baseCourse);
			if (res > 0) return StrUtil.RESULT_TRUE;
			return "修改失败!";
		}
	}
	
	
	@ResponseBody
	@RequestMapping(value="/delete")
	public String deleteStudnet(BaseCourse t) {
		if (baseCourseService.deleteBaseCourse(t) > 0) return StrUtil.RESULT_TRUE;
		return "删除失败!";
	}
	
	/**
	 * 批量删除
	 * @param tIds
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/deleteList")
	public String deleteStudnetList(String cIds) {
		List<Integer> list = new ArrayList<Integer>();
		try {
			String[] ids = cIds.split(",");
			for (String id: ids) {
				list.add(Integer.parseInt(id));
			}
			if (baseCourseService.deleteBaseCourse(list) > 0) {
				return StrUtil.RESULT_TRUE;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return "删除失败!参数出错!";//
		}
		return "删除失败!";
	}
	
	@ResponseBody
	@RequestMapping("/import")  
	public String impotr(HttpServletRequest request, MultipartFile file) {  
	     //获取上传的文件  
	     InputStream in = null;
		try {
			in = file.getInputStream();
			//数据导入  
			int res = baseCourseService.importExcelInfo(in,file);
			if (res > 0) {
				return StrUtil.RETURN_JONS_PRE_STR+"0"
						+StrUtil.RETURN_JONS_MID_STR+"true"
						+StrUtil.RETURN_JONS_END_STR;
			} else {
				return StrUtil.RETURN_JONS_PRE_STR+"0"
						+StrUtil.RETURN_JONS_MID_STR+"false"
						+StrUtil.RETURN_JONS_END_STR;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return StrUtil.RETURN_JONS_PRE_STR+"0"
			+StrUtil.RETURN_JONS_MID_STR+"error"
			+StrUtil.RETURN_JONS_END_STR;
		} finally {
			if (in != null)
				try {
					in.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
		}
	}
	
}
最近下载更多
Mr_VVcat  LV8 4月30日
wanglinddad  LV54 4月2日
WBelong  LV7 3月7日
houhanlin33  LV3 1月8日
xutao0523  LV2 2023年12月18日
zxcfgh  LV4 2023年11月21日
fesfefe  LV13 2023年10月23日
Rucoding  LV7 2023年6月23日
1515465193  LV9 2023年6月9日
微信网友_6260196253601792  LV7 2023年6月7日
最近浏览更多
Mr_VVcat  LV8 4月30日
fkjafjkkfo  LV2 4月24日
mzqnxyh  LV2 4月12日
wanglinddad  LV54 4月2日
XJH939  LV1 3月18日
玖零定制问题修复  LV34 3月3日
xinnnnn  LV1 2月26日
我要上研  LV2 1月22日
houhanlin33  LV3 1月8日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友