首页>代码>springboot+springmvc+mybatis实现对学生信息的增删改查简单demo>/springboot_springmvc_mybatis/src/main/java/com/ms/controller/StudentController.java
package com.ms.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
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.ModelAndView;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ms.pojo.Student;
import com.ms.service.StudentService;

@Controller
@RequestMapping("student")
public class StudentController {

	@Autowired
	StudentService studentService;
	
	/**
	 * restful风格实现页面跳转
	 */
	@RequestMapping("/{page}")
	public String showInfo(@PathVariable String page){
		return page;
	}
	
	//查询所有学生信息
	@RequestMapping("SelectAllStu")
	public ModelAndView SelectAllStu(@RequestParam(defaultValue="1") Integer page,
			HttpServletRequest request,HttpServletResponse response){
		PageHelper.startPage(page,5);
		List<Student> list=studentService.SelectAllStu();
		PageInfo pageinfo = new PageInfo(list,5);
		
		ModelAndView model = new ModelAndView();
		model.addObject("pageinfo", pageinfo);
		model.setViewName("showAllStu");
		return  model;
		
	}
	
	//添加学生信息
	@RequestMapping("dosertStu")
	public String insertStu(Student student){
		studentService.addStu(student);
		return "success";
		
	}
	
	//删除学生信息
	@RequestMapping("deleteStu")
	public String deleteStu(Student student){
		studentService.deleteStu(student);
		return "success";
		
	}
	
	//查询学生信息
	@RequestMapping("doselectStu")
	public String selectStu(Model model,Student student){
		List<Student> list=studentService.selectStu(student);
		model.addAttribute("list", list);
		return "selectStuResult";
	}
	
	//实现数据回显
	@RequestMapping("updateStu")
	public String updateStu(Student student,Model model,
			@RequestParam(value = "id", required = true) Integer id){
		Student stu=studentService.selectStuById(student);
		
		model.addAttribute("student", stu);
		
		return "updateStuView";
	}
	
	//修改学生的信息
	@RequestMapping("doupdateStu")
	public String doupdate(Student student){
		studentService.updateStu(student);
		return "success";
		
	}

}
最近下载更多
13940562934  LV22 2023年9月27日
1379585889  LV11 2023年6月2日
yeyuuu  LV6 2023年5月20日
李亮  LV19 2023年3月6日
codingwomen  LV9 2022年9月21日
莫回头  LV8 2022年8月31日
cc1061394399  LV1 2022年7月27日
alic44444  LV1 2022年4月12日
Francis132  LV4 2022年1月21日
LJYljyuuuuuuu  LV1 2022年1月6日
最近浏览更多
WBelong  LV7 4月2日
taoshen95  LV14 2023年12月25日
wwwww816  LV3 2023年12月19日
xiao小果  LV12 2023年12月13日
fff2003  LV6 2023年11月20日
sunshine9920  LV12 2023年11月7日
13940562934  LV22 2023年9月27日
 LV7 2023年8月21日
hhvivi  LV2 2023年7月2日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友