导航:

pre:  5.读者管理

next:7.借阅图书

只挑重点的讲,具体的请看项目源码。

1.项目源码

需要源码的朋友,请捐赠任意金额后留下邮箱发送:)

2.页面设计

2.1 book.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> <head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>图书管理</title>
<link rel="stylesheet" href="/static/layui/css/layui.css" th:href="@{/static/layui/css/layui.css}">
</head> <body>
<input type="text" id="ctx" hidden="hidden" th:value="${#request.getContextPath()}">
<!-- 内容主体区域 -->
<div>
<div class="search-div">
<div class="">
<div class="layui-inline">
<label class="layui-form-label">名称:</label>
<div class="layui-input-inline">
<input class="layui-input" id="name" name="name" autocomplete="off">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">ISBN:</label>
<div class="layui-input-inline">
<input class="layui-input" id="isbn" name="isbn" autocomplete="off">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">作者:</label>
<div class="layui-input-inline">
<input class="layui-input" id="author" name="author" autocomplete="off">
</div>
</div> <button class="layui-btn" data-type="reload" id="search">搜索</button>
</div> </div> <table id="tb-book" lay-filter="tb-book"></table> </div> <!--编辑表单-->
<script type="text/html" id="book-toolbar">
<div class="layui-btn-container">
<button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon"></i>新增</button>
<button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="remove"><i class="layui-icon"></i>删除
</button>
<button class="layui-btn layui-btn-sm" lay-event="refresh"><i class="layui-icon"></i>刷新
</button>
</div>
<!--<div class="layui-btn-container">
<button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
<button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
<button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
</div>-->
</script> <script type="text/html" id="barOps">
<a class="layui-btn layui-btn-sm" lay-event="edit"><i class="layui-icon"></i> </a>
</script> <script src="/static/js/jquery-1.11.3.min.js" th:src="@{/static/js/jquery-1.11.3.min.js}"></script>
<script src="/static/layui/layui.all.js" th:src="@{static/layui/layui.all.js}"></script>
<script src="/static/js/util.js" th:src="@{/static/js/util.js}"></script> <!--ctx-->
<script th:replace="~{fragment::ctx}"/> <script>
var element, layer, laydate, table, form,userTable; function reload(){
userTable.reload();
} $(function () {
// 使用模块
layui.use(['element', 'layer', 'laydate', 'table', 'form'], function () {
element = layui.element;
layer = layui.layer;
laydate = layui.laydate;
table = layui.table;
form = layui.form;
}); //第一个实例
userTable = table.render({
elem: '#tb-book'
, height: 515
, url: ctx+'api/book/list' //数据接口
, page: true //开启分页
, toolbar: '#book-toolbar'
,id: 'tb-book'
/*,request: {
pageName: 'pageNo' //页码的参数名称,默认:page
,limitName: 'pageSize' //每页数据量的参数名,默认:limit
}
, response: {
statusName: 'code', //规定返回的状态码字段为code
statusCode: 200 //规定成功的状态码为200,默认为0
}
, parseData: function (res) {
return {
"code": res.code, //解析接口状态
"msg": res.msg, //解析提示文本
"count": res.records, //解析数据长度
"data": res.rows //解析数据列表
}
}*/
, cols: [
[ //表头
{type: 'checkbox', fixed: 'left'}
, {field: 'id', title: 'ID', width: 80, sort: true, fixed: 'left',hide:true}
, {field: 'name', title: '图书名称', width: 180}
, {field: 'isbn', title: 'ISBN码', width: 160}
, {field: 'author', title: '作者', width: 80}
, {field: 'translator', title: '译者', width: 80}
, {field: 'categoryName', title: '图书分类', width: 160}
, {field: 'price', title: '图书单价', width: 120}
, {field: 'totalNumber', title: '藏书总量', width: 120}
, {field: 'leftNumber', title: '馆内剩余', width: 120}
, {field: 'publisherName', title: '出版社', width: 180}
, {field: 'pages', title: '页数', width: 80}
, {field: 'words', title: '字数', width: 80}
, {field: 'locationName', title: '存放位置', width: 120}
, {field: 'edition', title: '版次', width: 80}
, {field: 'registerTime', title: '登记日期', width: 120}
, {field: 'remark', title: '备注', width: 180}
, {fixed: 'right', title: '操作', toolbar: '#barOps', width: 120}
]
]
}); //监听表单提交
// 修改
form.on('submit(saveBook)', function (data) {
layer.alert(JSON.stringify(data.field));
$.ajax({
url: ctx+'api/book/save',
type: 'POST',
contentType: "application/json",
dataType: "json",
data: JSON.stringify(data.field),
success: function (result) {
if (result.code == 200) {
// layer.msg("修改成功!", {icon: 6});
cleanForm("#saveBook");
if(data.field.id.length>0){
layer.closeAll();//关闭所有的弹出层
}
userTable.reload();
}else {
layer.alert(result.message);
}
}
}); return false; }); //工具栏事件
table.on('toolbar(tb-book)', function (obj) {
var checkStatus = table.checkStatus(obj.config.id);
var checkData = checkStatus.data;
var ids = [];
switch (obj.event) {
// 新增
case 'add':
cleanForm("#saveBook"); top.layer.open({
type: 2,
offset: '10px',
title: "新增图书",
area: ['800px', '660px'],
content: ['bookAdd']
}); break;
// 删除
case 'remove':
if (checkData.length == 0) {
layer.alert('请选择要操作的行');
} else {
layer.confirm('确定要删除吗?', function (index) {
for (var i = 0; i < checkData.length; i++) {
ids.push(checkData[i].id);
}
//layer.alert(JSON.stringify(ids));
$.ajax({
url: ctx+'api/book/remove',
type: 'POST',
contentType: "application/json",
dataType: "json",
data: JSON.stringify(ids),
success: function (result) {
if (result.code == 200) {
setTimeout(function () {
layer.closeAll();//关闭所有的弹出层
userTable.reload();
}, 300);
}else {
layer.msg("操作失败!", {icon: 5});
}
}
});
});
}
break;
case 'refresh':
userTable.reload();
break;
case 'getCheckData':
layer.alert(JSON.stringify(data));
break;
case 'getCheckLength':
var data = checkStatus.data;
layer.msg('选中了:' + data.length + ' 个');
break;
case 'isAll':
layer.msg(checkStatus.isAll ? '全选' : '未全选')
break;
}
;
}); // 监听工具条
table.on('tool(tb-book)', function (obj) {
var data = obj.data;
// 修改
if (obj.event === 'edit') {
top.layer.open({
type: 2,
offset: '10px',
title: "修改图书",
area: ['800px', '660px'],
content: [ctx+'bookEdit/'+data.id]
});
}
}); // 搜索
$('#search').click(function () {
var name = $('#name').val();
var isbn = $('#isbn').val();
var author = $('#author').val();
table.reload('tb-book', {
url: ctx+'api/book/list'
,where: {
name:name,isbn:isbn,author:author
}
,page: {
curr: 1
}
});
});
}); </script>
</body> </html>

