• Springboot快速开发-书本信息管理系统(项目源码)


    【我后续会发一个资源包,里面是所有代码,数据库表设计也有,大学生可以直接用,导入数据库运行,再导入后端项目和前端项目,再去网页运行就好了,效果图下面有】

     

    1、考核要求:

    1. 数据库:MYSQL5.7+
    2. 后台技术:SpringBoot
    3. 前端技术:vue+elementui
    4. 代码简洁、有合理的注解,前面页面排版工整

    2、考核注意事项

    1.运行sql脚本,创建数据库及书本表(根据我的实体类建表就可以了,整个项目可直接运行,跨域问题已处理,前后端的端口也已处理)

    2.后台代码注意事项

            a.Maven地址的修改(修改成你自己的);

            b.依赖可能不在本地,需要联网重新下载;

            c.jdbc.properties设置,数据库相关配置:数据库名/账号/密码,请修改成自己电脑所对应的账号和密码。

            d.generatorConfig.xml设置:Ⅰ:修改classPathEntry配置,更换成本地maven仓库中mysql数据库jdbc驱动jar包的位置;Ⅱ:修改table配置表信息(tableName和domainObjectName),更换成考试中对应数据库表;Ⅲ:点击Edit Configurations...配置,添加Maven,输入命名:mybatis-gerenator:gerenate -e;

            e.application.yml设置:数据库相关设置:数据库名/帐号/密码,请修改成自己电脑对应的帐号和密码

            f.由于电脑tomcat以及jdk的安装位置不一样,请重新配置jdk和tomcat

            g.以上步骤完成,先不要写任何代码,先将web项目发布至tomcat并启动,如果首页访问成功,表示web项目部署成功,可以开始编写后台代码了

    3.前端代码注意事项:

    1.vue项目框架已搭建完成,为减小源码大小,相关模块已删除,运行项目前,请先进入vue项目根目录,使用npm install命令下载相关模块(此步骤需要联网)

    2.项目启动后无需添加路由或*.vue文件,运行后会直接跳转到BookList.vue,在此vue文件中添加相关功能即可

    3.开动

    generatorConfig.xml、jdbc.properties、application.yml这三个配置文件我就不展示了,有需要的下载我的资源包

    数据库表建好之后→导入前端(可以把需要的依赖先下载,然后干自己的事)→导入后端(进行我上面所说的那些后端操作)→写完代码运行后端→在写前端代码(运行前端)

    以下是后端的代码:

    Model层:Book

    1. package com.zking.spboot.model;
    2. public class Book {
    3. private Integer id;
    4. private String bookname;
    5. private Float price;
    6. private String booktype;
    7. public Book(Integer id, String bookname, Float price, String booktype) {
    8. this.id = id;
    9. this.bookname = bookname;
    10. this.price = price;
    11. this.booktype = booktype;
    12. }
    13. public Book() {
    14. super();
    15. }
    16. public Integer getId() {
    17. return id;
    18. }
    19. public void setId(Integer id) {
    20. this.id = id;
    21. }
    22. public String getBookname() {
    23. return bookname;
    24. }
    25. public void setBookname(String bookname) {
    26. this.bookname = bookname;
    27. }
    28. public Float getPrice() {
    29. return price;
    30. }
    31. public void setPrice(Float price) {
    32. this.price = price;
    33. }
    34. public String getBooktype() {
    35. return booktype;
    36. }
    37. public void setBooktype(String booktype) {
    38. this.booktype = booktype;
    39. }
    40. }

    Mapper层:BookMapper

    1. package com.zking.spboot.mapper;
    2. import com.zking.spboot.model.Book;
    3. import org.springframework.stereotype.Repository;
    4. import java.util.List;
    5. @Repository
    6. public interface BookMapper {
    7. /**
    8. * 根据书本名称模糊查询
    9. * @param book
    10. * @return
    11. */
    12. List queryAll(Book book);
    13. int deleteByPrimaryKey(Integer id);
    14. int insert(Book record);
    15. int insertSelective(Book record);
    16. Book selectByPrimaryKey(Integer id);
    17. int updateByPrimaryKeySelective(Book record);
    18. int updateByPrimaryKey(Book record);
    19. }

    BookMapper.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.BookMapper" >
    4. <resultMap id="BaseResultMap" type="com.zking.spboot.model.Book" >
    5. <constructor >
    6. <idArg column="id" jdbcType="INTEGER" javaType="java.lang.Integer" />
    7. <arg column="bookname" jdbcType="VARCHAR" javaType="java.lang.String" />
    8. <arg column="price" jdbcType="REAL" javaType="java.lang.Float" />
    9. <arg column="booktype" jdbcType="VARCHAR" javaType="java.lang.String" />
    10. constructor>
    11. resultMap>
    12. <sql id="Base_Column_List" >
    13. id, bookname, price, booktype
    14. sql>
    15. <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    16. select
    17. <include refid="Base_Column_List" />
    18. from t_book
    19. where id = #{id,jdbcType=INTEGER}
    20. select>
    21. <select id="queryAll" resultType="com.zking.spboot.model.Book">
    22. select <include refid="Base_Column_List"/> from t_book where 1=1
    23. <if test="null!=bookname and ''!=bookname">
    24. and bookname like concat('%',#{bookname},'%')
    25. if>
    26. select>
    27. <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    28. delete from t_book
    29. where id = #{id,jdbcType=INTEGER}
    30. delete>
    31. <insert id="insert" parameterType="com.zking.spboot.model.Book" >
    32. insert into t_book (id, bookname, price,
    33. booktype)
    34. values (#{id,jdbcType=INTEGER}, #{bookname,jdbcType=VARCHAR}, #{price,jdbcType=REAL},
    35. #{booktype,jdbcType=VARCHAR})
    36. insert>
    37. <insert id="insertSelective" parameterType="com.zking.spboot.model.Book" >
    38. insert into t_book
    39. <trim prefix="(" suffix=")" suffixOverrides="," >
    40. <if test="id != null" >
    41. id,
    42. if>
    43. <if test="bookname != null" >
    44. bookname,
    45. if>
    46. <if test="price != null" >
    47. price,
    48. if>
    49. <if test="booktype != null" >
    50. booktype,
    51. if>
    52. trim>
    53. <trim prefix="values (" suffix=")" suffixOverrides="," >
    54. <if test="id != null" >
    55. #{id,jdbcType=INTEGER},
    56. if>
    57. <if test="bookname != null" >
    58. #{bookname,jdbcType=VARCHAR},
    59. if>
    60. <if test="price != null" >
    61. #{price,jdbcType=REAL},
    62. if>
    63. <if test="booktype != null" >
    64. #{booktype,jdbcType=VARCHAR},
    65. if>
    66. trim>
    67. insert>
    68. <update id="updateByPrimaryKeySelective" parameterType="com.zking.spboot.model.Book" >
    69. update t_book
    70. <set >
    71. <if test="bookname != null" >
    72. bookname = #{bookname,jdbcType=VARCHAR},
    73. if>
    74. <if test="price != null" >
    75. price = #{price,jdbcType=REAL},
    76. if>
    77. <if test="booktype != null" >
    78. booktype = #{booktype,jdbcType=VARCHAR},
    79. if>
    80. set>
    81. where id = #{id,jdbcType=INTEGER}
    82. update>
    83. <update id="updateByPrimaryKey" parameterType="com.zking.spboot.model.Book" >
    84. update t_book
    85. set bookname = #{bookname,jdbcType=VARCHAR},
    86. price = #{price,jdbcType=REAL},
    87. booktype = #{booktype,jdbcType=VARCHAR}
    88. where id = #{id,jdbcType=INTEGER}
    89. update>
    90. mapper>

    Service层:BookService

    1. package com.zking.spboot.service;
    2. import com.zking.spboot.model.Book;
    3. import org.springframework.stereotype.Repository;
    4. import java.util.List;
    5. public interface BookService {
    6. /**
    7. * 根据书本名称模糊查询
    8. * @param book
    9. * @return
    10. */
    11. List queryAll(Book book);
    12. /**
    13. * 新增书本
    14. * @param record
    15. * @return
    16. */
    17. int insert(Book record);
    18. }

    impl层:BookServiceImpl

    1. package com.zking.spboot.service.impl;
    2. import com.zking.spboot.mapper.BookMapper;
    3. import com.zking.spboot.model.Book;
    4. import com.zking.spboot.service.BookService;
    5. import org.springframework.beans.factory.annotation.Autowired;
    6. import org.springframework.stereotype.Service;
    7. import java.util.List;
    8. /**
    9. * 实现类
    10. */
    11. @Service
    12. public class BookServiceImpl implements BookService {
    13. @Autowired
    14. private BookMapper bookMapper;
    15. @Override
    16. public List queryAll(Book book) {
    17. return bookMapper.queryAll(book);
    18. }
    19. @Override
    20. public int insert(Book record) {
    21. return bookMapper.insert(record);
    22. }
    23. }

    Controller层:BookController

    1. package com.zking.spboot.controller;
    2. import com.zking.spboot.model.Book;
    3. import com.zking.spboot.service.BookService;
    4. import lombok.AllArgsConstructor;
    5. import lombok.Data;
    6. import lombok.NoArgsConstructor;
    7. import org.springframework.beans.factory.annotation.Autowired;
    8. import org.springframework.web.bind.annotation.RequestMapping;
    9. import org.springframework.web.bind.annotation.RestController;
    10. import java.util.List;
    11. @RestController
    12. @RequestMapping("/book")
    13. public class BookController {
    14. @Autowired
    15. private BookService bookService;
    16. @RequestMapping("/addBook")
    17. public JsonResponsBody addBook(Book book){
    18. bookService.insert(book);
    19. return new JsonResponsBody<>();
    20. }
    21. @RequestMapping("/queryAll")
    22. public JsonResponsBody> queryAll(Book book){
    23. List books = bookService.queryAll(book);
    24. return new JsonResponsBody<>(200,"OK",books);
    25. }
    26. @Data
    27. @AllArgsConstructor
    28. @NoArgsConstructor
    29. class JsonResponsBody{
    30. private int code=200;
    31. private String mag="Ok";
    32. private T data;
    33. }
    34. }

    跨域问题处理:

    1. package com.zking.spboot;
    2. import org.apache.ibatis.annotations.Mapper;
    3. import org.mybatis.spring.annotation.MapperScan;
    4. import org.springframework.boot.SpringApplication;
    5. import org.springframework.boot.autoconfigure.SpringBootApplication;
    6. import org.springframework.context.annotation.EnableAspectJAutoProxy;
    7. import org.springframework.transaction.annotation.EnableTransactionManagement;
    8. @MapperScan("com.zking.spboot.mapper")
    9. @EnableTransactionManagement
    10. @EnableAspectJAutoProxy
    11. @SpringBootApplication
    12. public class SpbootApplication {
    13. public static void main(String[] args) {
    14. SpringApplication.run(SpbootApplication.class, args);
    15. }
    16. }

    以下是前端的代码:

    前端接收后端的请求路径,src下面api下面的action.js

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

     前端src下面的router下面的index.js

    1. import Vue from 'vue'
    2. import Router from 'vue-router'
    3. import BookList from '@/views/BookList'
    4. Vue.use(Router)
    5. export default new Router({
    6. routes: [
    7. {
    8. path: '/',
    9. name: 'BookList',
    10. component: BookList
    11. }
    12. ]
    13. })

    前端页面:

    1. <template>
    2. <div>
    3. <el-form :inline="true">
    4. <el-form-item label="书本名称">
    5. <el-input v-model="bookname" 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="id" label="书本编号" width="180">
    14. el-table-column>
    15. <el-table-column prop="bookname" label="书本名称" width="180">
    16. el-table-column>
    17. <el-table-column prop="price" label="书本价格">
    18. el-table-column>
    19. <el-table-column prop="booktype" label="书本类型">
    20. el-table-column>
    21. el-table>
    22. <el-dialog title="新增" :visible.sync="dialogFormVisible" @close="close">
    23. <el-form :model="book" :rules="rules" ref="book">
    24. <el-form-item prop="bookname" label="书本名称" label-width="90px">
    25. <el-input v-model="book.bookname" autocomplete="off">el-input>
    26. el-form-item>
    27. <el-form-item prop="price" label="书本价格" label-width="90px">
    28. <el-input v-model="book.price" autocomplete="off">el-input>
    29. el-form-item>
    30. <el-form-item prop="booktype" label="书本类型" label-width="90px">
    31. <el-select style="width:100%;" v-model="book.booktype" 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. bookname: '',
    50. tableData: [],
    51. dialogFormVisible: false,
    52. book: {
    53. bookname: '',
    54. price: '',
    55. booktype: ''
    56. },
    57. rules: {
    58. bookname: [{
    59. required: true,
    60. message: '请输入书本名称',
    61. trigger: 'blur'
    62. }, ],
    63. price: [{
    64. required: true,
    65. message: '请输入书本价格',
    66. trigger: 'blur'
    67. }, ],
    68. booktype: [{
    69. required: true,
    70. message: '请选择书本类型',
    71. trigger: 'change'
    72. }, ]
    73. }
    74. };
    75. },
    76. methods: {
    77. close:function(){
    78. //清空表单数据
    79. this.book={
    80. bookname: '',
    81. price: '',
    82. booktype: ''
    83. };
    84. //清空表单验证
    85. this.$refs['book'].resetFields();
    86. },
    87. save: function() {
    88. this.$refs['book'].validate((valid) => {
    89. if (valid) {
    90. let url=this.axios.urls.ADD;
    91. this.axios.post(url,this.book).then(resp => {
    92. let data = resp.data; //data --> date XXXXXX
    93. // {code:200,msg:'OK',data:[....]}
    94. if(data.code==200){
    95. //关闭弹出框
    96. this.dialogFormVisible=false;
    97. //再次查询列表方法
    98. this.query();
    99. }else{
    100. this.$message.error('新增失败!');
    101. }
    102. }).catch(err => {
    103. })
    104. } else {
    105. console.log('error submit!!');
    106. return false;
    107. }
    108. });
    109. },
    110. query: function() {
    111. //1.定义查询参数
    112. let params = {
    113. bookname: this.bookname
    114. };
    115. //2.获取请求路径
    116. let url = this.axios.urls.ALL;
    117. //3.发起ajax请求
    118. this.axios.post(url, params).then(resp => {
    119. let data = resp.data; //data --> date XXXXXX
    120. // {code:200,msg:'OK',data:[....]}
    121. console.log(data);
    122. this.tableData = data.data;
    123. }).catch(err => {
    124. })
    125. },
    126. open: function() {
    127. this.dialogFormVisible = true;
    128. }
    129. }
    130. }
    131. script>
    132. <style>
    133. style>

     以上就是今天的分享!!!

    刚好有大学生找我帮忙写这个项目,我想可以与大家分享一下代码,有其他同行需要代码的也可以找我。感谢支持!

  • 相关阅读:
    【解锁未来】探索Web3的无限可能性-01
    同花顺_代码解析_技术指标_V,W
    opencv快速入门(三)——图像几何变换
    Cookie和localStorage存储的区别
    llama2+localGPT打造纯私有知识助手
    request对象,类视图,HttpResponse对象,JsonResponse对象
    React之组件实例的三大属性之rel
    Gradle 出现 Could not resolve gradle
    王怀民院士:开源创新必将成为中国迈向世界科技强国的战略机遇
    高等工程数学 —— 第五章 (1)线性规划与单纯形法
  • 原文地址:https://blog.csdn.net/m0_62246061/article/details/127786329