package com.jiyun.controller;
import com.github.pagehelper.PageInfo;
import com.jiyun.mapper.TeacherMapper;
import com.jiyun.pojo.PageTvo;
import com.jiyun.pojo.Student;
import com.jiyun.pojo.Teacher;
import com.jiyun.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class StudentController {
@Autowired
StudentService b;
@Autowired
TeacherMapper d;
@RequestMapping("show")
public PageInfo show(@RequestBody PageTvo pageTvo){
return b.show(pageTvo);
}
// 教师
@RequestMapping("bu")
public List bu(){
return d.show();
}
@RequestMapping("add")
public Boolean add(@RequestBody Student student){
b.add(student);
return true;
}
//修改
@RequestMapping("update")
public Boolean update(@RequestBody Student student){
b.update(student);
return true;
}
@RequestMapping("del")
public Boolean del( Integer id){
b.del(id);
return true;
}
// 多选删除
@RequestMapping("delAll")
public Boolean delAll( @RequestBody List students){
for (Student student : students) {
b.del(student.getId());
}
return true;
}
}
封装分页信息:
Service:
package com.jiyun.service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jiyun.mapper.StudentMapper;
import com.jiyun.pojo.PageTvo;
import com.jiyun.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Service
public class StudentService {
@Autowired
StudentMapper b;
public PageInfo show(PageTvo pageTvo) {
//分页
PageHelper.startPage(pageTvo.getPageNum(),pageTvo.getPageSize());
// 获取封装里面的数据
Integer did = pageTvo.getDid();
String name = pageTvo.getName();
Date time = pageTvo.getTime();
//
//存入对象
Student student = new Student();
student.setName(name);
student.setDid(did);
student.setTime(time);
List show = b.show(student);
PageInfo studentPageInfo = new PageInfo(show);
return studentPageInfo;
}
public void add(Student student) {
b.add(student);
}
public void update(Student student) {
b.update(student);
}
public void del(Integer id) {
b.del(id);
}
}
Mapper:
insert into student (name, sex, hobby, time, state,did)
values (#{name},#{sex},#{hobby},#{time},#{state},#{did});
update student set name=#{name}, sex=#{sex}, hobby=#{hobby}, time=#{time}, state=#{state},did=#{did} where id=#{id}