当前位置:   article > 正文

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

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

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/663539
推荐阅读
相关标签
  

闽ICP备14008679号