3.图书管理service

/**
* @Description: 图书服务
* @Author laoxu
* @Date 2019/5/2 9:26
**/
@Service
public class BookService extends AbstractService {
public void add(Book entity) {
//String username = SecurityUtil.getLoginUser();
insert("bookMapper.insert",entity);
} public void modify(Book entity) {
update("bookMapper.update",entity);
} public void remove(Long id) {
delete("bookMapper.delete",id);
} public void removes(Long[] ids) {
delete("bookMapper.deletes",ids);
} public Book get(Long id) {
return selectOne("bookMapper.select",id);
} public Book getByIsbn(String isbn) {
return selectOne("bookMapper.selectByIsbn",isbn);
} public List<Book> getParentList(Long id) {
return selectList("bookMapper.selectParentList",id);
} public int count(Map<String, Object> param) {
return selectOne("bookMapper.count",param);
} public List<Book> getList(Map<String, Object> param) {
return selectList("bookMapper.selectList",param);
} public List<Book> getPageResult(Map<String, Object> param) {
return selectList("bookMapper.selectPageResult",param);
} public int checkCode(Book entity){
return selectOne("bookMapper.countCode",entity);
} }

4.图书管理controller

/**
* @Description: 图书控制器
* @Author laoxu
* @Date 2019/5/2 10:16
**/
@RestController
@RequestMapping("/api/book")
public class BookController {
@Autowired
BookService bookService; /**
* 保存(新增/修改)
*
* @param entity
* @return
*/
@PostMapping("/save")
public Result<String> modify(@RequestBody Book entity) {
String code = entity.getIsbn();
int count = bookService.checkCode(entity);
if(count>0){
return ResultUtil.fail("ISBN已存在!");
}
if(entity.getId()!=null){
bookService.modify(entity);
}else{
bookService.add(entity);
} return ResultUtil.ok();
} @PostMapping("/remove")
public Result<String> remove(@RequestBody Long[] ids) {
bookService.removes(ids);
return ResultUtil.ok();
} @GetMapping("/get")
public Result<Book> get(@RequestParam("id") Long id) {
Book entity = bookService.get(id); return ResultUtil.ok(entity);
} @GetMapping("/list")
public ResultBean<List<Book>> getPageResult(
@RequestParam(required = false) String name,
@RequestParam(required = false) String isbn,
@RequestParam(required = false) String author,
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer limit) { Map<String, Object> param = new HashMap<>(); // 计算起始行号
int offset = (page - 1) * limit;
int rows = limit; param.put("name",name);
param.put("isbn",isbn);
param.put("author",author);
param.put("offset", offset);
param.put("rows", rows); // 统计记录数
int totalRows = bookService.count(param); // 获取当前页结果集
List<Book> entities = bookService.getPageResult(param); ResultBean result = new ResultBean(0, "查询成功", totalRows, entities); return result; }
}

