发表于: 2017-11-04 22:23:04
1 821
【今天完成的事】
springMVC增删改查全部搞定~
上传一下最后的Controller层。
package com.xiuzhen.controller;
import com.xiuzhen.domain.Student;
import com.xiuzhen.service.StudentService;
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 javax.annotation.Resource;
import javax.persistence.criteria.CriteriaBuilder;
import java.util.Date;
import java.util.Map;
/**
* Created by ${MIND-ZR} on 2017/10/20.
*/
@Controller
public class StudentController {
@Resource
private StudentService studentService;
//遍历所有员工
@RequestMapping("/list")
public String testListStudent(Map<String, Object> map) {
map.put("studentAll", studentService.getAll());
return "list";
}
//跳转到相应的页面
@RequestMapping("/add")
public String Add() {
return "addStu";
}
//插入学生
@RequestMapping("/addStu")
public String addStudent(Student student) {
student.setCreate_at(System.currentTimeMillis() / 1000);
studentService.insertStudent(student);
return "redirect:list";
}
//修改操作
@RequestMapping("/edit")
public String editStu(Integer id, Model model) {
Student student = studentService.selectStudentById(id);
model.addAttribute("student", student);
return "editStu";
}
@RequestMapping(value = "/editStu", method = RequestMethod.POST)
public String saveOrEdit(Student student) {
student.setUpdate_at(System.currentTimeMillis() / 1000);
studentService.updateStudent(student);
return "redirect:list";
}
//删除操作
@RequestMapping("/deleteStu")
public String deleteStu(Integer id) {
studentService.deleteStudent(id);
return "redirect:list";
}
}
鉴于时间restful还没配上去,明天搞。
实现效果就是列表页
增加页
修改页
删除就直接删除返回list页面就不写了。
【遇到的问题】
主要问题还是对springMVC的理解不透彻,哪都报错。
【收获】
对springMVC理解更进一步~
【明天要做的事】
把restful配置完成,然后再学一下postman.
评论