首页>代码>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";
		
	}

}
最近下载更多
2194192290li  LV1 2024年12月2日
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日
最近浏览更多
微信网友_7316199114199040 2024年12月28日
暂无贡献等级
2194192290li  LV1 2024年12月2日
ma406805131  LV19 2024年6月28日
暂无贡献等级
颜菜菜  LV2 2024年6月19日
17380184110 2024年6月18日
暂无贡献等级
yuanyuan23  LV1 2024年5月30日
WBelong  LV8 2024年4月2日
微信网友_6815604991741952  LV1 2024年1月10日
taoshen95  LV16 2023年12月25日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友