• MyBatis注解开发实现学生管理页面(分页pagehelper,多条件搜索,查看课程信息)


    pom.xml

    1. "1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    5. <modelVersion>4.0.0modelVersion>
    6. <groupId>org.examplegroupId>
    7. <artifactId>studentSystemWorkartifactId>
    8. <version>1.0-SNAPSHOTversion>
    9. <properties>
    10. <maven.compiler.source>8maven.compiler.source>
    11. <maven.compiler.target>8maven.compiler.target>
    12. properties>
    13. <dependencies>
    14. <dependency>
    15. <groupId>org.projectlombokgroupId>
    16. <artifactId>lombokartifactId>
    17. <version>1.18.16version>
    18. dependency>
    19. <dependency>
    20. <groupId>org.mybatisgroupId>
    21. <artifactId>mybatisartifactId>
    22. <version>3.5.1version>
    23. dependency>
    24. <dependency>
    25. <groupId>mysqlgroupId>
    26. <artifactId>mysql-connector-javaartifactId>
    27. <version>8.0.25version>
    28. <scope>runtimescope>
    29. dependency>
    30. <dependency>
    31. <groupId>junitgroupId>
    32. <artifactId>junitartifactId>
    33. <version>4.12version>
    34. <scope>testscope>
    35. dependency>
    36. <dependency>
    37. <groupId>javax.servletgroupId>
    38. <artifactId>javax.servlet-apiartifactId>
    39. <version>3.1.0version>
    40. dependency>
    41. <dependency>
    42. <groupId>com.fasterxml.jackson.coregroupId>
    43. <artifactId>jackson-coreartifactId>
    44. <version>2.7.3version>
    45. dependency>
    46. <dependency>
    47. <groupId>com.fasterxml.jackson.coregroupId>
    48. <artifactId>jackson-databindartifactId>
    49. <version>2.7.3version>
    50. dependency>
    51. <dependency>
    52. <groupId>com.fasterxml.jackson.coregroupId>
    53. <artifactId>jackson-annotationsartifactId>
    54. <version>2.7.3version>
    55. dependency>
    56. <dependency>
    57. <groupId>commons-langgroupId>
    58. <artifactId>commons-langartifactId>
    59. <version>2.6version>
    60. dependency>
    61. <dependency>
    62. <groupId>org.apache.commonsgroupId>
    63. <artifactId>commons-lang3artifactId>
    64. <version>3.4version>
    65. dependency>
    66. <dependency>
    67. <groupId>junitgroupId>
    68. <artifactId>junitartifactId>
    69. <version>4.13version>
    70. <scope>testscope>
    71. dependency>
    72. <dependency>
    73. <groupId>commons-beanutilsgroupId>
    74. <artifactId>commons-beanutilsartifactId>
    75. <version>1.8.3version>
    76. dependency>
    77. <dependency>
    78. <groupId>commons-logginggroupId>
    79. <artifactId>commons-loggingartifactId>
    80. <version>1.1.1version>
    81. dependency>
    82. <dependency>
    83. <groupId>commons-dbutilsgroupId>
    84. <artifactId>commons-dbutilsartifactId>
    85. <version>1.6version>
    86. dependency>
    87. <dependency>
    88. <groupId>log4jgroupId>
    89. <artifactId>log4jartifactId>
    90. <version>1.2.17version>
    91. dependency>
    92. <dependency>
    93. <groupId>com.mchangegroupId>
    94. <artifactId>c3p0artifactId>
    95. <version>0.9.5version>
    96. dependency>
    97. <dependency>
    98. <groupId>com.github.pagehelpergroupId>
    99. <artifactId>pagehelperartifactId>
    100. <version>5.1.10version>
    101. dependency>
    102. dependencies>
    103. project>

    index.html

    1. html>
    2. <html>
    3. <head>
    4. <title>title>
    5. <meta charset="UTF-8">
    6. <link rel="stylesheet" href="element-ui-2.13.0/lib/theme-chalk/index.css" />
    7. <script type="text/javascript" src="vue/vue-v2.6.10.js">script>
    8. <script type="text/javascript" src="element-ui-2.13.0/lib/index.js">script>
    9. <script type="text/javascript" src="vue/axios-0.18.0.js">script>
    10. head>
    11. <body>
    12. <div id="app">
    13. <template>
    14. <el-table :data="tableData" @selection-change="handleSelectionChange" size="medium"
    15. highlight-current-row="true" style="width: 100%">
    16. <el-table-column type="selection" width="55" prop="sid">
    17. el-table-column>
    18. <el-table-column width="100px" label="序号" type="index">
    19. el-table-column>
    20. <el-table-column label="姓名" prop="sname">
    21. el-table-column>
    22. <el-table-column label="性别" prop="gender">
    23. el-table-column>
    24. <el-table-column label="班级" prop="tbClass.caption">
    25. el-table-column>
    26. <el-table-column>
    27. <template slot="header" slot-scope="scope">
    28. <el-input v-model="search" size="mini" placeholder="请输入姓名" />
    29. template>
    30. el-table-column>
    31. <el-table-column>
    32. <template slot="header" slot-scope="scope">
    33. <el-radio v-model="sex" label="男">el-radio>
    34. <el-radio v-model="sex" label="女">el-radio>
    35. template>
    36. el-table-column>
    37. <el-table-column>
    38. <template slot="header" slot-scope="scope">
    39. <el-button type="success" @click="findAll()">搜索el-button>
    40. template>
    41. <template slot-scope="scope">
    42. <el-button size="mini" @click="handleLook(scope.$index, scope.row)">查看课程信息el-button>
    43. template>
    44. el-table-column>
    45. el-table>
    46. template>
    47. <br />
    48. <el-row>
    49. <el-button type="warning" @click="delAll()">删除选中el-button>
    50. el-row>
    51. <template>
    52. <div class="block" align="right">
    53. <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
    54. :current-page="currentPage" :page-sizes="[3, 4, 5, 6]" :page-size="pageSize"
    55. layout="total, sizes, prev, pager, next, jumper" :total="totalCount">
    56. el-pagination>
    57. div>
    58. template>
    59. <el-dialog title="查看课程信息" :visible.sync="dialogFormVisible">
    60. <el-form ref="ruleForm" :model="ruleForm" label-width="80px">
    61. <el-form-item label="学生姓名">
    62. <el-input v-model="ruleForm.sname" style="width: 210px;" readonly>el-input>
    63. el-form-item>
    64. el-form>
    65. <el-table :data="tableCourse" @selection-change="handleSelectionChange" size="medium"
    66. highlight-current-row="true" style="width: 100%">
    67. <el-table-column width="100px" label="序号" type="index">
    68. el-table-column>
    69. <el-table-column label="课程" prop="courses[0].cname">
    70. el-table-column>
    71. <el-table-column label="成绩" prop="num">
    72. el-table-column>
    73. <el-table-column label="老师" prop="courses[0].teacher.tname">
    74. el-table-column>
    75. el-table>
    76. el-dialog>
    77. div>
    78. body>
    79. <script>
    80. axios.defaults.withCredentials = true
    81. new Vue({
    82. el: "#app",
    83. data: {
    84. /*表格数据*/
    85. tableData: [],
    86. tableCourse: [],
    87. /*条件查询关键字*/
    88. search: '',
    89. sex: "",
    90. //批量删除存放选中的复选框
    91. multipleSelection: [],
    92. //存放删除的数据
    93. delarr: [],
    94. //当前页
    95. currentPage: 1,
    96. //每页显示条数
    97. pageSize: 3,
    98. //总条数
    99. totalCount: '',
    100. //总页数
    101. totalPage: '',
    102. // 是否展示课程信息对话框
    103. dialogFormVisible: false,
    104. ruleForm: {
    105. sid: '',
    106. sname: '',
    107. gender: '',
    108. tbClass: '',
    109. class_id: '',
    110. },
    111. },
    112. methods: {
    113. findAll() {
    114. let param = new URLSearchParams();
    115. param.append("type", "showStuByPage");
    116. param.append("page", this.currentPage);
    117. param.append("rows", this.pageSize);
    118. param.append("sname", this.search);
    119. param.append("gender", this.sex);
    120. axios({
    121. method: "post",
    122. url: "http://localhost:8080/studentSystemWork_war_exploded/studentServlet",
    123. data: param
    124. }).then(obj => {
    125. this.tableData = obj.data.list;
    126. this.totalCount = obj.data.total;
    127. });
    128. },
    129. handleSizeChange: function (size) {
    130. this.pageSize = size;
    131. this.findAll();
    132. },
    133. handleCurrentChange: function (currentPage) {
    134. this.currentPage = currentPage;
    135. this.findAll();
    136. },
    137. delAll() {
    138. //获取删除的ID
    139. this.delarr = [];
    140. for (let i = 0; i < this.multipleSelection.length; i++) {
    141. this.delarr.push(this.multipleSelection[i].sid);
    142. }
    143. //判断要删除的文件是否为空
    144. if (this.delarr.length == 0) {
    145. this.$message.warning("请选择要删除的数据!")
    146. } else {
    147. this.$confirm("是否确认删除?", "提示", { type: 'warning' }).then(() => {
    148. //点击确认删除
    149. let param = new URLSearchParams();
    150. param.append("sids", this.delarr.join())
    151. param.append("type", "deleteStudents")
    152. axios({
    153. method: "post",
    154. url: "http://localhost:8080/studentSystemWork_war_exploded/studentServlet",
    155. data: param
    156. }).then(obj => {
    157. if (obj.data) {
    158. this.$message.success("删除成功!");
    159. setTimeout(function () {
    160. window.location.href = "index.html"
    161. }, 1500)
    162. } else {
    163. this.$message.error("删除失败!")
    164. }
    165. });
    166. });
    167. }
    168. },
    169. handleSelectionChange(val) {
    170. this.multipleSelection = val;
    171. },
    172. handleLook(index, row) {
    173. this.dialogFormVisible = true;
    174. this.ruleForm = row;
    175. let param = new URLSearchParams();
    176. param.append("type","getStudentCourseById")
    177. param.append("sid",row.sid);
    178. axios({
    179. method: "post",
    180. url: "http://localhost:8080/studentSystemWork_war_exploded/scoreServlet",
    181. data: param
    182. }).then(obj => {
    183. this.tableCourse = obj.data;
    184. });
    185. },
    186. },
    187. created() {
    188. this.findAll();
    189. }
    190. })
    191. script>
    192. html>

    studentDao

    1. package com.etime.dao;
    2. import com.etime.pojo.Student;
    3. import com.etime.pojo.TbClass;
    4. import org.apache.ibatis.annotations.*;
    5. import java.util.List;
    6. public interface StudentDao {
    7. @Select({""})
    8. int getCountStudent(Student student);
    9. @Select({""})
    10. @Results({
    11. @Result(property = "sid",column = "sid"),
    12. @Result(property = "gender",column = "gender"),
    13. @Result(property = "class_id",column = "class_id"),
    14. @Result(property = "sname",column = "sname"),
    15. @Result(property = "tbClass",column = "class_id",javaType = TbClass.class,
    16. one = @One(select = "com.etime.dao.TbClassDao.getClassByCid"))
    17. })
    18. List showStuByPage(Student student);
    19. @Delete({""})
    20. int deleteStudents(List list);
    21. }

    具体完整代码看资源

  • 相关阅读:
    【andriod】 设备APP连接云端平台的各种细节部署和操作
    2023苏州科技大学计算机考研信息汇总
    Flutter 使用Screen保持屏幕常亮不息屏
    C++库Eigen中拟合线性方程(最小二乘法)
    Linux-centos系统安装MySql5.7
    php简单后门实现及php连接数据库
    UE4 MVP 坐标转换
    Java入门必备基础知识
    Python解题 - CSDN周赛第11期 - 圆桌请客(脑筋急转弯)
    华为机试 - 模拟商场优惠打折
  • 原文地址:https://blog.csdn.net/weixin_62971115/article/details/133756891