package com.hhtc.controller; import java.util.List; import javax.servlet.http.HttpSession; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import com.hhtc.po.Page; import com.hhtc.po.Student; import com.hhtc.po.Teacher; import com.hhtc.service.AdminService; import net.sf.json.JSONArray; import net.sf.json.JSONObject; @Controller public class AdminController { @Autowired private AdminService adminService; @RequestMapping("/welcome") public ModelAndView welcome(Model model) { ModelAndView mav = new ModelAndView("admin/welcome"); return mav; } //学生 //学生数据分页 @RequestMapping(value = "/liststudent",method = {RequestMethod.POST, RequestMethod.GET},produces ="application/json;charset=UTF-8") @ResponseBody public String liststudent(Page page) { List<Student> list=adminService.stumanage(); page.caculatestart(); List<Student> list2=adminService.liststudent(page); JSONObject jsonobj=new JSONObject(); jsonobj.put("code", 0); jsonobj.put("msg", "成功"); jsonobj.put("count",list.size()); JSONArray jsonobj2=new JSONArray(); JSONObject jsonobj3=new JSONObject(); for(Student student:list2) { jsonobj3.put("id",student.getId()); jsonobj3.put("username",student.getUsername()); jsonobj3.put("password",student.getPassword()); jsonobj3.put("stuclass",student.getStuclass()); jsonobj3.put("stuname",student.getStuname()); jsonobj3.put("stuno",student.getStuno()); jsonobj2.add(jsonobj3); } jsonobj.put("data", jsonobj2); return jsonobj.toString(); } @RequestMapping("/addstudent") public ModelAndView addstu(Student student,Model model) { adminService.addStudent(student); ModelAndView mav = new ModelAndView("admin/stumanage"); return mav; } @RequestMapping("/delstu") public ModelAndView delstu(String id,Model model) { adminService.delstudnet(id); ModelAndView mav = new ModelAndView("admin/stumanage"); return mav; } @RequestMapping("/updatestu") public ModelAndView updatestu(String id,Student student,Model model) { student.setId(Integer.parseInt(id)); adminService.updatestu(student); ModelAndView mav = new ModelAndView("admin/stumanage"); return mav; } @RequestMapping(value = "/mohuname",method = {RequestMethod.POST, RequestMethod.GET},produces ="application/json;charset=UTF-8") @ResponseBody public String mohuname(HttpSession session) { @SuppressWarnings("unchecked") List<Student> list=(List<Student>) session.getAttribute("list"); JSONObject jsonobj=new JSONObject(); jsonobj.put("code", 0); jsonobj.put("msg", "成功"); jsonobj.put("count",list.size()); JSONArray jsonobj2=new JSONArray(); JSONObject jsonobj3=new JSONObject(); for(Student student:list) { jsonobj3.put("id",student.getId()); jsonobj3.put("username",student.getUsername()); jsonobj3.put("password",student.getPassword()); jsonobj3.put("stuclass",student.getStuclass()); jsonobj3.put("stuname",student.getStuname()); jsonobj3.put("stuno",student.getStuno()); jsonobj2.add(jsonobj3); } jsonobj.put("data", jsonobj2); return jsonobj.toString(); } //老师 @RequestMapping("/addtea") public ModelAndView addteacher(Teacher teacher,Model model) { adminService.addteacher(teacher); ModelAndView mav = new ModelAndView("admin/teamanage"); return mav; } @RequestMapping(value = "/teamanage",method = {RequestMethod.POST, RequestMethod.GET},produces ="application/json;charset=UTF-8") @ResponseBody public String teamanage(Model model) { List<Teacher> list=adminService.teamanage(); JSONObject jsonobj=new JSONObject(); jsonobj.put("code", 0); jsonobj.put("msg", "成功"); jsonobj.put("count",list.size()); JSONArray jsonobj2=new JSONArray(); JSONObject jsonobj3=new JSONObject(); for(Teacher teacher:list) { jsonobj3.put("id",teacher.getId()); jsonobj3.put("username",teacher.getUsername()); jsonobj3.put("password",teacher.getPassword()); jsonobj3.put("teaname",teacher.getTeaname()); jsonobj2.add(jsonobj3); } jsonobj.put("data", jsonobj2); return jsonobj.toString(); } @RequestMapping("/deltea") public ModelAndView deltea(String id,Model model) { adminService.delteacher(id); ModelAndView mav = new ModelAndView("admin/teamanage"); return mav; } @RequestMapping("/updatetea") public ModelAndView updatetea(String id,Teacher teacher,Model model) { teacher.setId(Integer.parseInt(id)); adminService.updatetea(teacher); ModelAndView mav = new ModelAndView("admin/teamanage"); return mav; } @RequestMapping(value = "/mohunametea",method = {RequestMethod.POST, RequestMethod.GET},produces ="application/json;charset=UTF-8") @ResponseBody public String mohunametea(HttpSession session) { @SuppressWarnings("unchecked") List<Teacher> list=(List<Teacher>) session.getAttribute("tealist"); JSONObject jsonobj=new JSONObject(); jsonobj.put("code", 0); jsonobj.put("msg", "成功"); jsonobj.put("count",list.size()); JSONArray jsonobj2=new JSONArray(); JSONObject jsonobj3=new JSONObject(); for(Teacher teacher:list) { jsonobj3.put("id",teacher.getId()); jsonobj3.put("username",teacher.getUsername()); jsonobj3.put("password",teacher.getPassword()); jsonobj3.put("teaname",teacher.getTeaname()); jsonobj2.add(jsonobj3); } jsonobj.put("data", jsonobj2); return jsonobj.toString(); } }
最近下载更多
自由吃柚子 LV2
前天
3090754224 LV2
1月7日
李朝磊 LV18
2023年12月30日
xiongwei11231 LV8
2023年12月12日
liuxiao2 LV16
2023年11月7日
蹇金金 LV7
2023年11月6日
wwewww LV4
2023年11月3日
wcheng LV2
2023年10月18日
李亮 LV19
2023年8月28日
000666 LV10
2023年7月11日
最近浏览更多
自由吃柚子 LV2
前天
微信网友_6914427966033920 LV4
3月19日
XJH939 LV1
3月14日
xinnnnn LV1
2月26日
admin_z LV22
1月29日
周青松5
1月15日
暂无贡献等级
3090754224 LV2
1月7日
minjing123 LV8
1月4日
李朝磊 LV18
2023年12月30日
zzzzzzz09173
2023年12月27日
暂无贡献等级