SSM02

SSM02

此时我们已经做好了登录模块接下来可以做一下学生管理系统的增删改查操作

首先,我们应当有一个登录成功后的主界面

在webapp下新建

1.main.html

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title><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-panekey="asd"label="欢迎页"name="asd"><iframe src="http://www.douyu.com" style="border: none;width: 99%;height: 600px;"></iframe></el-tab-pane><el-tab-panev-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.userInfoapp.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

2.list.html

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title><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"borderstyle="width: 100%"><el-table-columnprop="id"label="编号"></el-table-column><el-table-columnprop="name"label="姓名"></el-table-column><el-table-columnprop="age"label="年龄"></el-table-column><el-table-columnprop="address"label="地址"></el-table-column><el-table-columnlabel="班级"><template slot-scope="scope">{{scope.row.grade.gname}}</template></el-table-column><el-table-columnlabel="头像"><template slot-scope="scope"><img v-bind:src="scope.row.headImg" width="50px"/></template></el-table-column><el-table-columnlabel="操作"><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.dataapp.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.dataapp.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 = valgetStudentData(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.currentDataapp.t = backData.data.totalCount})}getStudentData(1, 5)
</script>
</body>
</html>

在数据正常展示时,页面效果如下

在这里插入图片描述

接下来进行数据的增删改查操作,此处只进行流程分析,源码在文章后边

3流程分析

当我们进入到学生管理界面,首先需要查询数据库中的数据,并且把他显示在页面当中

我们使用的是ElementUI提供的分页查询的代码。首先要发送post请求到"/ssm/stu/query"获取数据

  1. 在controller文件夹下创建StudentController用来处理请求的分发其中包括有
    1. 获取全部学生数据
    2. 根据ID删除学生
    3. 添加学生
    4. 根据ID获取单个学生
    5. 更新学生信息
  2. 在StudentController接收到请求时会调用service层的方法
  3. 首先有一个StudentService接口其中写了上述的五个方法
  4. 在新建StudentService的实现类,其中写的是业务处理的具体流程
  5. 在实现类中,我们想要实现业务需求,我们就要去调用mapper层中的方法去连接数据库进行数据的读取
  6. mapper层又要去找对应的mapper.xml配置文件进行sql语句的编写

所以这是一个连贯的过程,这里不再过多赘述

当获取到的数据响应到页面,这时一个完整的业务流程才算完毕

我们在实现类中可能会遇到实体类传参所以还要新建一些实体类,这些类放在pojo文件夹下

源码如下

4.controller层

4.1StudentController

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 {@Autowiredprivate 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);}}

4.2EmpController

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 {@Autowiredprivate EmpService empService;@RequestMapping("login")public AjaxResult login(String username, String password) {return empService.login(username, password);}@RequestMapping("getInfo")public AjaxResult getInfo() {return empService.getInfo();}
}

4.3GradeController

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 {@Autowiredprivate GradeService gradeService;@RequestMapping("list")public AjaxResult queryStudent() {return gradeService.listAllGrade();}
}

5.mapper层

5.1EmpMapper

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);
}

5.2GradeMapper

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();
}

5.3PermissionMapper

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);
}

5.4StudentMapper

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);
}

6.pojo

6.1dto

6.1.1DeptDTO

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;
}

6.1.2EmpDTO

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;
}

6.2vo

6.2.1StudentVO

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;
}

当然不止这些,还有好几个(懒得写了,实在头皮发麻)这些类主要就是用来接收参数用的

这一块需要注意的是,我们的数据库中其实是有外键的,虽然是逻辑外键。我们在新建类中可以看到,在类中有私有的成员对象,我们使用这种方法来凸显外键的作用

剩下的在这里就放张截图叭

在这里插入图片描述

7.result

用来接收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);}}

8.service

8.1impl实现类

8.1.1EmpServiceImpl

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 {@Autowiredprivate EmpMapper empMapper;@Autowiredprivate PermissionMapper permissionMapper;@Autowiredprivate HttpSession session;@Overridepublic 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();}@Overridepublic 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);}
}

8.1.2GradeServiceImpl

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 {@Autowiredprivate GradeMapper gradeMapper;@Overridepublic AjaxResult listAllGrade() {List<GradeDTO> gradeDTOS = gradeMapper.listAllGrades();return AjaxResult.success(gradeDTOS);}
}

8.1.3StudentServiceImpl

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 {@Autowiredprivate StudentMapper studentMapper;@Overridepublic 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);}@Overridepublic AjaxResult deleteStudent(Integer id) {int i = studentMapper.deleteStudentById(id);if (i > 0) {return AjaxResult.success();} else {return AjaxResult.error("删除失败");}}@Overridepublic AjaxResult addStudent(StudentVO studentVO) {System.out.println(studentVO);int i = studentMapper.addStudent(studentVO);if (i > 0) {return AjaxResult.success();} else {return AjaxResult.error("添加失败");}}@Overridepublic AjaxResult getStudentById(Integer id) {StudentVO student = studentMapper.getStudentById(id);return AjaxResult.success(student);}@Overridepublic AjaxResult updateStudent(StudentVO studentVO) {int i = studentMapper.uptateStudent(studentVO);if (i > 0) {return AjaxResult.success();} else {return AjaxResult.error("修改失败");}}
}

