此时我们已经做好了登录模块接下来可以做一下学生管理系统的增删改查操作
首先,我们应当有一个登录成功后的主界面
在webapp下新建
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<script src="js/vue.js">script>
<script src="js/jquery.min.js">script>
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<script src="https://unpkg.com/element-ui/lib/index.js">script>
<style>
* {
margin: 0;
padding: 0;
}
.el-header {
background-color: #B3C0D1;
color: #333;
line-height: 60px;
}
.el-tabs__header {
margin: 0;
}
.el-aside {
color: #333;
height: 640px;
}
.el-main {
padding: 0;
}
style>
head>
<body>
<div id="app">
<el-container style="height: 500px; border: 1px solid #eee">
<el-header style="text-align: right; font-size: 12px">
<span>欢迎用户:span>
<el-dropdown>
<i class="el-icon-setting" style="margin-right: 15px">i>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item>查看el-dropdown-item>
<el-dropdown-item>新增el-dropdown-item>
<el-dropdown-item>删除el-dropdown-item>
el-dropdown-menu>
el-dropdown>
<span>{{userInfo.ename}}span>
el-header>
<el-container>
<el-aside width="200px" style="background-color: rgb(238, 241, 246)">
<el-menu>
<el-submenu v-for="p in permissionArr" :index="p.id">
<template slot="title"><i :class="p.icon">i>{{p.title}}template>
<el-menu-item-group>
<el-menu-item v-for="sp in p.subMenu" :index="sp.id"
@click="addTabs(sp)">
{{sp.title}}
el-menu-item>
el-menu-item-group>
el-submenu>
el-menu>
el-aside>
<el-main>
<el-tabs v-model="editableTabsValue" type="card" closable @tab-remove="removeTab">
<el-tab-pane
key="asd"
label="欢迎页"
name="asd"
>
<iframe src="http://www.douyu.com" style="border: none;width: 99%;height: 600px;">iframe>
el-tab-pane>
<el-tab-pane
v-for="(item, index) in editableTabs"
:key="item.id"
:label="item.title"
:name="item.id"
>
<iframe :src="item.content" style="border: none;width: 99%;height: 600px;">iframe>
el-tab-pane>
el-tabs>
el-main>
el-container>
el-container>
div>
<script>
$.get("/ssm/emp/getInfo", function (backData) {
app.userInfo = backData.data.userInfo
app.permissionArr = backData.data.permissionInfo
})
var app = new Vue({
el: "#app",
data: {
tableData: [],
editableTabsValue: "asd",
editableTabs: [],
userInfo: {},
permissionArr: [],
},
methods: {
addTabs(data) {
if (this.editableTabs.indexOf(data) < 0) {
console.log(this.editableTabs)
this.editableTabs.push(data);
}
this.editableTabsValue = data.id;
},
removeTab(targetName) {
let tabs = this.editableTabs;
let activeName = this.editableTabsValue;
if (activeName === targetName) {
tabs.forEach((tab, index) => {
if (tab.id === targetName) {
let nextTab = tabs[index + 1] || tabs[index - 1];
if (nextTab) {
activeName = nextTab.id;
}
}
});
}
this.editableTabsValue = activeName;
this.editableTabs = tabs.filter(tab => tab.id !== targetName);
},
}
})
script>
body>
html>
在这个页面中,我们点击业务管理中的学生管理,就可以在右侧访问学生管理的界面。其他模块可以自行添加
进入学生管理页面,我们首先要在页面中展示学生信息
先在webapp下新建views/student/list.html
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<script src="../../js/vue.js">script>
<script src="../../js/jquery.min.js">script>
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<script src="https://unpkg.com/element-ui/lib/index.js">script>
head>
<body>
<div id="app">
<el-input v-model="queryInfo.name" placeholder="请输入名字" style="display: inline-block;width: 200px;">el-input>
<el-input v-model="queryInfo.minAge" placeholder="请输入最小年龄"
style="display: inline-block;width: 200px;">el-input>
<el-input v-model="queryInfo.maxAge" placeholder="请输入最大年龄"
style="display: inline-block;width: 200px;">el-input>
<el-button type="primary" icon="el-icon-search" @click="searchData()">搜索el-button>
<el-button type="primary">上传<i class="el-icon-upload el-icon--right">i>el-button>
<el-button type="primary">下载<i class="el-icon-download el-icon--right">i>el-button>
<el-button type="success" round @click="openAddStu()">添加学生el-button>
<el-table
:data="tableData"
border
style="width: 100%">
<el-table-column
prop="id"
label="编号"
>
el-table-column>
<el-table-column
prop="name"
label="姓名"
>
el-table-column>
<el-table-column
prop="age"
label="年龄">
el-table-column>
<el-table-column
prop="address"
label="地址">
el-table-column>
<el-table-column
label="班级">
<template slot-scope="scope">
{{scope.row.grade.gname}}
template>
el-table-column>
<el-table-column
label="头像">
<template slot-scope="scope">
<img v-bind:src="scope.row.headImg" width="50px"/>
template>
el-table-column>
<el-table-column
label="操作">
<template slot-scope="scope">
<el-button @click="deleteStudent(scope.row.id)" type="danger" icon="el-icon-delete" circle>el-button>
<el-button @click="openUpdateStu(scope.row.id)" type="primary" icon="el-icon-edit" circle>el-button>
template>
el-table-column>
el-table>
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="1"
:page-sizes="[5, 10, 15, 20]"
:page-size="5"
layout="total, sizes, prev, pager, next, jumper"
:total="t">
el-pagination>
<el-dialog :title="titlename" :visible.sync="dialogFormVisible">
<el-form :model="stuInfo" :rules="rules" ref="stuInfo">
<el-form-item label="学生姓名" prop="sname">
<el-input v-model="stuInfo.sname" autocomplete="off">el-input>
el-form-item>
<el-form-item label="学生年龄" prop="sage">
<el-input v-model="stuInfo.sage" autocomplete="off">el-input>
el-form-item>
<el-form-item label="学生地址" prop="saddress">
<el-input v-model="stuInfo.saddress" autocomplete="off">el-input>
el-form-item>
<el-form-item label="学生班级" prop="gid">
<el-select placeholder="请选择班级" v-model="stuInfo.gid">
<el-option v-for="g in gradeArr" :label="g.gname" :value="g.id">el-option>
el-select>
el-form-item>
el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible = false">取 消el-button>
<el-button type="primary" @click="addStudent()">确 定el-button>
div>
el-dialog>
div>
<script>
var app = new Vue({
el: "#app",
data: {
titlename: "",
dialogFormVisible: false,
queryInfo: {},
stuInfo: {},
tableData: [],
gradeArr: [],
size: 5,
t: 100,
rules: {
sname: [
{required: true, message: '请输入姓名', trigger: 'blur'},
],
sage: [
{required: true, message: '请输入年龄', trigger: 'blur'},
],
saddress: [
{required: true, message: '请输入地址', trigger: 'blur'},
],
gid: [
{required: true, message: '请选择班级', trigger: 'blur'},
]
}
},
methods: {
openUpdateStu(id) {
//请求班级的数据
$.get("/ssm/grade/list", function (backData) {
app.gradeArr = backData.data
$.get("/ssm/stu/get/" + id, function (backData) {
app.stuInfo = backData.data
app.titlename = "修改学生"
app.dialogFormVisible = true
})
})
},
addStudent() {
this.$refs["stuInfo"].validate((valid) => {
if (valid) {
var path = app.titlename === "添加学生" ? "/ssm/stu/add" : "/ssm/stu/update"
//发送ajax请求到后台
$.post(path, app.stuInfo, function (backData) {
if (backData.code == 1) {
app.$message({
type: 'success',
message: '操作成功!'
});
window.location.reload()
} else {
app.$message({
type: 'danger',
message: '操作失败!'
});
}
})
}
});
},
openAddStu() {
//请求班级的数据
$.get("/ssm/grade/list", function (backData) {
app.gradeArr = backData.data
app.stuInfo = {}
app.titlename = "添加学生"
app.dialogFormVisible = true
})
},
deleteStudent(id) {
this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
$.get("/ssm/stu/delete/" + id, function (backData) {
if (backData.code === 1) {
app.$message({
type: 'success',
message: '删除成功!'
});
window.location.reload()
} else {
app.$message({
type: 'danger',
message: '删除失败!'
});
}
});
});
},
handleSizeChange(val) {
app.size = val
getStudentData(1, app.size)
},
handleCurrentChange(val) {
getStudentData(val, app.size)
},
searchData() {
getStudentData(1, app.size)
}
}
})
function getStudentData(a, b) {
app.queryInfo.pageNo = a;
app.queryInfo.pageCount = b;
$.post("/ssm/stu/query", app.queryInfo, function (backData) {
app.tableData = backData.data.currentData
app.t = backData.data.totalCount
})
}
getStudentData(1, 5)
script>
body>
html>
在数据正常展示时,页面效果如下
接下来进行数据的增删改查操作,此处只进行流程分析,源码在文章后边
当我们进入到学生管理界面,首先需要查询数据库中的数据,并且把他显示在页面当中
我们使用的是ElementUI提供的分页查询的代码。首先要发送post请求到"/ssm/stu/query"获取数据
所以这是一个连贯的过程,这里不再过多赘述
当获取到的数据响应到页面,这时一个完整的业务流程才算完毕
我们在实现类中可能会遇到实体类传参所以还要新建一些实体类,这些类放在pojo文件夹下
源码如下
package com.aaa.ssm.controller;
import com.aaa.ssm.pojo.vo.StudentQuery;
import com.aaa.ssm.pojo.vo.StudentVO;
import com.aaa.ssm.result.AjaxResult;
import com.aaa.ssm.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Author Grg
* @Date 2023/9/18 17:49
* @PackageName:com.aaa.ssm.controller
* @ClassName: StudentController
* @Description: 又是码代码的一天
* @Version plus max 宇宙无敌终极版本
*/
@RestController
@RequestMapping("stu")
public class StudentController {
@Autowired
private StudentService studentService;
@RequestMapping("query")
public AjaxResult queryStudent(StudentQuery query) {
return studentService.queryStudent(query);
}
@RequestMapping("delete/{id}")
public AjaxResult deleteStudent(@PathVariable("id") Integer id) {
return studentService.deleteStudent(id);
}
@RequestMapping("add")
public AjaxResult addStudent(StudentVO studentVO) {
return studentService.addStudent(studentVO);
}
@RequestMapping("get/{id}")
public AjaxResult getStudentById(@PathVariable("id") Integer id) {
return studentService.getStudentById(id);
}
@RequestMapping("update")
public AjaxResult updateStudent(StudentVO studentVO) {
return studentService.updateStudent(studentVO);
}
}
package com.aaa.ssm.controller;
import com.aaa.ssm.result.AjaxResult;
import com.aaa.ssm.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Author Grg
* @Date 2023/9/17 14:49
* @PackageName:com.aaa.ssm.controller
* @ClassName: EmpController
* @Description: 又是码代码的一天
* @Version plus max 宇宙无敌终极版本
*/
@RestController
@RequestMapping("emp")
public class EmpController {
@Autowired
private EmpService empService;
@RequestMapping("login")
public AjaxResult login(String username, String password) {
return empService.login(username, password);
}
@RequestMapping("getInfo")
public AjaxResult getInfo() {
return empService.getInfo();
}
}
package com.aaa.ssm.controller;
import com.aaa.ssm.result.AjaxResult;
import com.aaa.ssm.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Author Grg
* @Date 2023/9/18 17:49
* @PackageName:com.aaa.ssm.controller
* @ClassName: StudentController
* @Description: 又是码代码的一天
* @Version plus max 宇宙无敌终极版本
*/
@RestController
@RequestMapping("grade")
public class GradeController {
@Autowired
private GradeService gradeService;
@RequestMapping("list")
public AjaxResult queryStudent() {
return gradeService.listAllGrade();
}
}
package com.aaa.ssm.mapper;
import com.aaa.ssm.pojo.dto.EmpDTO;
import com.aaa.ssm.pojo.dto.LoginDTO;
import org.apache.ibatis.annotations.Param;
/**
* @Author Grg
* @Date 2023/9/17 15:02
* @PackageName:com.aaa.ssm.mapper
* @ClassName: EmpMapper
* @Description: 又是码代码的一天
* @Version plus max 宇宙无敌终极版本
*/
public interface EmpMapper {
LoginDTO login(@Param("username")String username,@Param("password") String password);
EmpDTO getEmpInfoByEid(Integer eid);
}
package com.aaa.ssm.mapper;
import com.aaa.ssm.pojo.dto.GradeDTO;
import java.util.List;
/**
* @Author Grg
* @Date 2023/9/19 15:02
* @PackageName:com.aaa.ssm.mapper
* @ClassName: GradeMapper
* @Description: 又是码代码的一天
* @Version plus max 宇宙无敌终极版本
*/
public interface GradeMapper {
List<GradeDTO> listAllGrades();
}
package com.aaa.ssm.mapper;
import com.aaa.ssm.pojo.dto.PermissionDTO;
import java.util.List;
/**
* @Author Grg
* @Date 2023/9/18 15:13
* @PackageName:com.aaa.ssm.mapper
* @ClassName: PermissionMapper
* @Description: 又是码代码的一天
* @Version plus max 宇宙无敌终极版本
*/
public interface PermissionMapper {
List<PermissionDTO> listSuperAdminPermissions();
List<PermissionDTO> listNormalAdminPermissions(Integer rid);
}
package com.aaa.ssm.mapper;
import com.aaa.ssm.pojo.dto.StudentDTO;
import com.aaa.ssm.pojo.vo.StudentQuery;
import com.aaa.ssm.pojo.vo.StudentVO;
import java.util.List;
/**
* @Author Grg
* @Date 2023/9/18 17:55
* @PackageName:com.aaa.ssm.mapper
* @ClassName: StudentMapper
* @Description: 又是码代码的一天
* @Version plus max 宇宙无敌终极版本
*/
public interface StudentMapper {
List<StudentDTO> queryStudentByQuery(StudentQuery query);
Long queryStudentTotalCount(StudentQuery query);
int deleteStudentById(Integer id);
int addStudent(StudentVO studentVO);
StudentVO getStudentById(Integer id);
int uptateStudent(StudentVO studentVO);
}
package com.aaa.ssm.pojo.dto;
import lombok.Data;
import java.io.Serializable;
/**
* @Author Grg
* @Date 2023/9/17 15:22
* @PackageName:com.aaa.ssm.pojo.dto
* @ClassName: DeptDTO
* @Description: 又是码代码的一天
* @Version plus max 宇宙无敌终极版本
*/
@Data
public class DeptDTO implements Serializable {
private Integer id;
private String dname;
private String other;
private Integer state;
}
package com.aaa.ssm.pojo.dto;
import lombok.Data;
import java.io.Serializable;
/**
* @Author Grg
* @Date 2023/9/17 15:20
* @PackageName:com.aaa.ssm.pojo.dto
* @ClassName: EmpDTO
* @Description: 又是码代码的一天
* @Version plus max 宇宙无敌终极版本
*/
@Data
public class EmpDTO implements Serializable {
private Integer id;
private String ename;
private String hiredate;
private String telephone;
private DeptDTO dept;
private RoleDTO role;
}
package com.aaa.ssm.pojo.vo;
import lombok.Data;
import java.io.Serializable;
/**
* @Author Grg
* @Date 2023/9/19 15:45
* @PackageName:com.aaa.ssm.pojo.vo
* @ClassName: StudentVO
* @Description: 又是码代码的一天
* @Version plus max 宇宙无敌终极版本
*/
@Data
public class StudentVO implements Serializable {
private Integer id;
private String sname;
private Integer sage;
private String saddress;
private Integer gid;
}
当然不止这些,还有好几个(懒得写了,实在头皮发麻)这些类主要就是用来接收参数用的
这一块需要注意的是,我们的数据库中其实是有外键的,虽然是逻辑外键。我们在新建类中可以看到,在类中有私有的成员对象,我们使用这种方法来凸显外键的作用
剩下的在这里就放张截图叭
用来接收AJAX请求返回结果
AjaxResult
package com.aaa.ssm.result;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author Grg
* @Date 2023/8/28 15:58
* @PackageName:com.grg.Result
* @ClassName: AjaxResult
* @Description: 又是码代码的一天
* @Version plus max 宇宙无敌终极版本
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AjaxResult {
private Integer code;
private String msg;
private Object data;
public static AjaxResult success() {
return new AjaxResult(1,"操作成功",null);
}
public static AjaxResult success(Object data) {
return new AjaxResult(1,"操作成功",data);
}
public static AjaxResult error() {
return new AjaxResult(2,"操作失败",null);
}
public static AjaxResult error(String msg) {
return new AjaxResult(2,msg,null);
}
}
package com.aaa.ssm.service.impl;
import com.aaa.ssm.mapper.EmpMapper;
import com.aaa.ssm.mapper.PermissionMapper;
import com.aaa.ssm.pojo.dto.EmpDTO;
import com.aaa.ssm.pojo.dto.LoginDTO;
import com.aaa.ssm.pojo.dto.PermissionDTO;
import com.aaa.ssm.result.AjaxResult;
import com.aaa.ssm.service.EmpService;
import com.aaa.ssm.sysconst.DeptState;
import com.aaa.ssm.sysconst.EmpState;
import com.aaa.ssm.util.PermissionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* @Author Grg
* @Date 2023/9/17 15:00
* @PackageName:com.aaa.ssm.service.impl
* @ClassName: EmpServiceImpl
* @Description: 又是码代码的一天
* @Version plus max 宇宙无敌终极版本
*/
@Service
public class EmpServiceImpl implements EmpService {
@Autowired
private EmpMapper empMapper;
@Autowired
private PermissionMapper permissionMapper;
@Autowired
private HttpSession session;
@Override
public AjaxResult login(String username, String password) {
//1.验证账号密码是否正确
LoginDTO login = empMapper.login(username, password);
//1.5账号的状态是什么 state 0在职 1冻结 2离职
if (login == null) {
return AjaxResult.error("账号或者密码错误");
}
if (login.getState() == EmpState.EMP_DONGJIE) {
return AjaxResult.error("账号被冻结");
}
if (login.getState() == EmpState.EMP_LIZHI) {
return AjaxResult.error("员工已经离职 联系管理员");
}
//2.如果正确 获取员工编号 查询员工信息
Integer eid = login.getEid();
EmpDTO empInfo = empMapper.getEmpInfoByEid(eid);
if (empInfo.getDept().getState() == DeptState.DEPT_STATE_BILE) {
return AjaxResult.error("部门已倒闭 请联系主管");
}
//登录成功
//将当前用户信息存储近Session中
session.setAttribute("emp", empInfo);
return AjaxResult.success();
}
@Override
public AjaxResult getInfo() {
EmpDTO empInfo = (EmpDTO) session.getAttribute("emp");
HashMap<Object, Object> map = new HashMap<>();
map.put("userInfo", empInfo);
Integer state = empInfo.getRole().getState();
if (state == 1) {
return AjaxResult.success(map);
}
List<PermissionDTO> permissionDTOS = null;
Integer rid = empInfo.getRole().getId();
if (rid == 1) {
//超级管理员权限
permissionDTOS = permissionMapper.listSuperAdminPermissions();
} else {
//普通管理员
permissionDTOS = permissionMapper.listNormalAdminPermissions(rid);
}
List<PermissionDTO> data = PermissionUtil.handlerData(permissionDTOS);
map.put("permissionInfo", data);
return AjaxResult.success(map);
}
}
package com.aaa.ssm.service.impl;
import com.aaa.ssm.mapper.GradeMapper;
import com.aaa.ssm.pojo.dto.GradeDTO;
import com.aaa.ssm.result.AjaxResult;
import com.aaa.ssm.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Author Grg
* @Date 2023/9/19 15:00
* @PackageName:com.aaa.ssm.service.impl
* @ClassName: GradeServiceImpl
* @Description: 又是码代码的一天
* @Version plus max 宇宙无敌终极版本
*/
@Service
public class GradeServiceImpl implements GradeService {
@Autowired
private GradeMapper gradeMapper;
@Override
public AjaxResult listAllGrade() {
List<GradeDTO> gradeDTOS = gradeMapper.listAllGrades();
return AjaxResult.success(gradeDTOS);
}
}
package com.aaa.ssm.service.impl;
import com.aaa.ssm.mapper.StudentMapper;
import com.aaa.ssm.pojo.dto.StudentDTO;
import com.aaa.ssm.pojo.vo.StudentQuery;
import com.aaa.ssm.pojo.vo.StudentVO;
import com.aaa.ssm.result.AjaxResult;
import com.aaa.ssm.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
/**
* @Author Grg
* @Date 2023/9/18 17:53
* @PackageName:com.aaa.ssm.service.impl
* @ClassName: StudentImpl
* @Description: 又是码代码的一天
* @Version plus max 宇宙无敌终极版本
*/
@Service
public class StudentServiceImpl implements StudentService {
@Autowired
private StudentMapper studentMapper;
@Override
public AjaxResult queryStudent(StudentQuery query) {
List<StudentDTO> studentDTOS = studentMapper.queryStudentByQuery(query);
Long totalCount = studentMapper.queryStudentTotalCount(query);
HashMap<Object, Object> map = new HashMap<>();
map.put("currentData", studentDTOS);
map.put("totalCount", totalCount);
return AjaxResult.success(map);
}
@Override
public AjaxResult deleteStudent(Integer id) {
int i = studentMapper.deleteStudentById(id);
if (i > 0) {
return AjaxResult.success();
} else {
return AjaxResult.error("删除失败");
}
}
@Override
public AjaxResult addStudent(StudentVO studentVO) {
System.out.println(studentVO);
int i = studentMapper.addStudent(studentVO);
if (i > 0) {
return AjaxResult.success();
} else {
return AjaxResult.error("添加失败");
}
}
@Override
public AjaxResult getStudentById(Integer id) {
StudentVO student = studentMapper.getStudentById(id);
return AjaxResult.success(student);
}
@Override
public AjaxResult updateStudent(StudentVO studentVO) {
int i = studentMapper.uptateStudent(studentVO);
if (i > 0) {
return AjaxResult.success();
} else {
return AjaxResult.error("修改失败");
}
}
}
package com.aaa.ssm.service;
import com.aaa.ssm.result.AjaxResult;
/**
* @Author Grg
* @Date 2023/9/17 14:58
* @PackageName:com.aaa.ssm.service
* @ClassName: EmpService
* @Description: 又是码代码的一天
* @Version plus max 宇宙无敌终极版本
*/
public interface EmpService {
AjaxResult login(String username, String password);
AjaxResult getInfo();
}
package com.aaa.ssm.service;
import com.aaa.ssm.result.AjaxResult;
/**
* @Author Grg
* @Date 2023/9/19 14:59
* @PackageName:com.aaa.ssm.service
* @ClassName: GradeService
* @Description: 又是码代码的一天
* @Version plus max 宇宙无敌终极版本
*/
public interface GradeService {
AjaxResult listAllGrade();
}
package com.aaa.ssm.service;
import com.aaa.ssm.pojo.vo.StudentQuery;
import com.aaa.ssm.pojo.vo.StudentVO;
import com.aaa.ssm.result.AjaxResult;
/**
* @Author Grg
* @Date 2023/9/18 17:52
* @PackageName:com.aaa.ssm.service
* @ClassName: StudentService
* @Description: 又是码代码的一天
* @Version plus max 宇宙无敌终极版本
*/
public interface StudentService {
AjaxResult queryStudent(StudentQuery query);
AjaxResult deleteStudent(Integer id);
AjaxResult addStudent(StudentVO studentVO);
AjaxResult getStudentById(Integer id);
AjaxResult updateStudent(StudentVO studentVO);
}
这个是在登陆时,根据登录账号的权限不同 展示的数据和能进行的操作也不一样
package com.aaa.ssm.util;
import com.aaa.ssm.pojo.dto.PermissionDTO;
import java.util.ArrayList;
import java.util.List;
/**
* @Author Grg
* @Date 2023/9/18 15:58
* @PackageName:com.aaa.ssm.util
* @ClassName: PermissionUtil
* @Description: 又是码代码的一天
* @Version plus max 宇宙无敌终极版本
*/
public class PermissionUtil {
public static List<PermissionDTO> handlerData(List<PermissionDTO> permissionDTOS){
ArrayList<PermissionDTO> data = new ArrayList<>();
for (PermissionDTO permissionDTO : permissionDTOS) {
if (permissionDTO.getPid() == 0) {
data.add(permissionDTO);
}
}
for (PermissionDTO permissionDTO : permissionDTOS) {
Integer pid = permissionDTO.getPid();
for (PermissionDTO datum : data) {
if (datum.getId().equals(pid)) {
datum.getSubMenu().add(permissionDTO);
}
}
}
return data;
}
}
DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.aaa.ssm.mapper.EmpMapper">
<select id="login" resultType="com.aaa.ssm.pojo.dto.LoginDTO">
select * from t_emp_login where username = #{username} and password = #{password};
select>
<resultMap id="empInfo" type="empDTO">
<id column="id" property="id">id>
<result column="ename" property="ename">result>
<result column="hiredate" property="hiredate">result>
<result column="telephone" property="telephone">result>
<association property="dept" javaType="deptDTO">
<id column="did" property="id">id>
<result column="dname" property="dname">result>
<result column="dstate" property="state">result>
association>
<association property="role" javaType="roleDTO">
<id column="rid" property="id">id>
<result column="rname" property="rname">result>
<result column="rstate" property="state">result>
association>
resultMap>
<select id="getEmpInfoByEid" resultMap="empInfo">
SELECT e.id,
e.ename,
e.hiredate,
e.telephone,
d.id did,
d.dname,
d.other,
d.state dstate,
r.id rid,
r.rname,
r.state rstate
from t_emp_info e
LEFT JOIN t_dept d on e.did = d.id
LEFT JOIN t_role r on e.rid = r.id
where e.id = #{eid};
select>
mapper>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.aaa.ssm.mapper.GradeMapper">
<select id="listAllGrades" resultType="com.aaa.ssm.pojo.dto.GradeDTO">
select *
from t_grade
where state = 0;
</select>
</mapper>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.aaa.ssm.mapper.PermissionMapper">
<select id="listSuperAdminPermissions" resultType="com.aaa.ssm.pojo.dto.PermissionDTO">
select id, pid, type, pname title, url content, state, icon
from t_perm
</select>
<select id="listNormalAdminPermissions" resultType="com.aaa.ssm.pojo.dto.PermissionDTO">
select p.id, p.pid, p.type, p.pname title, p.url content, p.state, p.icon
from t_rp tp
left join t_perm p on tp.pid = p.id
where tp.rid = #{rid}
and p.state = 0
</select>
</mapper>
DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.aaa.ssm.mapper.StudentMapper">
<resultMap id="StudentMap" type="com.aaa.ssm.pojo.dto.StudentDTO">
<id column="id" property="id">id>
<result column="name" property="name">result>
<result column="age" property="age">result>
<result column="address" property="address">result>
<result column="headImg" property="headImg">result>
<association property="grade" javaType="com.aaa.ssm.pojo.dto.GradeDTO">
<id column="tid" property="id">id>
<result column="gname" property="gname">result>
<result column="state" property="state">result>
association>
resultMap>
<sql id="queryStu">
<where>
<if test="name != null and '' != name">
and ts.name like concat('%',#{name},'%')
if>
<if test="minAge != null and '' != minAge">
and ts.age > #{minAge}
if>
<if test="maxAge != null and '' != maxAge">
and ts.age < #{maxAge}
if>
where>
sql>
<insert id="addStudent">
insert into t_student ( name, age, address, gid) values (#{sname},#{sage},#{saddress},#{gid})
insert>
<update id="uptateStudent">
update t_student
SET name = #{sname},
age = #{sage},
address = #{saddress},
gid= #{gid}
where id = #{id}
update>
<delete id="deleteStudentById">
delete
from t_student
where id = #{id}
delete>
<select id="queryStudentByQuery" resultMap="StudentMap">
select ts.id,
ts.name,
ts.age,
ts.address,
ts.headImg,
tg.id tid,
tg.gname,
tg.state
from t_student ts
left join t_grade tg
on ts.gid = tg.id
<include refid="queryStu">include>
limit #{index},#{pageCount}
select>
<select id="queryStudentTotalCount" resultType="java.lang.Long">
select count(*) from t_student ts
<include refid="queryStu">include>
select>
<select id="getStudentById" resultType="com.aaa.ssm.pojo.vo.StudentVO">
select id, name sname, age sage, address saddress, gid
from t_student
where id = #{id}
select>
mapper>