Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_45598856
white-jotter
提交
3d303ad4
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,发现更多精彩内容 >>
提交
3d303ad4
编写于
6月 01, 2020
作者:
E
Evan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use redis to cache data
上级
01317381
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
59 addition
and
12 deletion
+59
-12
.travis.yml
.travis.yml
+1
-0
README.md
README.md
+2
-2
src/main/java/com/gm/wj/service/BookService.java
src/main/java/com/gm/wj/service/BookService.java
+30
-8
src/main/java/com/gm/wj/util/CastUtils.java
src/main/java/com/gm/wj/util/CastUtils.java
+24
-0
src/main/resources/application.properties
src/main/resources/application.properties
+2
-2
未找到文件。
.travis.yml
浏览文件 @
3d303ad4
...
...
@@ -18,6 +18,7 @@ before_install:
sevices
:
-
mysql
-
redis-server --port
6379
script
:
-
./mvnw clean install -B
\ No newline at end of file
README.md
浏览文件 @
3d303ad4
...
...
@@ -76,7 +76,7 @@
## 数据库
1.
MySQL
1.
MySQL
2.
Redis
# 部署方法
...
...
@@ -95,7 +95,7 @@
数据库完整脚本
`wj.sql`
放在后端项目的
`src\main\resources`
目录下,也可根据需要自行在 MySQL 中执行数据库脚本。
Redis
端口为 6379(默认端口),密码为空。
运行项目前请启动 Redis 服务,
端口为 6379(默认端口),密码为空。
3.
数据库配置在后端项目的
`src\main\resources`
目录下的
`application.properties`
文件中,mysql 版本为 8.0.15 。
...
...
src/main/java/com/gm/wj/service/BookService.java
浏览文件 @
3d303ad4
package
com.gm.wj.service
;
import
com.gm.wj.config.RedisConfig
;
import
com.gm.wj.dao.BookDAO
;
import
com.gm.wj.entity.Book
;
import
com.gm.wj.entity.Category
;
import
com.gm.wj.redis.RedisService
;
import
com.gm.wj.util.CastUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.processing.Processor
;
import
java.util.List
;
import
java.util.Timer
;
/**
* @author Evan
...
...
@@ -20,22 +20,44 @@ import java.util.List;
@Service
public
class
BookService
{
@Autowired
BookDAO
bookDAO
;
private
BookDAO
bookDAO
;
@Autowired
CategoryService
categoryService
;
private
CategoryService
categoryService
;
@Autowired
private
RedisService
redisService
;
// @Cacheable(value = RedisConfig.REDIS_KEY_DATABASE)
public
List
<
Book
>
list
()
{
Sort
sort
=
new
Sort
(
Sort
.
Direction
.
DESC
,
"id"
);
return
bookDAO
.
findAll
(
sort
);
String
key
=
"booklist"
;
List
<
Book
>
books
=
CastUtils
.
castList
(
redisService
.
get
(
key
),
Book
.
class
);
if
(
books
==
null
)
{
Sort
sort
=
new
Sort
(
Sort
.
Direction
.
DESC
,
"id"
);
books
=
bookDAO
.
findAll
(
sort
);
redisService
.
set
(
key
,
books
);
}
return
books
;
}
public
void
addOrUpdate
(
Book
book
)
{
redisService
.
delete
(
"booklist"
);
bookDAO
.
save
(
book
);
try
{
Thread
.
sleep
(
500
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
redisService
.
delete
(
"booklist"
);
}
public
void
deleteById
(
int
id
)
{
redisService
.
delete
(
"booklist"
);
bookDAO
.
deleteById
(
id
);
try
{
Thread
.
sleep
(
500
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
redisService
.
delete
(
"booklist"
);
}
public
List
<
Book
>
listByCategory
(
int
cid
)
{
...
...
src/main/java/com/gm/wj/util/CastUtils.java
0 → 100644
浏览文件 @
3d303ad4
package
com.gm.wj.util
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @author Evan
* @date 2020/5/31 19:04
*/
public
class
CastUtils
{
public
static
<
T
>
List
<
T
>
castList
(
Object
obj
,
Class
<
T
>
clazz
)
{
List
<
T
>
result
=
new
ArrayList
<
T
>();
if
(
obj
instanceof
List
<?>)
{
for
(
Object
o
:
(
List
<?>)
obj
)
{
result
.
add
(
clazz
.
cast
(
o
));
}
return
result
;
}
return
null
;
}
}
src/main/resources/application.properties
浏览文件 @
3d303ad4
...
...
@@ -13,8 +13,8 @@ spring.datasource.initialization-mode=always
spring.jpa.hibernate.ddl-auto
=
none
# 打印 sql 语句
#
spring.jpa.properties.hibernate.show_sql=true
#
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.show_sql
=
true
spring.jpa.properties.hibernate.format_sql
=
true
## Hikari 连接池配置
## 最小空闲连接数量
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录