• Vue+Element之SpingBoot学生管理系统


    目录

    前后端分离

            1.1后端

            1.1.1配置generatorConfig.xml中的mysql文件目录,自动生成代码

            1.1.2mapper层

            1.1.2.1mapper.xml层

            1.1.3StudentService-->将BookMapper复制到Service

            1.1.4StudentServiceImpl(业务逻辑层)

            1.1.5StudentController层

            1.2前端

            1.2.1在cmd中下载依赖npm i(install)

            1.2.2在api中action.js配置请求路径

            1.2.3前端views写前端页面功能代码

            1.2.4在cmd中跑起来npm run dev

    查询+主页面绑值

    新增

    generatorConfig.xml

    mapper层

    1. @Repository
    2. public interface StudentMapper {
    3. /**
    4. * 新增
    5. * @param record
    6. * @return
    7. */
    8. int insert(Student record);
    9. /**
    10. * 查询
    11. * @param student
    12. * @return
    13. */
    14. List all(Student student);
    15. }

     mapper.xml层

    1. "1.0" encoding="UTF-8" ?>
    2. mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
    3. <mapper namespace="com.zking.spboot.mapper.StudentMapper" >
    4. <resultMap id="BaseResultMap" type="com.zking.spboot.model.Student" >
    5. <constructor >
    6. <idArg column="sid" jdbcType="INTEGER" javaType="java.lang.Integer" />
    7. <arg column="sname" jdbcType="VARCHAR" javaType="java.lang.String" />
    8. <arg column="score" jdbcType="VARCHAR" javaType="java.lang.String" />
    9. <arg column="sex" jdbcType="VARCHAR" javaType="java.lang.String" />
    10. constructor>
    11. resultMap>
    12. <sql id="Base_Column_List" >
    13. sid, sname, score, sex
    14. sql>
    15. <select id="all" resultType="com.zking.spboot.model.Student">
    16. select <include refid="Base_Column_List" /> from t_student where 1=1
    17. <if test="sname!=null">
    18. and sname like concat('%',#{sname},'%')
    19. if>
    20. select>
    21. <insert id="insert" parameterType="com.zking.spboot.model.Student" >
    22. insert into t_student (sname, score,sex)
    23. values (#{sname,jdbcType=VARCHAR}, #{score,jdbcType=VARCHAR},#{sex,jdbcType=VARCHAR})
    24. insert>
    25. mapper>

    StudentService

    1. public interface StudentService {
    2. /**
    3. * 新增
    4. * @param record
    5. * @return
    6. */
    7. int insert(Student record);
    8. /**
    9. * 查询
    10. * @param student
    11. * @return
    12. */
    13. List all(Student student);
    14. }

    StudentServiceImpl 

    1. @Service
    2. public class StudentServiceImpl implements StudentService {
    3. @Autowired
    4. private StudentMapper studentMapper;
    5. @Override
    6. public int insert(Student record) {
    7. return studentMapper.insert(record);
    8. }
    9. @Override
    10. public List all(Student student) {
    11. return studentMapper.all(student);
    12. }
    13. }

    StudentController层

    1. package com.zking.spboot.controller;
    2. import com.zking.spboot.model.Student;
    3. import com.zking.spboot.service.StudentService;
    4. import org.springframework.beans.factory.annotation.Autowired;
    5. import org.springframework.web.bind.annotation.RequestMapping;
    6. import org.springframework.web.bind.annotation.RestController;
    7. import java.util.HashMap;
    8. import java.util.List;
    9. import java.util.Map;
    10. @RestController
    11. @RequestMapping("/student")
    12. public class StudentController {
    13. @Autowired
    14. private StudentService studentService;
    15. /**
    16. * 查询
    17. * @param student
    18. * @return
    19. */
    20. @RequestMapping("/list")
    21. public Map all(Student student){
    22. List all = studentService.all(student);
    23. Map rs=new HashMap<>();
    24. rs.put("code",200);
    25. rs.put("list",all);
    26. return rs;
    27. }
    28. /**
    29. * 新增
    30. * @param student
    31. * @return
    32. */
    33. @RequestMapping("/add")
    34. public Map add(Student student){
    35. int i = studentService.insert(student);
    36. Map rs=new HashMap<>();
    37. if (i>0)
    38. rs.put("code",200);
    39. return rs;
    40. }
    41. }

    api中action.js

    1. /**
    2. * 对后台请求的地址的封装,URL格式如下:
    3. * 模块名_实体名_操作
    4. */
    5. export default {
    6. //服务器
    7. 'SERVER': 'http://localhost:8080/spboot',
    8. 'ADD':'/student/add',
    9. 'ALL':'/student/list',
    10. //获得请求的完整地址,用于mockjs测试时使用
    11. 'getFullPath': k => {
    12. return this.SERVER + this[k];
    13. }
    14. }

    views

    1. <template>
    2. <div>
    3. <el-form :inline="true">
    4. <el-form-item label="学生名称">
    5. <el-input v-model="sname" placeholder="书本名称">el-input>
    6. el-form-item>
    7. <el-form-item>
    8. <el-button type="primary" @click="query">查询el-button>
    9. <el-button type="primary" @click="open">新增el-button>
    10. el-form-item>
    11. el-form>
    12. <el-table :data="tableData" style="width: 100%">
    13. <el-table-column prop="sid" label="学生编号" width="180">
    14. el-table-column>
    15. <el-table-column prop="sname" label="学生名称" width="180">
    16. el-table-column>
    17. <el-table-column prop="score" label="学生成绩">
    18. el-table-column>
    19. <el-table-column prop="sex" label="学生性别">
    20. el-table-column>
    21. el-table>
    22. <el-dialog title="新增" :visible.sync="dialogFormVisible" @close="close">
    23. <el-form :model="student" :rules="rules" ref="student">
    24. <el-form-item prop="sname" label="学生名称" label-width="90px">
    25. <el-input v-model="student.sname" autocomplete="off">el-input>
    26. el-form-item>
    27. <el-form-item prop="score" label="学生成绩" label-width="90px">
    28. <el-input v-model="student.score" autocomplete="off">el-input>
    29. el-form-item>
    30. <el-form-item prop="sex" label="学生性别" label-width="90px">
    31. <el-select style="width: 100%;" v-model="student.sex" placeholder="请选择书本类型">
    32. <el-option label="玄幻" value="玄幻">el-option>
    33. <el-option label="文学" value="文学">el-option>
    34. el-select>
    35. el-form-item>
    36. el-form>
    37. <div slot="footer" class="dialog-footer">
    38. <el-button @click="dialogFormVisible = false">取 消el-button>
    39. <el-button type="primary" @click="save">确 定el-button>
    40. div>
    41. el-dialog>
    42. div>
    43. template>
    44. <script>
    45. export default {
    46. data: function() {
    47. return {
    48. ts: new Date().getTime(),
    49. //搜索框
    50. sname: '',
    51. //表格数据
    52. tableData: [],
    53. //弹出框是否显示
    54. dialogFormVisible: false,
    55. //弹出框数据
    56. student: {
    57. sname: '',
    58. score: '',
    59. sex: ''
    60. },
    61. //表单验证
    62. rules: {
    63. sname: [{
    64. required: true,
    65. message: '请输入书本名称',
    66. trigger: 'blur'
    67. }, ],
    68. score: [{
    69. required: true,
    70. message: '请输入书本价格',
    71. trigger: 'blur'
    72. }, ],
    73. sex: [{
    74. required: true,
    75. message: '请选择书本类型',
    76. trigger: 'change',
    77. }, ]
    78. }
    79. };
    80. },
    81. methods: {
    82. close: function() {
    83. //清空表单数据
    84. this.student = {
    85. sname: '',
    86. score: '',
    87. sex: ''
    88. };
    89. //清空表单验证
    90. this.$refs['student'].resetFields();
    91. },
    92. //新增方法
    93. save: function() {
    94. this.$refs['student'].validate((valid) => {
    95. if (valid) {
    96. let url = this.axios.urls.ADD;
    97. this.axios.post(url, this.student).then(resp => {
    98. let data = resp.data;
    99. if (data.code == 200) {
    100. //关闭弹出框
    101. this.dialogFormVisible = false;
    102. //再次查询列表方法
    103. this.query();
    104. } else {
    105. this.$message.error('新增失败!');
    106. }
    107. }).catch(err => {
    108. })
    109. } else {
    110. console.log('error submit!!');
    111. return false;
    112. }
    113. });
    114. },
    115. //查询方法
    116. query: function() {
    117. //1.定义查询参数
    118. let params = {
    119. sname: this.sname
    120. };
    121. //2.获取请求路径
    122. let url = this.axios.urls.ALL;
    123. //3.发起ajax请求
    124. this.axios.post(url, params).then(resp => {
    125. let data = resp.data;
    126. this.tableData = data.list;
    127. console.log(data);
    128. }).catch(err => {
    129. console.log(err);
    130. })
    131. },
    132. //打开弹出框的方法
    133. open: function() {
    134. this.dialogFormVisible = true;
    135. }
    136. }
    137. }
    138. script>
    139. <style>
    140. style>

     views


     

     
     

     views 


     

     
     

  • 相关阅读:
    python使用pandas中的read_csv函数读取csv数据为dataframe、使用isnull函数查看数据中是否包含缺失值
    Ansys(Maxwell、Simplorer)与Simulink联合仿真(二)直线电机
    Spring STOMP-权限
    Codeforces Round #802 (Div. 2) C D
    基于hexo框架快速从0到1搭建个人博客----文章写作(四)
    Qt之元对象metaObject
    AI变现之数字人工具库账号引流
    基于 CentOS7 制作 Apache HTTPD 2.4.58 的RPM安装包
    day58 单调栈.p1
    年搜索量超 7 亿次背后:这款 APP 用火山引擎 DataTester 完成“数据驱动”
  • 原文地址:https://blog.csdn.net/weixin_62356088/article/details/127824590