8.2EmpService

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();
}

8.3GradeService

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();
}

8.4StudentService

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);
}

9.util工具类

9.1PermissionUtil

这个是在登陆时,根据登录账号的权限不同 展示的数据和能进行的操作也不一样

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;}
}

10.mapper.xml

10.1EmpMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//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 rstatefrom t_emp_info eLEFT JOIN t_dept d on e.did = d.idLEFT JOIN t_role r on e.rid = r.idwhere e.id = #{eid};</select>
</mapper>

10.2GradeMapper

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//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_gradewhere state = 0;</select>
</mapper>

10.3PermissionMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//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, iconfrom 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.iconfrom t_rp tpleft join t_perm p on tp.pid = p.idwhere tp.rid = #{rid}and p.state = 0</select>
</mapper>

10.4StudentMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//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 &gt; #{minAge}</if><if test="maxAge != null and '' != maxAge">and ts.age &lt; #{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_studentSET name    = #{sname},age     = #{sage},address = #{saddress},gid= #{gid}where id = #{id}</update><delete id="deleteStudentById">deletefrom t_studentwhere 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.statefrom t_student tsleft join t_grade tgon 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, gidfrom t_studentwhere id = #{id}</select>
</mapper>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/136298.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

天选之子C++是如何发展起来的?如何学习C++呢?

天选之子C是如何发展起来的&#xff1f;如何学习C呢? 一、什么是C二、C发展史三、C的重要性3.1 语言的使用广泛度3.2 在工作领域 四、如何学习C4.1 大佬怎么学&#xff1f;4.2 自己怎么学 一、什么是C C语言是结构化和模块化的语言&#xff0c;适合处理较小规模的程序。对于复…

Echarts散点图筛选新玩法dataZoom

目录 前言 一、引入Echarts5.4.3 二、新建index.html 三、绑定Echarts展示元素 四、初始数据绑定 五、option设置 六、效果展示 七、参数说明 总结 前言 如果您在日常的工作当中也会遇到如下场景&#xff0c;需要在线对已经展示出来的图表进行进一步的筛选&#xff0c…

在编译源码的环境下,搭建起Discuz!社区论坛和WordPress博客的LNMP架构

目录 一.编译安装nginx 二.编译安装MySQL 三.编译安装PHP 四.安装论坛 五.安装wordpress博客 六.yum安装LNMP架构&#xff08;简要过程参考&#xff09; 一.编译安装nginx 1&#xff09;关闭防火墙&#xff0c;将安装nginx所需软件包传到/opt目录下 systemctl stop fire…

mysql表的导出和导入

表的导出 mysql 默认对导出的目录有权限限制&#xff0c;也就是说使用命令进行导出的时候&#xff0c;需要指定目录进行操作 show global variables like ‘%secure%’; secure_file_priv 值情况分析&#xff1a; 如果设置为empty&#xff0c;表示不限制文件生成的位置&#x…

Redis 三种特殊的数据类型 - Geospatial地理位置 - Hyperloglog基数统计的算法 - Bitmaps位图(位存储)

目录 Redis 三种特殊的数据类型&#xff1a; Geospatial&#xff1a;地理位置 Geospatial类型常用的命令&#xff1a; GEOADD&#xff1a;添加地理位置 GEOPOS&#xff1a;获取地理位置 GEODIST&#xff1a;返回两个给定位置之间的距离 GEORADIUS&#xff1a;以给定的经纬…

企业电子招投标采购系统——功能模块功能描述+数字化采购管理 采购招投标

功能描述 1、门户管理&#xff1a;所有用户可在门户页面查看所有的公告信息及相关的通知信息。主要板块包含&#xff1a;招标公告、非招标公告、系统通知、政策法规。 2、立项管理&#xff1a;企业用户可对需要采购的项目进行立项申请&#xff0c;并提交审批&#xff0c;查看所…

compose——底部弹窗ModalBottomSheetLayout

底部弹窗ModalBottomSheetLayout ModalBottomSheetLayout 是 Jetpack Compose 中的一个组件&#xff0c;用于创建底部弹窗。它可以在屏幕底部显示一个半透明的背景&#xff0c;并从底部滑出一个内容面板。ModalBottomSheetLayout 包含两个主要部分&#xff1a;背景和内容面板。…

uqrcode+uni-app 微信小程序生成二维码

使用微信小程序需要弹出动态二维码的需求&#xff0c;从插件市场选了一个下载次数较多的组件引入到项目中uqrcode&#xff0c;使用步骤如下&#xff1a; 1、从插件市场下载 插件地址&#xff1a;https://ext.dcloud.net.cn/plugin?id1287&#xff0c;若你是跟我一样是用uni-…

