Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_45598856
white-jotter
提交
510be01d
W
white-jotter
项目概览
qq_45598856
/
white-jotter
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
white-jotter
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
510be01d
编写于
4月 06, 2019
作者:
E
Evan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update: 实现图书搜索功能(支持模糊查询)
上级
214d70ef
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
92 addition
and
23 deletion
+92
-23
wj-vue/src/components/library/Books.vue
wj-vue/src/components/library/Books.vue
+24
-18
wj-vue/src/components/library/EditForm.vue
wj-vue/src/components/library/EditForm.vue
+2
-2
wj-vue/src/components/library/SearchBar.vue
wj-vue/src/components/library/SearchBar.vue
+35
-0
wj/src/main/java/com/gm/wj/controller/LibraryController.java
wj/src/main/java/com/gm/wj/controller/LibraryController.java
+11
-2
wj/src/main/java/com/gm/wj/dao/BookDAO.java
wj/src/main/java/com/gm/wj/dao/BookDAO.java
+3
-1
wj/src/main/java/com/gm/wj/pojo/Search.java
wj/src/main/java/com/gm/wj/pojo/Search.java
+13
-0
wj/src/main/java/com/gm/wj/service/BookService.java
wj/src/main/java/com/gm/wj/service/BookService.java
+4
-0
未找到文件。
wj-vue/src/components/library/Books.vue
浏览文件 @
510be01d
<
template
>
<div>
<div
style=
"margin-bottom: 10px;display: flex;justify-content: center;align-items: center"
>
<el-input
placeholder=
"默认展示部分书籍,可以通过书名搜索更多书籍..."
prefix-icon=
"el-icon-search"
size=
"small"
style=
"width: 400px;margin-right: 10px"
v-model=
"keywords"
>
</el-input>
<el-button
size=
"small"
type=
"primary"
icon=
"el-icon-search"
@
click=
"searchClick"
>
搜索
</el-button>
</div>
<search-bar
@
onSearch=
"searchResult"
ref=
"searchBar"
></search-bar>
<el-tooltip
effect=
"dark"
placement=
"right"
v-for=
"(item,index) in books"
:key=
"item.id"
v-loading=
"cardLoading[index]"
>
<p
slot=
"content"
style=
"font-size: 14px;margin-bottom: 6px;"
>
{{
item
.
title
}}
</p>
...
...
@@ -33,15 +24,16 @@
<div
class=
"author"
>
{{
item
.
author
}}
</div>
</el-card>
</el-tooltip>
<
add-or-update-button
@
onSubmit=
"loadBooks()"
ref=
"add"
></add-or-update-button
>
<
edit-form
@
onSubmit=
"loadBooks()"
ref=
"edit"
></edit-form
>
</div>
</
template
>
<
script
>
import
AddOrUpdateButton
from
'
./AddOrUpdateButton
'
import
EditForm
from
'
./EditForm
'
import
SearchBar
from
'
./SearchBar
'
export
default
{
name
:
'
BookCard
'
,
components
:
{
AddOrUpdateButton
},
components
:
{
EditForm
,
SearchBar
},
mounted
:
function
()
{
this
.
loadBooks
()
},
...
...
@@ -58,6 +50,21 @@
}
})
},
searchResult
()
{
var
_this
=
this
this
.
$axios
.
post
(
'
/search
'
,
{
keywords
:
this
.
$refs
.
searchBar
.
keywords
}).
then
(
resp
=>
{
if
(
resp
&&
resp
.
status
===
200
)
{
_this
.
books
=
resp
.
data
var
length
=
resp
.
data
.
length
_this
.
cardLoading
=
Array
.
apply
(
null
,
Array
(
length
)).
map
(
function
(
item
,
i
)
{
return
false
})
}
})
},
deleteBook
(
id
)
{
this
.
$confirm
(
'
此操作将永久删除该书籍, 是否继续?
'
,
'
提示
'
,
{
confirmButtonText
:
'
确定
'
,
...
...
@@ -80,8 +87,8 @@
// alert(id)
},
editBook
(
item
)
{
this
.
$refs
.
add
.
dialogFormVisible
=
true
this
.
$refs
.
add
.
form
=
{
this
.
$refs
.
edit
.
dialogFormVisible
=
true
this
.
$refs
.
edit
.
form
=
{
id
:
item
.
id
,
cover
:
item
.
cover
,
title
:
item
.
title
,
...
...
@@ -92,11 +99,10 @@
}
}
},
data
:
function
()
{
data
()
{
return
{
books
:
[],
cardLoading
:
[],
keywords
:
''
cardLoading
:
[]
}
}
}
...
...
wj-vue/src/components/library/
AddOrUpdateButton
.vue
→
wj-vue/src/components/library/
EditForm
.vue
浏览文件 @
510be01d
<
template
>
<div>
<i
class=
"el-icon-circle-plus-outline"
@
click=
"dialogFormVisible = true"
></i>
<el-dialog
title=
"添加图书"
:visible.sync=
"dialogFormVisible"
>
<el-dialog
title=
"添加
/修改
图书"
:visible.sync=
"dialogFormVisible"
>
<el-form
:model=
"form"
style=
"text-align: left"
>
<el-form-item
label=
"书名"
:label-width=
"formLabelWidth"
>
<el-input
v-model=
"form.title"
autocomplete=
"off"
placeholder=
"不加《》"
></el-input>
...
...
@@ -38,7 +38,7 @@
<
script
>
export
default
{
name
:
'
AddButton
'
,
name
:
'
EditForm
'
,
data
()
{
return
{
dialogFormVisible
:
false
,
...
...
wj-vue/src/components/library/SearchBar.vue
0 → 100644
浏览文件 @
510be01d
<
template
>
<div
style=
"margin-bottom: 10px;display: flex;justify-content: center;align-items: center"
>
<el-input
@
keyup.enter.native=
"searchClick"
placeholder=
"通过书名或作者搜索..."
prefix-icon=
"el-icon-search"
size=
"small"
style=
"width: 400px;margin-right: 10px"
v-model=
"keywords"
>
</el-input>
<el-button
size=
"small"
type=
"primary"
icon=
"el-icon-search"
@
click=
"searchClick"
>
搜索
</el-button>
</div>
</
template
>
<
script
>
export
default
{
name
:
'
SearchBar
'
,
data
()
{
return
{
keywords
:
''
,
books
:
[],
cardLoading
:
[]
}
},
methods
:
{
searchClick
()
{
this
.
$emit
(
'
onSearch
'
)
}
}
}
</
script
>
<
style
scoped
>
</
style
>
wj/src/main/java/com/gm/wj/controller/LibraryController.java
浏览文件 @
510be01d
package
com.gm.wj.controller
;
import
com.gm.wj.pojo.Book
;
import
com.gm.wj.pojo.Search
;
import
com.gm.wj.service.BookService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.List
;
@RestController
public
class
LibraryController
{
@Autowired
...
...
@@ -33,4 +32,14 @@ public class LibraryController {
bookService
.
deleteById
(
book
.
getId
());
// System.out.println(book.getId());
}
@CrossOrigin
@PostMapping
(
value
=
"/api/search"
)
public
List
<
Book
>
searchResult
(
@RequestBody
Search
s
)
throws
Exception
{
if
(
""
.
equals
(
s
.
getKeywords
()))
{
return
bookService
.
list
();
}
else
{
return
bookService
.
Search
(
s
.
getKeywords
());
}
}
}
wj/src/main/java/com/gm/wj/dao/BookDAO.java
浏览文件 @
510be01d
...
...
@@ -3,6 +3,8 @@ package com.gm.wj.dao;
import
com.gm.wj.pojo.Book
;
import
org.springframework.data.jpa.repository.JpaRepository
;
public
interface
BookDAO
extends
JpaRepository
<
Book
,
Integer
>
{
import
java.util.List
;
public
interface
BookDAO
extends
JpaRepository
<
Book
,
Integer
>
{
List
<
Book
>
findAllByTitleLikeOrAuthorLike
(
String
keyword1
,
String
keyword2
);
}
wj/src/main/java/com/gm/wj/pojo/Search.java
0 → 100644
浏览文件 @
510be01d
package
com.gm.wj.pojo
;
public
class
Search
{
String
keywords
;
public
String
getKeywords
()
{
return
keywords
;
}
public
void
setKeywords
(
String
keywords
)
{
this
.
keywords
=
keywords
;
}
}
wj/src/main/java/com/gm/wj/service/BookService.java
浏览文件 @
510be01d
...
...
@@ -25,4 +25,8 @@ public class BookService {
public
void
deleteById
(
int
id
)
{
bookDAO
.
deleteById
(
id
);
}
public
List
<
Book
>
Search
(
String
keywords
)
{
return
bookDAO
.
findAllByTitleLikeOrAuthorLike
(
'%'
+
keywords
+
'%'
,
'%'
+
keywords
+
'%'
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录