1. 使用技术
1.1 后端
- SpringCloud+SpringBoot+maven2+web+MySQL+xml+pagehelper+lombok+jwt+ras+BaseResult
- Eureka 注册中心 + Eureka 客户端+Zuul网关 + 过滤器
1.2 前端
2. 需完成功能
2.1 功能1:用户登录
前端代码
api.js
import axios from 'axios'
import {
Message } from 'element-ui'
axios.defaults.baseURL = 'http://localhost:10010/api'
axios.defaults.timeout = 3000
// 全局ajax错误处理
// axios.interceptors.response.use(response => {
// return response
// }, error => {
// Message.error(error.message)
// return Promise.reject(error)
// })
export function login (user) {
return axios.post('/userservice/user/login', user)
}
export function FindClassesForPageNum (ClassesPi) {
return axios.get('/studentservice/classes/FindClassesForPageNum',{
params:ClassesPi
} )
}
export function Findteacher1list (t1) {
return axios.get('/studentservice/classes/Findteacher1list/' +t1)
}
export function Findteacher2list (t2) {
return axios.get('/studentservice/classes/Findteacher2list/' +t2)
}
export function Findteacher3list (t3) {
return axios.get('/studentservice/classes/Findteacher3list/' + t3)
}
export function addClasses (classes) {
return axios.post('/studentservice/classes/addClasses', classes)
}
export function DeleteClassesByCid (ids) {
return axios.delete('/studentservice/classes/DeleteClassesByCid/' + ids)
}
export function FindByClassesByCid (cid) {
return axios.get('/studentservice/classes/FindByClassesByCid/' + cid)
}
export function UpdateClasses (classes) {
return axios.put('/studentservice/classes/UpdateClasses', classes)
}
export function FindStudentListForPageNum (studentPi) {
return axios.get('/studentservice/student/FindStudentListForPageNum', {
params:studentPi
})
}
export function Findclasses () {
return axios.get('/studentservice/student/Findclasses')
}
export function addStudent (student) {
return axios.post('/studentservice/student/addStudent', student)
}
export function deleteStudentBysid (ids) {
return axios.delete('/studentservice/student/deleteStudentBysid/'+ids)
}
export function FindStudent (sid) {
return axios.get('/studentservice/student/FindStudent/'+sid)
}
后端代码
org.springframework.boot
spring-boot-starter-web
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
tk.mybatis
mapper-spring-boot-starter
2.0.4
mysql
mysql-connector-java
com.czxy.cloud
Exam_common
1.0-SNAPSHOT
server:
port: 9090
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/cloud_db?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
username: root
password: 947411
application:
name: userservice
eureka:
client:
service-url:
defaultZone: http://localhost:10086/eureka/
package com.czxy;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import tk.mybatis.spring.annotation.MapperScan;
@SpringBootApplication
@EnableEurekaClient
@MapperScan(basePackages = "com.czxy.mapper")
public class UserApplicatioon {
public static void main(String[] args) {
SpringApplication.run(UserApplicatioon.class,args);
}
}
package com.czxy.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Id;
import javax.persistence.Table;
@Table(name = "tb_user")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {
@Id
private Integer id;
private String user_name;
private String password;
}
package com.czxy.mapper;
import com.czxy.domain.User;
import tk.mybatis.mapper.common.Mapper;
public interface UserMapper extends Mapper<User> {
}
package com.czxy.service;
import com.czxy.domain.User;
public interface UserService {
User login(User user);
}
package com.czxy.service.impl;
import com.czxy.domain.User;
import com.czxy.mapper.UserMapper;
import com.czxy.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
@Service
@Transactional
public class UserServiceImpl implements UserService {
@Resource
private UserMapper userMapper;
@Override
public User login(User user) {
Example example = new Example(User.class);
Example.Criteria c = example.createCriteria();
c.andEqualTo("user_name",user.getUser_name());
c.andEqualTo("password",user.getPassword());
User bean = userMapper.selectOneByExample(example);
if (bean==null){
return null;
}
return bean;
}
}
package com.czxy.controller;
import com.czxy.domain.User;
import com.czxy.service.UserService;
import com.czxy.vo.BaseResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController
@RequestMapping("/user")
public class UserController {
@Resource
private UserService userService;
@PostMapping("/login")
public BaseResult login(@RequestBody User user){
User loginUser = userService.login(user);
if (loginUser!=null){
return BaseResult.ok("登录成功",loginUser);
}else{
return BaseResult.error("用户名或密码错误");
}
}
}
2.2 功能2:布局
综合案例
2.3 功能3:添加班级
前端代码
后端代码
package com.czxy.domain;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
@Table(name = "tb_class")
public class Classes implements Serializable {
@Id
private Integer cid;
private String cname;
private Integer teacher1_id;
private Teacher teacher1;
private Integer teacher2_id;
private Teacher teacher2;
private Integer teacher3_id;
private Teacher teacher3;
@Override
public String toString() {
return "Classes{" +
"cid=" + cid +
", cname='" + cname + '\'' +
", teacher1_id=" + teacher1_id +
", teacher1=" + teacher1 +
", teacher2_id=" + teacher2_id +
", teacher2=" + teacher2 +
", teacher3_id=" + teacher3_id +
", teacher3=" + teacher3 +
'}';
}
public Classes() {
}
public Integer getCid() {
return cid;
}
public void setCid(Integer cid) {
this.cid = cid;
}
public String getCname() {
return cname;
}
public void setCname(String cname) {
this.cname = cname;
}
public Integer getTeacher1_id() {
return teacher1_id;
}
public void setTeacher1_id(Integer teacher1_id) {
this.teacher1_id = teacher1_id;
}
public Teacher getTeacher1() {
return teacher1;
}
public void setTeacher1(Teacher teacher1) {
this.teacher1 = teacher1;
}
public Integer getTeacher2_id() {
return teacher2_id;
}
public void setTeacher2_id(Integer teacher2_id) {
this.teacher2_id = teacher2_id;
}
public Teacher getTeacher2() {
return teacher2;
}
public void setTeacher2(Teacher teacher2) {
this.teacher2 = teacher2;
}
public Integer getTeacher3_id() {
return teacher3_id;
}
public void setTeacher3_id(Integer teacher3_id) {
this.teacher3_id = teacher3_id;
}
public Teacher getTeacher3() {
return teacher3;
}
public void setTeacher3(Teacher teacher3) {
this.teacher3 = teacher3;
}
}
package com.czxy.domain;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
@Table(name = "tb_teacher")
public class Teacher implements Serializable{
@Id
private Integer tid;
private String tname;
private Integer type;
@Override
public String toString() {
return "Teacher{" +
"tid=" + tid +
", tname='" + tname + '\'' +
", type=" + type +
'}';
}
public Integer getTid() {
return tid;
}
public void setTid(Integer tid) {
this.tid = tid;
}
public String getTname() {
return tname;
}
public void setTname(String tname) {
this.tname = tname;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public Teacher(Integer tid, String tname, Integer type) {
this.tid = tid;
this.tname = tname;
this.type = type;
}
public Teacher() {
}
}
package com.czxy.mapper;
import com.czxy.domain.Classes;
import com.czxy.domain.ClassesPi;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;
public interface ClassesMapper extends Mapper<Classes> {
}
package com.czxy.mapper;
import com.czxy.domain.Teacher;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;
public interface TeacherMapper extends Mapper<Teacher> {
}
package com.czxy.service;
import com.czxy.domain.Classes;
public interface ClassesService {
void addClasses(Classes classes);}
package com.czxy.service.impl;
import com.czxy.domain.Classes;
import com.czxy.mapper.ClassesMapper;
import com.czxy.mapper.StudentMapper;
import com.czxy.mapper.TeacherMapper;
import com.czxy.service.ClassesService;
import javax.annotation.Resource;
@Service
@Transactional
public class ClassesServiceImpl implements ClassesService {
@Resource
private ClassesMapper classesMapper;
@Resource
private TeacherMapper teacherMapper;
@Resource
private StudentMapper studentMapper;
@PostMapping("/addClasses")
public BaseResult addClasses(@RequestBody Classes classes){
classesService.addClasses(classes);
return BaseResult.ok("添加成功");
}
}
package com.czxy.controller;
import com.czxy.domain.Classes;
import javax.annotation.Resource;
@RestController
@RequestMapping("/classes")
public class ClassesController {
@Resource
private ClassesService classesService;
@PostMapping("/addClasses")
public BaseResult addClasses(@RequestBody Classes classes){
classesService.addClasses(classes);
return BaseResult.ok("添加成功");
}
2.4 功能4:班级列表(基本列表 + 分页 + 条件)
前端代码
{
path: '/classesList' }">首页
班级管理
班级列表
查询
{
{
scope.row.teacher1.tname }}
{
{
scope.row.teacher2.tname }}
{
{
scope.row.teacher3.tname }}
编辑
批量删除
后端代码
package com.czxy.controller;
import com.czxy.domain.Classes;
import com.czxy.domain.ClassesPi;
import com.czxy.service.ClassesService;
import com.czxy.vo.BaseResult;
import com.github.pagehelper.PageInfo;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/classes")
public class ClassesController {
@Resource
private ClassesService classesService;
@PostMapping("/addClasses")
public BaseResult addClasses(@RequestBody Classes classes){
classesService.addClasses(classes);
return BaseResult.ok("添加成功");
}
@GetMapping("/FindClassesForPageNum")
public BaseResult FindClassesForPageNum( ClassesPi classesPi){
PageInfo<Classes> pi = classesService.FindClassesForPageNum(classesPi);
for (Classes classes : pi.getList()) {
System.out.println(classes.toString());
}
return BaseResult.ok("查询成功",pi);
}
}
package com.czxy.service;
import com.czxy.domain.Classes;
import com.czxy.domain.ClassesPi;
import com.github.pagehelper.PageInfo;
import java.util.List;
public interface ClassesService {
void addClasses(Classes classes);
PageInfo<Classes> FindClassesForPageNum(ClassesPi classesPi);
}
package com.czxy.mapper;
import com.czxy.domain.Classes;
import com.czxy.domain.ClassesPi;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;
public interface ClassesMapper extends Mapper<Classes> {
@Select(" ")
@Results(id = "c1",value = {
@Result(property = "cid",column = "cid"),
@Result(property = "cname",column = "cname"),
@Result(property = "teacher1_id",column = "teacher1_id"),
@Result(property = "teacher2_id",column = "teacher2_id"),
@Result(property = "teacher3_id",column = "teacher3_id"),
@Result(property = "teacher1",column = "teacher1_id",one = @One(select = "com.czxy.mapper.TeacherMapper.selectByID")),
@Result(property = "teacher2",column = "teacher2_id",one = @One(select = "com.czxy.mapper.TeacherMapper.selectByID")),
@Result(property = "teacher3",column = "teacher3_id",one = @One(select = "com.czxy.mapper.TeacherMapper.selectByID"))
})
List<Classes> FindClassesForPageNum(@Param("classesPi") ClassesPi classesPi);
}
2.5 功能5:批量删除班级
前段代码
{
path: '/classesList' }">首页
班级管理
班级列表
查询
{
{
scope.row.teacher1.tname }}
{
{
scope.row.teacher2.tname }}
{
{
scope.row.teacher3.tname }}
编辑
批量删除
修改班级
后端代码
package com.czxy.controller;
import com.czxy.domain.Classes;
import com.czxy.domain.ClassesPi;
import com.czxy.service.ClassesService;
import com.czxy.vo.BaseResult;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/classes")
public class ClassesController {
@Resource
private ClassesService classesService;
@GetMapping("/FindClassesForPageNum")
public BaseResult FindClassesForPageNum( ClassesPi classesPi){
PageInfo<Classes> pi = classesService.FindClassesForPageNum(classesPi);
for (Classes classes : pi.getList()) {
System.out.println(classes.toString());
}
return BaseResult.ok("查询成功",pi);
}
@PostMapping("/addClasses")
public BaseResult addClasses(@RequestBody Classes classes){
classesService.addClasses(classes);
return BaseResult.ok("添加成功");
}
@DeleteMapping("/DeleteClassesByCid/{ids}")
public BaseResult DeleteClassesByCid(@PathVariable("ids")String ids){
classesService.DeleteClassesByCid(ids);
return BaseResult.ok("删除成功");
}
}
package com.czxy.service;
import com.czxy.domain.Classes;
import com.czxy.domain.ClassesPi;
import com.github.pagehelper.PageInfo;
import java.util.List;
public interface ClassesService {
PageInfo<Classes> FindClassesForPageNum(ClassesPi classesPi);
void addClasses(Classes classes);
void DeleteClassesByCid(String ids);
}
package com.czxy.service.impl;
import com.czxy.domain.Classes;
import com.czxy.domain.ClassesPi;
import com.czxy.mapper.ClassesMapper;
import com.czxy.mapper.StudentMapper;
import com.czxy.mapper.TeacherMapper;
import com.czxy.service.ClassesService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional
public class ClassesServiceImpl implements ClassesService {
@Resource
private ClassesMapper classesMapper;
@Resource
private TeacherMapper teacherMapper;
@Resource
private StudentMapper studentMapper;
@Override
public PageInfo<Classes> FindClassesForPageNum(ClassesPi classesPi) {
PageHelper.startPage(classesPi.getPageNum(),classesPi.getPageSize());
if (classesPi.getCname()!=null && !"" .equals(classesPi.getCname())){
classesPi.setCname("%"+classesPi.getCname()+"%");
}
List<Classes> clist = classesMapper.FindClassesForPageNum(classesPi);
PageInfo<Classes> classesPageInfo = new PageInfo<>(clist);
return classesPageInfo;
}
@Override
public void addClasses(Classes classes) {
classesMapper.insertSelective(classes);
}
@Override
public void DeleteClassesByCid(String ids) {
String[] split = ids.split(",");
for (String s : split) {
classesMapper.deleteByPrimaryKey(Integer.parseInt(s));
}
}
}
2.6 功能6:修改班级
前段代码
{
path: '/classesList' }">首页
班级管理
班级列表
查询
{
{
scope.row.teacher1.tname }}
{
{
scope.row.teacher2.tname }}
{
{
scope.row.teacher3.tname }}
编辑
批量删除
修改班级
后端代码
package com.czxy.controller;
import com.czxy.domain.Classes;
import com.czxy.domain.ClassesPi;
import com.czxy.domain.Teacher;
import com.czxy.service.ClassesService;
import com.czxy.vo.BaseResult;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/classes")
public class ClassesController {
@Resource
private ClassesService classesService;
@GetMapping("/FindClassesForPageNum")
public BaseResult FindClassesForPageNum( ClassesPi classesPi){
PageInfo<Classes> pi = classesService.FindClassesForPageNum(classesPi);
for (Classes classes : pi.getList()) {
System.out.println(classes.toString());
}
return BaseResult.ok("查询成功",pi);
}
@GetMapping("/Findteacher1list/{t1}")
public BaseResult Findteacher1list(@PathVariable("t1")Integer tid){
List<Teacher> tlist = classesService.Findteacher1list(tid);
System.out.println(tlist);
return BaseResult.ok("查询成功",tlist);
}
@GetMapping("/Findteacher2list/{t2}")
public BaseResult Findteacher2list(@PathVariable("t2")Integer tid){
List<Teacher> tlist = classesService.Findteacher2list(tid);
System.out.println(tlist);
return BaseResult.ok("查询成功",tlist);
}
@GetMapping("/Findteacher3list/{t3}")
public BaseResult Findteacher3list(@PathVariable("t3")Integer tid){
List<Teacher> tlist = classesService.Findteacher3list(tid);
System.out.println(tlist);
return BaseResult.ok("查询成功",tlist);
}
@PostMapping("/addClasses")
public BaseResult addClasses(@RequestBody Classes classes){
classesService.addClasses(classes);
return BaseResult.ok("添加成功");
}
@DeleteMapping("/DeleteClassesByCid/{ids}")
public BaseResult DeleteClassesByCid(@PathVariable("ids")String ids){
classesService.DeleteClassesByCid(ids);
return BaseResult.ok("删除成功");
}
@GetMapping("/FindByClassesByCid/{cid}")
public BaseResult FindByClassesByCid(@PathVariable("cid") Integer cid){
Classes classes = classesService.FindByClassesByCid(cid);
return BaseResult.ok("查询成功",classes);
}
}
package com.czxy.service;
import com.czxy.domain.Classes;
import com.czxy.domain.ClassesPi;
import com.czxy.domain.Teacher;
import com.github.pagehelper.PageInfo;
import java.util.List;
public interface ClassesService {
PageInfo<Classes> FindClassesForPageNum(ClassesPi classesPi);
List<Teacher> Findteacher1list(Integer tid);
List<Teacher> Findteacher2list(Integer tid);
List<Teacher> Findteacher3list(Integer tid);
void addClasses(Classes classes);
void DeleteClassesByCid(String ids);
Classes FindByClassesByCid(Integer cid);
}
package com.czxy.service.impl;
import com.czxy.domain.Classes;
import com.czxy.domain.ClassesPi;
import com.czxy.domain.Teacher;
import com.czxy.mapper.ClassesMapper;
import com.czxy.mapper.StudentMapper;
import com.czxy.mapper.TeacherMapper;
import com.czxy.service.ClassesService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional
public class ClassesServiceImpl implements ClassesService {
@Resource
private ClassesMapper classesMapper;
@Resource
private TeacherMapper teacherMapper;
@Resource
private StudentMapper studentMapper;
@Override
public PageInfo<Classes> FindClassesForPageNum(ClassesPi classesPi) {
PageHelper.startPage(classesPi.getPageNum(),classesPi.getPageSize());
if (classesPi.getCname()!=null && !"" .equals(classesPi.getCname())){
classesPi.setCname("%"+classesPi.getCname()+"%");
}
List<Classes> clist = classesMapper.FindClassesForPageNum(classesPi);
PageInfo<Classes> classesPageInfo = new PageInfo<>(clist);
return classesPageInfo;
}
@Override
public List<Teacher> Findteacher1list(Integer tid) {
List<Teacher> tlist = teacherMapper.Findteacher1list(tid);
return tlist;
}
@Override
public List<Teacher> Findteacher2list(Integer tid) {
List<Teacher> tlist = teacherMapper.Findteacher1list(tid);
return tlist;
}
@Override
public List<Teacher> Findteacher3list(Integer tid) {
List<Teacher> tlist = teacherMapper.Findteacher1list(tid);
return tlist;
}
@Override
public void addClasses(Classes classes) {
classesMapper.insertSelective(classes);
}
@Override
public void DeleteClassesByCid(String ids) {
String[] split = ids.split(",");
for (String s : split) {
classesMapper.deleteByPrimaryKey(Integer.parseInt(s));
}
}
@Override
public Classes FindByClassesByCid(Integer cid) {
Classes classes = classesMapper.FindByClassesByCid(cid);
return classes;
}
}
package com.czxy.mapper;
import com.czxy.domain.Classes;
import com.czxy.domain.ClassesPi;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;
public interface ClassesMapper extends Mapper<Classes> {
@Select(" ")
@Results(id = "c1",value = {
@Result(property = "cid",column = "cid"),
@Result(property = "cname",column = "cname"),
@Result(property = "teacher1_id",column = "teacher1_id"),
@Result(property = "teacher2_id",column = "teacher2_id"),
@Result(property = "teacher3_id",column = "teacher3_id"),
@Result(property = "teacher1",column = "teacher1_id",one = @One(select = "com.czxy.mapper.TeacherMapper.selectByID")),
@Result(property = "teacher2",column = "teacher2_id",one = @One(select = "com.czxy.mapper.TeacherMapper.selectByID")),
@Result(property = "teacher3",column = "teacher3_id",one = @One(select = "com.czxy.mapper.TeacherMapper.selectByID"))
})
List<Classes> FindClassesForPageNum(@Param("classesPi") ClassesPi classesPi);
@Select("select * from tb_class where cid=#{cid}")
@ResultMap( "c1")
Classes FindByClassesByCid(@Param("cid") Integer cid);
}
2.7 功能7:添加学生
前端代码
男
女
添加学生
后端代码
package com.czxy.domain;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
@Table(name = "tb_student")
public class Student implements Serializable {
@Id
private Integer sid;
private String sname;
private Integer gender;
private Integer age;
private Double salary;
@Column(name = "`desc`")
private String desc;
private Integer class_id;
private Classes classes;
@Override
public String toString() {
return "Student{" +
"sid=" + sid +
", sname='" + sname + '\'' +
", gender=" + gender +
", age=" + age +
", salary=" + salary +
", desc='" + desc + '\'' +
", class_id=" + class_id +
", classes=" + classes +
'}';
}
public Integer getSid() {
return sid;
}
public void setSid(Integer sid) {
this.sid = sid;
}
public String getSname() {
return sname;
}
public void setSname(String sname) {
this.sname = sname;
}
public Integer getGender() {
return gender;
}
public void setGender(Integer gender) {
this.gender = gender;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Double getSalary() {
return salary;
}
public void setSalary(Double salary) {
this.salary = salary;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public Integer getClass_id() {
return class_id;
}
public void setClass_id(Integer class_id) {
this.class_id = class_id;
}
public Classes getClasses() {
return classes;
}
public void setClasses(Classes classes) {
this.classes = classes;
}
public Student(Integer sid, String sname, Integer gender, Integer age, Double salary, String desc, Integer class_id, Classes classes) {
this.sid = sid;
this.sname = sname;
this.gender = gender;
this.age = age;
this.salary = salary;
this.desc = desc;
this.class_id = class_id;
this.classes = classes;
}
public Student() {
}
}
package com.czxy.mapper;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;
public interface StudentMapper extends Mapper<Student> {
}
package com.czxy.service;
import com.czxy.domain.Student;
import java.util.List;
public interface StudentService {
void addStudent(Student student);
}
package com.czxy.service.impl;
import com.czxy.domain.Student;
import com.czxy.mapper.ClassesMapper;
import com.czxy.mapper.StudentMapper;
import com.czxy.mapper.TeacherMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
@Service
@Transactional
public class StudentServiceImpl implements StudentService {
@Resource
private ClassesMapper classesMapper;
@Resource
private TeacherMapper teacherMapper;
@Resource
private StudentMapper studentMapper;
@Override
public void addStudent(Student student) {
studentMapper.insertSelective(student);
}
package com.czxy.controller;
import com.czxy.domain.Student;
import com.czxy.service.StudentService;
import com.czxy.vo.BaseResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@RestController
@RequestMapping("/student")
public class StudentController {
@Resource
private StudentService studentService;
@PostMapping("/addStudent")
private BaseResult addStudent(@RequestBody Student student){
studentService.addStudent(student);
return BaseResult.ok("添加成功");
}
}
2.8 功能8:学生列表(基本列表+分页+条件)
前端代码
{
path: '/studentList' }">首页
学生管理
学生列表
{
{
scope.row.gender==1 ? "男":"女"}}
{
{
scope.row.classes.cname }}
{
{
scope.row.classes.teacher1.tname }}
{
{
scope.row.classes.teacher2.tname }}
{
{
scope.row.classes.teacher3.tname }}
查看
批量删除
后端代码
package com.czxy.controller;
import com.czxy.domain.Classes;
import com.czxy.domain.Student;
import com.czxy.domain.StudentPi;
import com.czxy.service.StudentService;
import com.czxy.vo.BaseResult;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/student")
public class StudentController {
@Resource
private StudentService studentService;
@GetMapping("/FindStudentListForPageNum")
public BaseResult FindStudentListForPageNum( StudentPi studentPi){
PageInfo<Student> pageInfo = studentService.FindStudentListForPageNum(studentPi);
return BaseResult.ok("查询成功",pageInfo);
}
@PostMapping("/addStudent")
private BaseResult addStudent(@RequestBody Student student){
studentService.addStudent(student);
return BaseResult.ok("添加成功");
}
}
package com.czxy.service;
import com.czxy.domain.Classes;
import com.czxy.domain.Student;
import com.czxy.domain.StudentPi;
import com.github.pagehelper.PageInfo;
import java.util.List;
public interface StudentService {
PageInfo<Student> FindStudentListForPageNum(StudentPi studentPi);
void addStudent(Student student);
}
package com.czxy.service.impl;
import com.czxy.domain.Classes;
import com.czxy.domain.Student;
import com.czxy.domain.StudentPi;
import com.czxy.mapper.ClassesMapper;
import com.czxy.mapper.StudentMapper;
import com.czxy.mapper.TeacherMapper;
import com.czxy.service.StudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional
public class StudentServiceImpl implements StudentService {
@Resource
private ClassesMapper classesMapper;
@Resource
private TeacherMapper teacherMapper;
@Resource
private StudentMapper studentMapper;
@Override
public PageInfo<Student> FindStudentListForPageNum(StudentPi studentPi) {
PageHelper.startPage(studentPi.getPageNum(),studentPi.getPageSize());
if (studentPi.getSname() != null && !"" .equals(studentPi.getSname())){
studentPi.setSname("%"+studentPi.getSname()+"%");
}
List<Student> slist = studentMapper.FindStudentListForPageNum(studentPi);
PageInfo<Student> pageInfo = new PageInfo<>(slist);
return pageInfo;
}
@Override
public void addStudent(Student student) {
studentMapper.insertSelective(student);
}
package com.czxy.mapper;
import com.czxy.domain.Student;
import com.czxy.domain.StudentPi;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;
public interface StudentMapper extends Mapper<Student> {
@Select("")
@Results(id = "s1",value = {
@Result(property = "class_id",column = "class_id"),
@Result(property = "classes",column = "class_id",one = @One(select = "com.czxy.mapper.ClassesMapper.FindByClassesByCid"))
})
List<Student> FindStudentListForPageNum(@Param("studentPi") StudentPi studentPi);
}
2.9 功能9:批量删除
前段代码
{
path: '/studentList' }">首页
学生管理
学生列表
{
{
scope.row.gender==1 ? "男":"女"}}
{
{
scope.row.classes.cname }}
{
{
scope.row.classes.teacher1.tname }}
{
{
scope.row.classes.teacher2.tname }}
{
{
scope.row.classes.teacher3.tname }}
查看
批量删除
后端代码
package com.czxy.controller;
import com.czxy.domain.Classes;
import com.czxy.domain.Student;
import com.czxy.domain.StudentPi;
import com.czxy.service.StudentService;
import com.czxy.vo.BaseResult;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/student")
public class StudentController {
@Resource
private StudentService studentService;
@GetMapping("/FindStudentListForPageNum")
public BaseResult FindStudentListForPageNum( StudentPi studentPi){
PageInfo<Student> pageInfo = studentService.FindStudentListForPageNum(studentPi);
return BaseResult.ok("查询成功",pageInfo);
}
@PostMapping("/addStudent")
private BaseResult addStudent(@RequestBody Student student){
studentService.addStudent(student);
return BaseResult.ok("添加成功");
}
@DeleteMapping("/deleteStudentBysid/{ids}")
public BaseResult deleteStudentBysid(@PathVariable("ids") String ids){
studentService.deleteStudentBysid(ids);
return BaseResult.ok("删除成功");
}
}
package com.czxy.service;
import com.czxy.domain.Classes;
import com.czxy.domain.Student;
import com.czxy.domain.StudentPi;
import com.github.pagehelper.PageInfo;
import java.util.List;
public interface StudentService {
PageInfo<Student> FindStudentListForPageNum(StudentPi studentPi);
void addStudent(Student student);
void deleteStudentBysid(String ids);
}
package com.czxy.service.impl;
import com.czxy.domain.Classes;
import com.czxy.domain.Student;
import com.czxy.domain.StudentPi;
import com.czxy.mapper.ClassesMapper;
import com.czxy.mapper.StudentMapper;
import com.czxy.mapper.TeacherMapper;
import com.czxy.service.StudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional
public class StudentServiceImpl implements StudentService {
@Resource
private ClassesMapper classesMapper;
@Resource
private TeacherMapper teacherMapper;
@Resource
private StudentMapper studentMapper;
@Override
public PageInfo<Student> FindStudentListForPageNum(StudentPi studentPi) {
PageHelper.startPage(studentPi.getPageNum(),studentPi.getPageSize());
if (studentPi.getSname() != null && !"" .equals(studentPi.getSname())){
studentPi.setSname("%"+studentPi.getSname()+"%");
}
List<Student> slist = studentMapper.FindStudentListForPageNum(studentPi);
PageInfo<Student> pageInfo = new PageInfo<>(slist);
return pageInfo;
}
@Override
public void addStudent(Student student) {
studentMapper.insertSelective(student);
}
@Override
public void deleteStudentBysid(String ids) {
String[] split = ids.split(",");
for (String s : split) {
studentMapper.deleteByPrimaryKey(Integer.parseInt(s));
}
}
2.10 功能10:修改学生
前端代码
{
path: '/studentList' }">首页
学生管理
学生列表
{
{
scope.row.gender==1 ? "男":"女"}}
{
{
scope.row.classes.cname }}
{
{
scope.row.classes.teacher1.tname }}
{
{
scope.row.classes.teacher2.tname }}
{
{
scope.row.classes.teacher3.tname }}
查看
男
女
取 消
确 定
批量删除
后端代码
package com.czxy.controller;
import com.czxy.domain.Classes;
import com.czxy.domain.Student;
import com.czxy.domain.StudentPi;
import com.czxy.service.StudentService;
import com.czxy.vo.BaseResult;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/student")
public class StudentController {
@Resource
private StudentService studentService;
@GetMapping("/FindStudentListForPageNum")
public BaseResult FindStudentListForPageNum( StudentPi studentPi){
PageInfo<Student> pageInfo = studentService.FindStudentListForPageNum(studentPi);
return BaseResult.ok("查询成功",pageInfo);
}
@GetMapping("/Findclasses")
public BaseResult Findclasses(){
List<Classes> clist = studentService.Findclasses();
return BaseResult.ok("查询成功",clist);
}
@PostMapping("/addStudent")
private BaseResult addStudent(@RequestBody Student student){
studentService.addStudent(student);
return BaseResult.ok("添加成功");
}
@DeleteMapping("/deleteStudentBysid/{ids}")
public BaseResult deleteStudentBysid(@PathVariable("ids") String ids){
studentService.deleteStudentBysid(ids);
return BaseResult.ok("删除成功");
}
@GetMapping("/FindStudent/{sid}")
public BaseResult FindStudent(@PathVariable("sid") Integer sid){
Student student = studentService.FindStudent(sid);
return BaseResult.ok("查询成功",student);
}
}
package com.czxy.service;
import com.czxy.domain.Classes;
import com.czxy.domain.Student;
import com.czxy.domain.StudentPi;
import com.github.pagehelper.PageInfo;
import java.util.List;
public interface StudentService {
PageInfo<Student> FindStudentListForPageNum(StudentPi studentPi);
List<Classes> Findclasses();
void addStudent(Student student);
void deleteStudentBysid(String ids);
Student FindStudent(Integer sid);
}
package com.czxy.service.impl;
import com.czxy.domain.Classes;
import com.czxy.domain.Student;
import com.czxy.domain.StudentPi;
import com.czxy.mapper.ClassesMapper;
import com.czxy.mapper.StudentMapper;
import com.czxy.mapper.TeacherMapper;
import com.czxy.service.StudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional
public class StudentServiceImpl implements StudentService {
@Resource
private ClassesMapper classesMapper;
@Resource
private TeacherMapper teacherMapper;
@Resource
private StudentMapper studentMapper;
@Override
public PageInfo<Student> FindStudentListForPageNum(StudentPi studentPi) {
PageHelper.startPage(studentPi.getPageNum(),studentPi.getPageSize());
if (studentPi.getSname() != null && !"" .equals(studentPi.getSname())){
studentPi.setSname("%"+studentPi.getSname()+"%");
}
List<Student> slist = studentMapper.FindStudentListForPageNum(studentPi);
PageInfo<Student> pageInfo = new PageInfo<>(slist);
return pageInfo;
}
@Override
public List<Classes> Findclasses() {
List<Classes> classes = classesMapper.selectAll();
return classes;
}
@Override
public void addStudent(Student student) {
studentMapper.insertSelective(student);
}
@Override
public void deleteStudentBysid(String ids) {
String[] split = ids.split(",");
for (String s : split) {
studentMapper.deleteByPrimaryKey(Integer.parseInt(s));
}
}
@Override
public Student FindStudent(Integer sid) {
Student student = studentMapper.FindStudent(sid);
return student;
}
}
package com.czxy.mapper;
import com.czxy.domain.Student;
import com.czxy.domain.StudentPi;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;
public interface StudentMapper extends Mapper<Student> {
@Select("")
@Results(id = "s1",value = {
@Result(property = "class_id",column = "class_id"),
@Result(property = "classes",column = "class_id",one = @One(select = "com.czxy.mapper.ClassesMapper.FindByClassesByCid"))
})
List<Student> FindStudentListForPageNum(@Param("studentPi") StudentPi studentPi);
@Select("select * from tb_student where sid=#{sid}")
@ResultMap("s1")
Student FindStudent(@Param("sid") Integer sid);
}