java导出Excel合并列(自定义列根据模板进行导出)附详细代码及注解

【版权所有&#xff0c;文章允许转载&#xff0c;但须以链接方式注明源地址&#xff0c;否则追究法律责任】【创作不易&#xff0c;点个赞就是对我最大的支持】 前言 仅作为学习笔记&#xff0c;供大家参考 总结的不错的话&#xff0c;记得点赞收藏关注哦&#xff01; 这里…

DM/达梦数据库查询或更新某一列中多个字典码对应内容

准备工作&#xff08;建表、插入数据&#xff09; 1、建立表格&#xff1a;学生-学习科目表student_study 注意&#xff1a;科目kemu列内容是字典码&#xff0c;需要更换成对应内容。 CREATE TABLE "TEST"."STUDENT_STUDY" ( "NAME" VARCHAR(2…

各种电机驱动原理

步进电机 步进电机参考资料 野火官方文档 步进电机驱动原理 上面参考文档中有的内容就不写了&#xff0c;写一下我自己的总结吧。 说明&#xff1a; 电机驱动器输入信号有电机转动方向信号DIR&#xff0c;电机转速信号PWM&#xff0c;电机使能信号EN&#xff1b;电机驱动器…

安装VS2015时提示安装包丢失或损坏

今天安装VS2015社区版本时&#xff0c;提示缺失以下两个内容&#xff1a; Microsoft VisualStudio JavaScript Project System : 找不到元素。 Microsoft VisualStudio JavaScript Language Service : 系统找不到指定的文件。 虽然似乎不影响C代码的运行&#xff0c;但是我怕有…

计算机网络第四节 数据链路层

一&#xff0c;引入数据链路层的目的 1.目的意义 数据链路层是体系结构中的第二层&#xff1b; 从发送端来讲&#xff0c;物理层可以将数据链路层交付下来的数据&#xff0c;装换成光&#xff0c;电信号发送到传输介质上了 从接收端来讲&#xff0c;物理层能将传输介质的光&…

github 网页显示不全?

问题 解决 1、检查网页&#xff0c;打开 network&#xff0c;重新刷新 github 网页 2、查看无法加载的资源&#xff08;如 css 文件&#xff09; 3、查看域名地址 https://tool.chinaz.com/dns/&#xff0c;github.githubassets.com&#xff08;检查网页元素&#xff0c;点击无…

在Spring Boot API Gateway中实现Sticky Session

文章目录 小结问题在API Gateway中实现Sticky Session在同一个API Gateway中同时支持Sticky Session和RoundRobinLoadBalancer参考 小结 在Kubernetes微服务的云环境中&#xff0c;如何在Spring Boot API Gateway中实现Sticky Session&#xff0c;当服务请求被某一个服务器处理…

2023年7月京东平板电脑行业品牌销售排行榜(京东销售数据分析)

鲸参谋监测的京东平台7月份平板电脑市场销售数据已出炉&#xff01; 根据鲸参谋电商数据分析平台的相关数据显示&#xff0c;今年7月份&#xff0c;京东平台上平板电脑的销量为68万&#xff0c;同比增长超过37%&#xff1b;销售额为22亿&#xff0c;同比增长约54%。从价格上看…

win系统环境搭建(四)——Windows安装mysql8压缩包版本

windows环境搭建专栏&#x1f517;点击跳转 win系统环境搭建&#xff08;四&#xff09;——Windows安装mysql8压缩包版本 本系列windows环境搭建开始讲解如何给win系统搭建环境&#xff0c;本人所用系统是腾讯云服务器的Windows Server 2022&#xff0c;你可以理解成就是你用…

mysql知识大全

MySQL知识大全&#xff08;2&#xff09; MySqL 基础为1—7&#xff08;增删改查基础语法&#xff09;&#xff0c;MySQL进阶知识为8—11&#xff08;约束、数据库设计、多表查询、事务&#xff09; 1、数据库相关概念 以前我们做系统&#xff0c;数据持久化的存储采用的是文件…

直线模组的常用语

在工业生产中&#xff0c;直线模组的叫法有很多种&#xff0c;对于新手小白来说&#xff0c;很容易就会被绕晕&#xff0c;今天我们就来简单说一下直线模组的常用称呼吧&#xff01; 1、直线模组&#xff1a;与直线滑台同义&#xff0c;基本可以相互互换。直线模组一般是指可以…

微信小程序隐私授权

微信开发者平台新公告&#xff1a;2023年9月15之后&#xff0c;隐私协议将被启用&#xff0c;所以以后的小程序都要加上隐私协议的内容提示用户&#xff0c; 首先设置好隐私协议的内容&#xff0c;登录小程序的开发者后台&#xff0c;在设置--》服务内容声明--》用户隐私保护指…