Spring Boot图书管理系统项目实战-6.图书管理的更多相关文章

  1. Spring Boot → 11:项目实战-账单管理系统完整版

    Spring Boot → 11:项目实战-账单管理系统完整版

  2. Spring Boot → 06:项目实战-账单管理系统

    Spring Boot → 06:项目实战-账单管理系统

  3. Java 架构师+高并发+性能优化+Spring boot大型分布式项目实战

    视频课程内容包含: 高级 Java 架构师包含:Spring boot.Spring cloud.Dubbo.Redis.ActiveMQ.Nginx.Mycat.Spring.MongoDB.Zer ...

  4. 新书上线:《Spring Boot+Spring Cloud+Vue+Element项目实战:手把手教你开发权限管理系统》,欢迎大家买回去垫椅子垫桌脚

    新书上线 大家好,笔者的新书<Spring Boot+Spring Cloud+Vue+Element项目实战:手把手教你开发权限管理系统>已上线,此书内容充实.材质优良,乃家中必备垫桌脚 ...

  5. 图书-技术-SpringBoot:《Spring Boot 企业级应用开发实战》

    ylbtech-图书-技术-SpringBoot:<Spring Boot 企业级应用开发实战> Spring Boot 企业级应用开发实战,全书围绕如何整合以 Spring Boot 为 ...

  6. Linux-基础学习(四)-部署图书管理系统项目

    部署图书管理项目需要以下软件 项目文件(django项目文件夹) 数据库文件(django项目对应的数据库文件) centos7(linux本体) nginx(反向代理以及静态文件收集) uWSGI( ...

  7. Django学习——分组查询、图书管理系统项目、wsgi, uwsgi, cgi, fastcgi

    1 分组查询 # 分组查询 # 查询每一个出版社id,以及图书平均价格(单表) # 原生sql # select publish_id,avg(price) from app01_book group ...

  8. 从零一起学Spring Boot之LayIM项目长成记(五)websocket

    前言 距离上一篇已经比较久的时间了,项目也是开了个头.并且,由于网上的关于Spring Boot的websocket讲解也比较多.于是我采用了另外的一个通讯框架 t-io 来实现LayIM中的通讯功能 ...

  9. Spring Boot会员管理系统——处理文件上传

    温馨提示 Spring Boot会员管理系统的中,需要涉及到Spring框架,SpringMVC框架,Hibernate框架,thymeleaf模板引擎.所以,可以学习下这些知识.当然,直接入门的话使 ...

  10. 使用Spring Boot开发Web项目(二)之添加HTTPS支持

    上篇博客使用Spring Boot开发Web项目我们简单介绍了使用如何使用Spring Boot创建一个使用了Thymeleaf模板引擎的Web项目,当然这还远远不够.今天我们再来看看如何给我们的We ...

随机推荐

  1. GoMusic-歌单迁移工具网站 一键迁移网易云/QQ音乐歌单至 Apple/Youtube/Spotify Music

    GoMusic是什么: GoMusic是一个在线歌单迁移工具网站,帮助用户一键迁移网易云/QQ音乐歌单至 Apple/Youtube/Spotify Music,直接输入歌单链接,复制查询结果,打开 ...

  2. [转帖]mysql8 ALGORITHM=INSTANT 亿级数据秒速增加字段

    一.概述 登录后复制 在线DDL之快速增加列(秒级别的),并不会造成业务抖动.该功能自 MySQL 8.0.12 版本引入,是由腾讯游戏DBA团队贡献,此功能只适用于 InnoDB 表.实际上MySQ ...

  3. [转帖]TiDB 数据库核心原理与架构 [TiDB v6](101)笔记

    https://www.jianshu.com/p/01e49a93f671 description: "本课程专为将在工作中使用 TiDB 数据库的开发人员.DBA 和架构师设计. 本门课 ...

  4. [转帖]rsar - Extract data from plain-text sar files

    sar -A -t -f /tmp/sa11 >/tmp/sar11 https://github.com/ryran/rsar When dealing with sysstat sar da ...

  5. 【转帖】关于网卡特性TSO、UFO、GSO、LRO、GRO

    https://www.cnblogs.com/larrypeng/p/12496810.html 我们来看下关于网卡特性的解释,不过记住GSO和GRO两个特性就好. TSO(TCP Segmenta ...

  6. reposync与createrepo创建离线yum源的方法

    背景 昨天晚上进行了在线升级银河麒麟V10SP2的audit和mate-indicator的rpm包 今天想了下,如果机器无法上网. 必须得在公司内部搭建一套离线的rpm源进行处理 想了下还是使用re ...

  7. 基于javaPoet的缓存key优化实践

    一. 背景 在一次系统opsreview中,发现了一些服务配置了@Cacheable注解.@cacheable 来源于spring cache框架中,作用是使用aop的方式将数据库中的热数据缓存在re ...

  8. git中git cherry-pick的使用

    git中git cherry-pick的使用 A分支是从远端的开发分支dev拉取的 B分支是从远端的测试分支rel拉取的 现在我们遇见一个问题. 我们在A分支修改了代码.并且推送到了远端的dev分支. ...

  9. 【JS 逆向百例】W店UA,OB反混淆,抓包替换CORS跨域错误分析

    关注微信公众号:K哥爬虫,持续分享爬虫进阶.JS/安卓逆向等技术干货! 声明 本文章中所有内容仅供学习交流,抓包内容.敏感网址.数据接口均已做脱敏处理,严禁用于商业用途和非法用途,否则由此产生的一切后 ...

  10. 解决VS选择运行“在证书存储区中找不到清单签名证书”

     转:https://www.cnblogs.com/190196539/archive/2011/12/03/2272861.html 解决"在证书存储区中找不到清单签名证书" ...