//@PathVariable可以用来映射URL中的占位符到目标方法的参数中
public String edit(Model model,@PathVariable int id){
model.addAttribute(“entity”, classesService.getCLassId(id));
return “class/edit”;
}
/*
- 编辑保存
*/
@RequestMapping(“/editSave”)
//@Valid的参数后必须紧挨着一个BindingResult 参数
//Spring验证的错误返回
public String editSave(Model model,@ModelAttribute(“entity”) @Valid Classes entity,BindingResult bindingResult){
//如果模型中存在错误
if(bindingResult.hasErrors()){
model.addAttribute(“entity”, entity);
return “/class/edit”;
}else{
classesService.update(entity);
return “redirect:list”;
}
}
@RequestMapping(“search/{id}”)
public String search(@PathVariable int id,Model model) {
List slist=studentService.getStuByCid(id);
model.addAttribute(“slist”, slist);
return “class/stulist”;
}
@RequestMapping(“search1/{id}”)
public String search1(@PathVariable int id,Model model) {
/*List slist=studentService.getStuByCid(id);
model.addAttribute(“slist”, slist);*/
Classes classes=classesService.getStuByid(id);
model.addAttribute(“classes”, classes);
return “class/stulist1”;
}
}
CourseController
package com.offcn.controller;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
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.servlet.mvc.support.RedirectAttributes;
import com.offcn.mapper.CtcMapper;
import com.offcn.pojo.Classes;
import com.offcn.pojo.Course;
import com.offcn.pojo.CtcKey;
import com.offcn.pojo.Teacher;
import com.offcn.pojo.User;
import com.offcn.service.ClassesService;
import com.offcn.service.CourseService;
import com.offcn.service.TeacherService;
import java.util.ArrayList;
import java.util.List;
/**
-
Company: offcn
-
@author zgf
-
@date 2017年5月22日
-
@version 1.0
*/
@Controller
@RequestMapping(“/cou”)
public class CourseController {
@Resource
CourseService courseService;
@Resource
TeacherService teacherService;
@Resource
ClassesService classesService;
/* @Resource
CtcService ctcService;*/
/* @Resource
GradeService gradeService;*/
/*
- 列表与分页Action
*/
@RequestMapping(“/list”)
public String list(Model model,@RequestParam(required=false,defaultValue=“1”) int pageNO){
int size=3;
model.addAttribute(“size”,size);
model.addAttribute(“pageNO”,pageNO);
model.addAttribute(“count”,courseService.getCourseCount());
model.addAttribute(“coulist”, courseService.getCoursePager(pageNO, size));
return “course/list”;
}
/*
- 删除单个对象Action
*/
@RequestMapping(“/delete/{id}”)
public String delete(Model model,@PathVariable int id,@RequestParam(required=false,defaultValue=“1”) int pageNO,RedirectAttributes redirectAttributes){
if(courseService.delete(id)>0)
{
redirectAttributes.addFlashAttribute(“message”, “删除成功!”);
}else{
redirectAttributes.addFlashAttribute(“message”, “删除成功!”);
}
return “redirect:/cou/list?pageNO=”+pageNO;
}
/*
- 删除多个对象Action
*/
@RequestMapping(“/deletes”)
public String deletes(Model model,@RequestParam int[] id,@RequestParam(required=false,defaultValue=“1”) int pageNO,RedirectAttributes redirectAttributes){
//执行删除
System.out.println(“批量删除”+id.toString());
int rows=courseService.deletes(id);
if(rows>0)
{
redirectAttributes.addFlashAttribute(“message”, “删除”+rows+“行记录成功!”);
}else{
redirectAttributes.addFlashAttribute(“message”, “删除失败!”);
}
return “redirect:/cou/list?pageNO=”+pageNO;
}
/*
- 添加
*/
@RequestMapping(“/add”)
public String add(Model model){
model.addAttribute(“entity”, new Course());
return “course/add”;
}
/*
- 添加保存
*/
@RequestMapping(“/addSave”)
public String addSave(Model model,@ModelAttribute(“entity”) @Valid Course entity,BindingResult bindingResult){
//如果模型中存在错误
if(bindingResult.hasErrors()){
model.addAttribute(“entity”, entity);
return “course/add”;
}else{
courseService.insert(entity);
return “redirect:/cou/list”;
}
}
/*
- 编辑
*/
@RequestMapping(“/edit/{id}”)
public String edit(Model model,@PathVariable int id){
model.addAttribute(“entity”, courseService.getCourseId(id));
return “course/edit”;
}
/*
- 编辑保存
*/
@RequestMapping(“/editSave”)
public String editSave(Model model,@ModelAttribute(“entity”) @Valid Course entity,BindingResult bindingResult){
//如果模型中存在错误
if(bindingResult.hasErrors()){
model.addAttribute(“entity”, entity);
return “/course/edit”;
}else{
courseService.update(entity);
return “redirect:list”;
}
}
//排课
@RequestMapping(“/setTeacher/{id}”)
public String setTeacher(Model model,@PathVariable int id){
Course course=courseService.getCourseId(id);
model.addAttribute(“entity”,course);
List tlist=teacherService.getAllTeacher();
List clist=classesService.getAllClasses();
model.addAttribute(“tlist”, tlist);
model.addAttribute(“clist”, clist);
return “course/setct”;
}
@RequestMapping(“editSavect”)
public String editSavect(Model model,@ModelAttribute(“entity”) Course entity,RedirectAttributes redirectAttributes){
//Course course=entity;
String classid=entity.getClasses();
String[] classids=classid.split(“,”);
List ctclist=new ArrayList();
for(int i=0;i<classids.length;i++){
CtcKey c=new CtcKey();
c.setCouid(entity.getId());
c.setClaid(Integer.parseInt(classids[i]));
c.setTid(entity.getTeacher().getId());
ctclist.add©;
}
try{
courseService.insertBatch(ctclist);
}catch(Exception e){
redirectAttributes.addFlashAttribute(“msg”, “排课存在冲突,请核对后重新选!”);
}
return “redirect:/cou/list”;
}
@RequestMapping(“toChangePassword”)
public String toChangePassword(){
return “course/changePassword”;
}
@ResponseBody
@RequestMapping(“changePassword”)
public int changePassword(String password,String oldPass,int id,HttpServletRequest re){
HttpSession session = re.getSession();
User user = (User)session.getAttribute(“user”);
if(user.getPassword().equals(oldPass)) {
courseService.changePassword(password,id,user);
return 1;
}else
return 2;
}
}
StudentController
package com.offcn.controller;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
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.servlet.mvc.support.RedirectAttributes;
import com.offcn.pojo.Classes;
import com.offcn.pojo.CourseExt;
import com.offcn.pojo.Sc;
import com.offcn.pojo.Student;
import com.offcn.service.ClassesService;
import com.offcn.service.StudentService;
@Controller
@RequestMapping(“/stu”)
public class StudentController {
@Resource
StudentService studentService;
@Resource
ClassesService classesService;
@RequestMapping(“/list”)
public String getlist(@RequestParam(required=false,defaultValue=“1”) int pageNO,Model model) {
int size=3;
List slist=studentService.getStudentPager(pageNO, size);
model.addAttribute(“pageNO”, pageNO);
model.addAttribute(“size”, size);
model.addAttribute(“count”, studentService.getCount());
model.addAttribute(“slist”, slist);
return “student/list”;
}
@RequestMapping(“/findByName”)
public String findByName(String name,Model model) {
int size=10;
List slist=studentService.findByName(name);
model.addAttribute(“pageNO”, 1);
model.addAttribute(“size”, size);
model.addAttribute(“count”, studentService.getCount());
model.addAttribute(“slist”, slist);
model.addAttribute(“name”, name);
return “student/list”;
}
@RequestMapping(“/findByName2”)
public String findByName2(String id,Model model) {
int size=10;
List slist = new ArrayList<>();
if(id!=“”&&id!=null) {
slist=studentService.findByName2(Integer.parseInt(id));
}
model.addAttribute(“pageNO”, 1);
model.addAttribute(“size”, size);
model.addAttribute(“count”, studentService.getCount());
model.addAttribute(“slist”, slist);
model.addAttribute(“id”, id);
return “student/list”;
}
@RequestMapping(“/findByName3”)
public String findByName3(String address,Model model) {
int size=10;
List slist=studentService.findByName3(address);
model.addAttribute(“pageNO”, 1);
model.addAttribute(“size”, size);
model.addAttribute(“count”, studentService.getCount());
model.addAttribute(“slist”, slist);
model.addAttribute(“address”, address);
return “student/list”;
}
//重定向一定要写绝对路径eg:redirect:/stu/list
@RequestMapping(“/delete/{id}”)
public String delete(@PathVariable int id,Model model) {
studentService.deleteByPrimaryKey(id);
return “redirect:/stu/list”;
}
@RequestMapping(“/deletes”)
public String deletes(@RequestParam(“id”) int[] ids,Model model,RedirectAttributes redirectAttributes) {
int rows=0;
rows=studentService.multiDelete(ids);
if(rows>0){
redirectAttributes.addFlashAttribute(“message”, “成功删除!”);
}else{
redirectAttributes.addFlashAttribute(“message”, “删除shibai!”);
}
return “redirect:/stu/list”;
}
//
@RequestMapping(“/add”)
public String add(Model model) {
List clist=classesService.getAllClasses();
model.addAttribute(“clist”, clist);
model.addAttribute(“entity”, new Student());
return “student/add”;
}
//mm `
@RequestMapping(“/addSave”)
public String addSave(Model model,@ModelAttribute(“entity”) @Valid Student entity,BindingResult bindingResult,RedirectAttributes redirectAttributes) {
if(bindingResult.hasErrors()){
model.addAttribute(“entity”, entity);
List clist=classesService.getAllClasses();
model.addAttribute(“clist”, clist);
//redirectAttributes.addFlashAttribute(“entity”, arg1)
return “student/add”;
//return “redirect:/add”;
}else{
List clist=classesService.getAllClasses();
model.addAttribute(“clist”, clist);
model.addAttribute(“entity”, new Student());
studentService.insert(entity);
return “redirect:/stu/list”;
}
}
//edit/${entity.id}
@RequestMapping(“/edit/{id}”)
public String add(Model model,@PathVariable int id) {
List clist=classesService.getAllClasses();
model.addAttribute(“clist”, clist);
model.addAttribute(“entity”, studentService.selectByPrimaryKey(id));
return “student/edit”;
}
//
@RequestMapping(“/editSave”)
public String editSave(Model model,Student student) {
studentService.updateByPrimaryKey(student);
return “redirect:/stu/list”;
}
@RequestMapping(“/getXuXiu”)
public String getXuXiu(Model model,HttpServletRequest req){
HttpSession session=req.getSession();
Student student=(Student) session.getAttribute(“user”);
List clist= studentService.getXuxiu(student.getClassid());
model.addAttribute(“colist”, clist);
return “student/colist”;
}
@RequestMapping(value=“/semycou”,produces=“text/html;charset=utf8”)
@ResponseBody
public String semycou(@RequestParam(“cou”) String[] ct,HttpServletRequest req){
HttpSession session=req.getSession();
Student student=(Student) session.getAttribute(“user”);
List sclist=new ArrayList();
for(int i=0;i<ct.length;i++){
Sc sc=new Sc();
String cteveryone=ct[i];
String[] ctarray=cteveryone.split(“_”);
sc.setCid(Integer.parseInt(ctarray[0]));
sc.setTid(Integer.parseInt(ctarray[1]));
sc.setSid(student.getId());
sclist.add(sc);
}
String msg=“”;
try{
studentService.inserBatch(sclist);
msg=“选课成功!”;
}catch(Exception e){
msg=“选课可能有重复,请审核后重试!”;
}
return msg;
}
@RequestMapping(“/getStuCourse”)
public String getStuCourse(Model model,HttpServletRequest req){
HttpSession session=req.getSession();
Student student=(Student) session.getAttribute(“user”);
List ctlist=studentService.getMycourses(student.getClassid(), student.getId());
model.addAttribute(“ctlist”, ctlist);
return “student/cslist”;
}
}
TeacherController
package com.offcn.controller;
import java.io.File;
import java.util.List;
import java.util.UUID;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.offcn.pojo.Grade;
import com.offcn.pojo.StudentView;
import com.offcn.pojo.Teacher;
import com.offcn.service.TeacherService;
/**
-
Company: offcn
-
@author zgf
-
@date 2017年5月22日
-
@version 1.0
*/
@Controller
@RequestMapping(“/tea”)
public class TeacherController {
@Resource
TeacherService teacherService;
/*
- 学生列表与分页Action
*/
@RequestMapping(“/list”)
public String list(Model model,@RequestParam(required=false,defaultValue=“1”) int pageNO){
int size=3;
model.addAttribute(“size”,size);
model.addAttribute(“pageNO”,pageNO);
model.addAttribute(“count”,teacherService.getTeacherCount());
model.addAttribute(“tealist”, teacherService.getTeacherPager(pageNO, size));
return “teacher/list”;
}
/*
- 删除单个学生对象Action
*/
@RequestMapping(“/delete/{id}”)
public String delete(Model model,@PathVariable int id,@RequestParam(required=false,defaultValue=“1”) int pageNO,RedirectAttributes redirectAttributes){
if(teacherService.delete(id)>0)
{
redirectAttributes.addFlashAttribute(“message”, “删除成功!”);
}else{
redirectAttributes.addFlashAttribute(“message”, “删除失败!”);
}
return “redirect:/tea/list?pageNO=”+pageNO;
}
/*
- 删除多个学生对象Action
*/
@RequestMapping(“/deletes”)
public String deletes(Model model,@RequestParam int[] id,@RequestParam(required=false,defaultValue=“1”) int pageNO,RedirectAttributes redirectAttributes){
//执行删除
System.out.println(“批量删除”+id.toString());
int rows=teacherService.deletes(id);
if(rows>0)
{
redirectAttributes.addFlashAttribute(“message”, “删除”+rows+“行记录成功!”);
}else{
redirectAttributes.addFlashAttribute(“message”, “删除失败!”);
}
return “redirect:/tea/list?pageNO=”+pageNO;
}
/*
- 添加
*/
@RequestMapping(“/add”)
public String add(Model model){
model.addAttribute(“entity”, new Teacher());
return “teacher/add”;
}
/*
- 添加保存
*/
@RequestMapping(“/addSave”)
public String addSave(Model model,@ModelAttribute(“entity”) @Valid Teacher entity,BindingResult bindingResult){
//如果模型中存在错误
if(bindingResult.hasErrors()){
model.addAttribute(“entity”, entity);
return “teacher/add”;
}else{
entity.setPassword(“aaaaaa”);
teacherService.insert(entity);
return “redirect:/tea/list”;
}
}
/*
- 编辑
*/
@RequestMapping(“/edit/{id}”)
public String edit(Model model,@PathVariable int id){
model.addAttribute(“entity”, teacherService.getTeacherId(id));
return “teacher/edit”;
}
/*
- 保存
*/
@RequestMapping(“/editSave”)
public String editSave(Model model,@ModelAttribute(“entity”) @Valid Teacher entity,BindingResult bindingResult){
//如果模型中存在错误
if(bindingResult.hasErrors()){
model.addAttribute(“entity”, entity);
return “/teacher/edit”;
}else{
//entity.setPassword(“aaaaaa”);
teacherService.update(entity);
return “redirect:list”;
}
}
//
@RequestMapping(“getMyStu”)
public String getMyStu(Model model,HttpServletRequest req){
HttpSession session=req.getSession();
Teacher teacher=(Teacher) session.getAttribute(“user”);
List slist=teacherService.getMystus(teacher.getId());
model.addAttribute(“stulist”, slist);
return “teacher/couOftea/stulist”;
}
//
@RequestMapping(“setGrades/{sid}/{sname}/{cid}”)
public String setGrades(Model model,@PathVariable int sid,@PathVariable String sname,@PathVariable int cid){
Grade grade=new Grade();
grade.setSid(sid);
grade.setCid(cid);
model.addAttribute(“entity”, grade);
model.addAttribute(“sname”, sname);
return “teacher/couOftea/setgrade”;
}
@RequestMapping(“/saveGrade”)
public String setGrades(Model model,Grade entity,HttpServletRequest req,RedirectAttributes redirectAttributes){
HttpSession session=req.getSession();
Teacher teacher=(Teacher) session.getAttribute(“user”);
entity.setZgrade(entity.getPgrade()+entity.getKgrade());
entity.setTid(teacher.getId());
int rows=teacherService.insertGrade(entity);
if(rows>0){
redirectAttributes.addFlashAttribute(“msg”, “录入成功!”);
}else{
redirectAttributes.addFlashAttribute(“msg”, “录入失败!”);
}
return “redirect:getMyStu”;
}
}
UserController
package com.offcn.controller;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
最后
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此收集整理了一份《2024年Web前端开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
cher=(Teacher) session.getAttribute(“user”);
entity.setZgrade(entity.getPgrade()+entity.getKgrade());
entity.setTid(teacher.getId());
int rows=teacherService.insertGrade(entity);
if(rows>0){
redirectAttributes.addFlashAttribute(“msg”, “录入成功!”);
}else{
redirectAttributes.addFlashAttribute(“msg”, “录入失败!”);
}
return “redirect:getMyStu”;
}
}
UserController
package com.offcn.controller;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
最后
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此收集整理了一份《2024年Web前端开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
[外链图片转存中…(img-DxZEv3l8-1715457738475)]
[外链图片转存中…(img-VI8STTuQ-1715457738476)]
[外链图片转存中…(img-2Ohh5LOP-1715457738476)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!