Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
SpringBoot-kwan
提交
779aadfa
S
SpringBoot-kwan
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
SpringBoot-kwan
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SpringBoot-kwan
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
779aadfa
编写于
3月 23, 2023
作者:
Kwan的解忧杂货铺@新空间代码工作室
🐭
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:获取redis信息
上级
cc58c4cf
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
170 addition
and
24 deletion
+170
-24
src/main/java/com/kwan/springbootkwan/constant/CommonConstant.java
...java/com/kwan/springbootkwan/constant/CommonConstant.java
+20
-0
src/main/java/com/kwan/springbootkwan/controller/RedisController.java
...a/com/kwan/springbootkwan/controller/RedisController.java
+13
-13
src/main/java/com/kwan/springbootkwan/entity/Result.java
src/main/java/com/kwan/springbootkwan/entity/Result.java
+126
-0
src/main/resources/application.yaml
src/main/resources/application.yaml
+11
-11
未找到文件。
src/main/java/com/kwan/springbootkwan/constant/CommonConstant.java
0 → 100644
浏览文件 @
779aadfa
package
com.kwan.springbootkwan.constant
;
public
class
CommonConstant
{
/**
* 成功
*/
public
static
final
Integer
SC_OK_200
=
200
;
/**
* 服务器错误
*/
public
static
final
Integer
SC_INTERNAL_SERVER_ERROR_500
=
500
;
/**
* 未认证
*/
public
static
final
int
SC_JEECG_NO_AUTHZ
=
401
;
/**
* redis前缀
*/
public
static
final
String
PREFIX_REDIS_KEY
=
"test:"
;
}
src/main/java/com/kwan/springbootkwan/controller/RedisController.java
浏览文件 @
779aadfa
package
com.kwan.springbootkwan.controller
;
import
com.kwan.springbootkwan.entity.Result
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -10,35 +12,33 @@ import org.springframework.web.bind.annotation.RestController;
import
javax.annotation.Resource
;
import
java.util.concurrent.TimeUnit
;
import
static
com
.
kwan
.
springbootkwan
.
constant
.
CommonConstant
.
PREFIX_REDIS_KEY
;
@Slf4j
@Api
(
value
=
"redis测试信息"
,
tags
=
"RedisController"
)
@RestController
@RequestMapping
(
"/test"
)
public
class
RedisController
{
public
static
final
String
REDIS_KEY
=
"test:_w"
;
@Resource
private
RedisTemplate
redisTemplate
;
@ApiOperation
(
value
=
"redis添加数据"
,
notes
=
"redis添加数据"
)
@GetMapping
(
"/add"
)
public
void
add
()
{
//当前时间时间戳
String
nowStr
=
String
.
valueOf
(
System
.
currentTimeMillis
());
//设置redis中的key值
String
redisKey
=
REDIS_KEY
.
concat
(
nowStr
);
public
Result
add
(
String
key
,
String
value
)
{
//向对应的key值添加数据
redisTemplate
.
opsForValue
().
set
(
REDIS_KEY
,
"测试向redis中添加数据"
);
redisTemplate
.
opsForValue
().
set
(
PREFIX_REDIS_KEY
+
key
,
value
);
//设置过期时间
redisTemplate
.
expire
(
REDIS_KEY
,
2000000
,
TimeUnit
.
SECONDS
);
redisTemplate
.
expire
(
PREFIX_REDIS_KEY
,
2000000
,
TimeUnit
.
SECONDS
);
return
Result
.
ok
();
}
@ApiOperation
(
value
=
"redis获取数据"
,
notes
=
"redis获取数据"
)
@GetMapping
(
"/get"
)
public
void
get
(
)
{
public
Result
get
(
String
key
)
{
//获取redis中的数据
String
str
=
(
String
)
redisTemplate
.
opsForValue
().
get
(
REDIS_KEY
);
System
.
out
.
println
(
"获取redis中的数据-->"
+
str
);
String
value
=
(
String
)
redisTemplate
.
opsForValue
().
get
(
PREFIX_REDIS_KEY
+
key
);
log
.
info
(
"获取redis中的数据-->{}"
,
value
);
return
Result
.
ok
(
value
);
}
}
src/main/java/com/kwan/springbootkwan/entity/Result.java
0 → 100644
浏览文件 @
779aadfa
package
com.kwan.springbootkwan.entity
;
import
com.kwan.springbootkwan.constant.CommonConstant
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* 接口返回数据格式
*
* @author scott
* @email jeecgos@163.com
* @date 2019年1月19日
*/
@Data
@ApiModel
(
value
=
"接口返回对象"
,
description
=
"接口返回对象"
)
public
class
Result
<
T
>
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 成功标志
*/
@ApiModelProperty
(
value
=
"成功标志"
)
private
boolean
success
=
true
;
/**
* 返回处理消息
*/
@ApiModelProperty
(
value
=
"返回处理消息"
)
private
String
message
=
"操作成功!"
;
/**
* 返回代码
*/
@ApiModelProperty
(
value
=
"返回代码"
)
private
Integer
code
=
0
;
/**
* 返回数据对象 data
*/
@ApiModelProperty
(
value
=
"返回数据对象"
)
private
T
result
;
/**
* 时间戳
*/
@ApiModelProperty
(
value
=
"时间戳"
)
private
long
timestamp
=
System
.
currentTimeMillis
();
public
Result
()
{
}
public
Result
<
T
>
success
(
String
message
)
{
this
.
message
=
message
;
this
.
code
=
CommonConstant
.
SC_OK_200
;
this
.
success
=
true
;
return
this
;
}
public
Result
<
T
>
good
(
T
t
)
{
this
.
setResult
(
t
);
this
.
code
=
CommonConstant
.
SC_OK_200
;
this
.
success
=
true
;
return
this
;
}
public
Result
<
T
>
good
()
{
this
.
code
=
CommonConstant
.
SC_OK_200
;
this
.
success
=
true
;
this
.
setMessage
(
"成功"
);
return
this
;
}
public
Result
<
T
>
fail
(
String
msg
)
{
this
.
setCode
(
CommonConstant
.
SC_INTERNAL_SERVER_ERROR_500
);
this
.
setMessage
(
msg
);
this
.
setSuccess
(
false
);
return
this
;
}
public
static
Result
<
Object
>
ok
()
{
Result
<
Object
>
r
=
new
Result
<>();
r
.
setSuccess
(
true
);
r
.
setCode
(
CommonConstant
.
SC_OK_200
);
r
.
setMessage
(
"成功"
);
return
r
;
}
public
static
Result
<
Object
>
ok
(
Object
data
)
{
Result
<
Object
>
r
=
new
Result
<>();
r
.
setSuccess
(
true
);
r
.
setCode
(
CommonConstant
.
SC_OK_200
);
r
.
setResult
(
data
);
return
r
;
}
public
static
Result
<
Object
>
error
(
String
msg
)
{
return
error
(
CommonConstant
.
SC_INTERNAL_SERVER_ERROR_500
,
msg
);
}
public
static
Result
<
Object
>
error
(
int
code
,
String
msg
)
{
Result
<
Object
>
r
=
new
Result
<
Object
>();
r
.
setCode
(
code
);
r
.
setMessage
(
msg
);
r
.
setSuccess
(
false
);
return
r
;
}
public
Result
<
T
>
error500
(
String
message
)
{
this
.
message
=
message
;
this
.
code
=
CommonConstant
.
SC_INTERNAL_SERVER_ERROR_500
;
this
.
success
=
false
;
return
this
;
}
/**
* 无权限访问返回结果
*/
public
static
Result
<
Object
>
noauth
(
String
msg
)
{
return
error
(
CommonConstant
.
SC_JEECG_NO_AUTHZ
,
msg
);
}
}
\ No newline at end of file
src/main/resources/application.yaml
浏览文件 @
779aadfa
server
:
port
:
8
761
port
:
8
888
servlet
:
encoding
:
force
:
true
...
...
@@ -38,7 +38,7 @@ spring:
database
:
0
# Redis数据库索引(默认为0)
host
:
120.79.36.53
#Redis服务器地址
port
:
6379
# Redis服务器连接端口
password
:
# Redis服务器连接密码(默认为空)
password
:
123456
# Redis服务器连接密码(默认为空)
jedis
:
pool
:
max-active
:
200
# 连接池最大连接数(使用负值表示没有限制)
...
...
@@ -66,15 +66,15 @@ spring:
password
:
15671628341Qwe.
seata
:
application-id
:
spring-boot-name
tx-service-group
:
my-tx-group
service
:
vgroup-mapping
:
my-tx-group
:
seata-server
grouplist
:
seata-server
:
127.0.0.1:8091
enabled
:
true
#
seata:
#
application-id: spring-boot-name
#
tx-service-group: my-tx-group
#
service:
#
vgroup-mapping:
#
my-tx-group: seata-server
#
grouplist:
#
seata-server: 127.0.0.1:8091
#
enabled: true
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录