html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>教师信息</title>
<script src="./js/vue.js"></script>
<script src="./js/axios-0.18.0.js"></script><script src="js/jquery.min.js"></script>
<script src="js/element.js"></script>
<script src="js/axios-0.18.0.js"></script>
<link rel="stylesheet" href="element-ui/index.css">
<script src="./element-ui/index.js"></script>
<style>
.el-header{
background: #409EFF;
}
.el-aside {
color: #333;}
</style>
</head>
<body>
<div id="app" align="center">
<el-menu
:default-active="activeIndex2"
class="el-menu-demo"
mode="horizontal"
@select="handleSelect"
background-color="#545c64"
text-color="#fff"
active-text-color="#ffd04b">
<el-menu-item index="1">处理中心</el-menu-item>
<el-submenu index="2">
<template slot="title">我的工作台</template>
<el-menu-item index="2-1">教师详细信息</el-menu-item>
<el-menu-item index="2-2">教学评价</el-menu-item>
<el-menu-item index="2-3">教学反馈</el-menu-item>
</el-submenu>
<el-menu-item index="3" disabled>消息中心</el-menu-item>
</el-menu>
<el-container style="height: 500px; border: 1px solid #eee">
<el-aside width="200px" style="background-color: rgb(238, 241, 246)">
<el-menu :default-openeds="['1', '3']">
<el-submenu index="1">
<template slot="title"><i class="el-icon-message"></i>专业管理</template>
<el-menu-item-group>
<template slot="title">分组一</template>
<el-menu-item index="1-1">选项1</el-menu-item>
<el-menu-item index="1-2">选项2</el-menu-item>
</el-menu-item-group>
<el-menu-item-group title="分组2">
<el-menu-item index="1-3">选项3</el-menu-item>
</el-menu-item-group>
<el-submenu index="1-4">
<template slot="title">选项4</template>
<el-menu-item index="1-4-1">选项4-1</el-menu-item>
</el-submenu>
</el-submenu>
<el-submenu index="2">
<template slot="title"><i class="el-icon-menu"></i>班级管理</template>
<el-menu-item-group>
<template slot="title">分组一</template>
<el-menu-item index="2-1">选项1</el-menu-item>
<el-menu-item index="2-2">选项2</el-menu-item>
</el-menu-item-group>
<el-menu-item-group title="分组2">
<el-menu-item index="2-3">选项3</el-menu-item>
</el-menu-item-group>
<el-submenu index="2-4">
<template slot="title">选项4</template>
<el-menu-item index="2-4-1">选项4-1</el-menu-item>
</el-submenu>
</el-submenu>
<el-submenu index="3">
<template slot="title"><i class="el-icon-setting"></i>学生管理</template>
<el-menu-item-group>
<template slot="title">分组一</template>
<el-menu-item index="3-1">选项1</el-menu-item>
<el-menu-item index="3-2">选项2</el-menu-item>
</el-menu-item-group>
<el-menu-item-group title="分组2">
<el-menu-item index="3-3">选项3</el-menu-item>
</el-menu-item-group>
<el-submenu index="3-4">
<template slot="title">选项4</template>
<el-menu-item index="3-4-1">选项4-1</el-menu-item>
</el-submenu>
</el-submenu>
<el-submenu index="1">
<template slot="title"><i class="el-icon-message"></i>教师管理</template>
<el-menu-item-group>
<template slot="title">分组一</template>
<el-menu-item index="1-1">选项1</el-menu-item>
<el-menu-item index="1-2">选项2</el-menu-item>
</el-menu-item-group>
<el-menu-item-group title="分组2">
<el-menu-item index="1-3">选项3</el-menu-item>
</el-menu-item-group>
<el-submenu index="1-4">
<template slot="title">选项4</template>
<el-menu-item index="1-4-1">选项4-1</el-menu-item>
</el-submenu>
</el-submenu>
<el-submenu index="1">
<template slot="title"><i class="el-icon-message"></i>课程管理</template>
<el-menu-item-group>
<template slot="title">分组一</template>
<el-menu-item index="1-1">选项1</el-menu-item>
<el-menu-item index="1-2">选项2</el-menu-item>
</el-menu-item-group>
<el-menu-item-group title="分组2">
<el-menu-item index="1-3">选项3</el-menu-item>
</el-menu-item-group>
<el-submenu index="1-4">
<template slot="title">选项4</template>
<el-menu-item index="1-4-1">选项4-1</el-menu-item>
</el-submenu>
</el-submenu>
</el-menu>
</el-aside>
<el-container>
<el-header >
<h1 align="center"></h1>
教师列表展示
</el-header>
<!--<h1 align="center"></h1>-->
<!--<el-container>-->
<!-- <el-header>教师信息列表展示</el-header>-->
<!--</el-container>-->
<el-main>
<el-table :data="tableData">
<el-table-column prop="id" label="工号" width="140">
</el-table-column>
<el-table-column prop="name" label="姓名" width="120">
</el-table-column>
<el-table-column prop="email" label="邮箱">
</el-table-column>
</el-table-column>
<el-table-column prop="department" label="部门">
</el-table-column>
</el-table-column>
<el-table-column prop="password" label="密码">
</el-table-column>
</el-table-column>
<el-table-column label="操作" width="200">
<div align="center" style="display: flex; justify-content: center;">
<a href="teacher_edit.html">
<el-button type="primary" icon="el-icon-edit" size="medium" round>修改</el-button>
<a href="teacher_delete2.html">
<el-button type="primary" icon="el-icon-delete" size="medium" round>删除</el-button></a>
</a></div>
</el-table-column>
</el-table>
</el-main>
</el-container>
</el-container>
<div>
<el-switch v-model="value">
</el-switch>
<p align="center">
<el-pagination
layout="total, sizes, prev, pager, next, jumper"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-sizes="[3, 5, 10, 20]"
:page-size="pageSize"
:total="total">
</el-pagination>
</p>
</div>
</div>
<script>
new Vue({
el: "#app",
data() {
return {
tableData: []
}
},
mounted(){
//peotfindAll
axios.get('/teacher').then(res=>{
if(res.data.code==1){
this.tableData = res.data.data;
}
}).catch(r=>{
console.error(r);
});
},
})
</script>
</body>
</html>
TeacherController
package com.example.teacher.controller;
import com.example.teacher.pojo.Pagebean;
import com.example.teacher.pojo.Result;
import com.example.teacher.pojo.Teacher;
import com.example.teacher.service.TeacherService;
import com.sun.istack.logging.Logger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@Slf4j
@RestController
public class TeacherController {
@Autowired
private TeacherService teacherService;
//查询
@GetMapping("/teacher")
public Result findAllJson1() {
return Result.success(teacherService.findAll());
}
@DeleteMapping("/teacher/{id}")
public void deleteTeacher(@PathVariable("id") Integer id) {
teacherService.deleteTeacher(id);
}
@GetMapping("/teachers/{id}")
public Result teacherfindById(@PathVariable("id") Integer id) { // 注意@PathVariable的使用和参数列表后面的大括号
return Result.success(teacherService.teacherfindById(id)); // 假设peotService有一个名为peotfindById的方法
}
@PutMapping("/teacherup")
public Result updataTeacher(@RequestBody Teacher teacher) {
boolean r = teacherService.updataTeacher(teacher);
if (r) {
return Result.success();
} else {
return Result.error("更新失败");
}
}
@PostMapping("/teacherup")
public Result insertTeacher(@RequestBody Teacher teacher) {
boolean result = teacherService.insertTeacher(teacher);
if (result) {
return Result.success();
} else {
return Result.error("添加失败");
}
}
@GetMapping("/teacher/{page}/{pageSize}")
public Result findAll(@PathVariable Integer page,
@PathVariable Integer pageSize){
Pagebean pageBean = teacherService.list(page,pageSize);
return Result.success(pageBean);
}
}
TeacherMapper
package com.example.teacher.mapper;
import com.example.teacher.pojo.Teacher;
import org.apache.ibatis.annotations.*;
import java.util.List;
@Mapper
public interface TeacherMapper {
@Select("select * from teacher")
public List<Teacher> findAll();
@Delete("delete from teacher where id =#{id}")
public int deleteTeacher(Integer id);
@Select("select * from teacher where id=#{id}")
public Teacher teacherfindById(Integer ID);
@Update("updata teacher set name=#{name},gender=#{gender},emil=#{emil},department=#{department},password=#{password} where id=#{id}")
public boolean updataTeacher(Teacher teacher);
@Insert("insert into teacher(name,gender,emil,department,password)values(#{name},#{gender}.#{emil},#{department},#{password}")
public int insertTeacher(Teacher teacher);
@Select("select * from teacher")
public List<Teacher> list();
}
Service
package com.example.teacher.service.impl;
import com.example.teacher.mapper.TeacherMapper;
import com.example.teacher.pojo.Pagebean;
import com.example.teacher.pojo.Teacher;
import com.example.teacher.service.TeacherService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class TeacherServiceImpl implements TeacherService {
@Autowired
private TeacherMapper teacherMapper;
@Override
public List<Teacher> findAll() {
return teacherMapper.findAll();
}
@Override
public int deleteTeacher(Integer id) {
return teacherMapper.deleteTeacher(id);
}
@Override
public Teacher teacherfindById(Integer id) {
return teacherMapper.teacherfindById(id);
}
@Override
public boolean updataTeacher(Teacher teacher) {
return teacherMapper.updataTeacher(teacher);
}
@Override
public boolean insertTeacher(Teacher teacher) {
int result = teacherMapper.insertTeacher(teacher);
return result == 1;
}
@Override
public Pagebean list(Integer page, Integer pageSize) {
//问:PageHelper.startPage(page, pageSize); 请解释一下
// 设置分页参数
PageHelper.startPage(page, pageSize);
// 执行分页查询
List<Teacher> teacherList = teacherMapper.list();
// 获取分页结果
PageInfo<Teacher> p = new PageInfo<>(teacherList);
//封装PageBean
Pagebean pageBean = new Pagebean(p.getTotal(), p.getList());
return pageBean;
}
}
package com.example.teacher.service;
import com.example.teacher.pojo.Pagebean;
import com.example.teacher.pojo.Teacher;
import org.springframework.context.annotation.Bean;
import java.util.List;
public interface TeacherService {
public List<Teacher> findAll();
public int deleteTeacher(Integer id);
public Teacher teacherfindById(Integer id);
public boolean updataTeacher(Teacher teacher);
public boolean insertTeacher(Teacher teacher);
public Pagebean list(Integer page, Integer pageSize);
}
login.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="./js/vue.js"></script>
<script src="./js/axios-0.18.0.js"></script><script src="js/jquery.min.js"></script>
<script src="js/element.js"></script>
<script src="js/axios-0.18.0.js"></script>
<link rel="stylesheet" href="element-ui/index.css">
<script src="./element-ui/index.js"></script>
<link rel="stylesheet"href="reset.css">
<link rel="stylesheet"href="login.css">
</head>
<body>
<div class="wrap">
<h1>教师管理系统</h1>
<form action="" method="">
<div class="input-group">
<i class="icon-user fa fa-user"></i>
<input type="text" name="" class="form-control" placeholder="请输入账号" />
</div>
<div class="input-group">
<i class="icon-user fa fa-lock"></i>
<input type="text" name="" class="form-control" placeholder="请输入密码" />
</div>
<div class="input-group btn-group">
<button >登录</button>
</div>
</form>
<p>@zm</p>
</div>
</body>
</html>