Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
SpringBoot-kwan
提交
e78d61a0
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看板
提交
e78d61a0
编写于
12月 19, 2022
作者:
Q
qinyingjie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:添加swagger
上级
1f307777
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
203 addition
and
29 deletion
+203
-29
pom.xml
pom.xml
+26
-0
src/main/java/com/kwan/springbootkwan/config/DataSourceConfig.java
...java/com/kwan/springbootkwan/config/DataSourceConfig.java
+0
-24
src/main/java/com/kwan/springbootkwan/config/RedisConfig.java
...main/java/com/kwan/springbootkwan/config/RedisConfig.java
+40
-0
src/main/java/com/kwan/springbootkwan/config/Swagger2Config.java
...n/java/com/kwan/springbootkwan/config/Swagger2Config.java
+46
-0
src/main/java/com/kwan/springbootkwan/controller/BookController.java
...va/com/kwan/springbootkwan/controller/BookController.java
+5
-1
src/main/java/com/kwan/springbootkwan/controller/FileUploadController.java
.../kwan/springbootkwan/controller/FileUploadController.java
+5
-0
src/main/java/com/kwan/springbootkwan/controller/PersonController.java
.../com/kwan/springbootkwan/controller/PersonController.java
+4
-0
src/main/java/com/kwan/springbootkwan/controller/RedisController.java
...a/com/kwan/springbootkwan/controller/RedisController.java
+44
-0
src/main/java/com/kwan/springbootkwan/controller/UserController.java
...va/com/kwan/springbootkwan/controller/UserController.java
+5
-2
src/main/java/com/kwan/springbootkwan/entity/Person.java
src/main/java/com/kwan/springbootkwan/entity/Person.java
+6
-1
src/main/java/com/kwan/springbootkwan/entity/User.java
src/main/java/com/kwan/springbootkwan/entity/User.java
+10
-1
src/main/java/com/kwan/springbootkwan/mapper/UserMapper.java
src/main/java/com/kwan/springbootkwan/mapper/UserMapper.java
+1
-0
src/main/resources/application.yaml
src/main/resources/application.yaml
+11
-0
未找到文件。
pom.xml
浏览文件 @
e78d61a0
...
...
@@ -83,6 +83,32 @@
<artifactId>
druid-spring-boot-starter
</artifactId>
<version>
1.1.10
</version>
</dependency>
<!--集成redis-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
<exclusions>
<exclusion>
<groupId>
io.lettuce
</groupId>
<artifactId>
lettuce-core
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
redis.clients
</groupId>
<artifactId>
jedis
</artifactId>
</dependency>
<!--集成swagger-->
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
<version>
2.6.1
</version>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger-ui
</artifactId>
<version>
2.6.1
</version>
</dependency>
</dependencies>
<build>
<plugins>
...
...
src/main/java/com/kwan/springbootkwan/config/DataSourceConfig.java
已删除
100644 → 0
浏览文件 @
1f307777
package
com.kwan.springbootkwan.config
;
import
com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
javax.sql.DataSource
;
@Configuration
public
class
DataSourceConfig
{
@Bean
@ConfigurationProperties
(
"spring.datasource.one"
)
DataSource
dataSourceOne
()
{
return
DruidDataSourceBuilder
.
create
().
build
();
}
@Bean
@ConfigurationProperties
(
"spring.datasource.two"
)
DataSource
dataSourceTwo
()
{
return
DruidDataSourceBuilder
.
create
().
build
();
}
}
src/main/java/com/kwan/springbootkwan/config/RedisConfig.java
0 → 100644
浏览文件 @
e78d61a0
package
com.kwan.springbootkwan.config
;
import
com.fasterxml.jackson.annotation.JsonAutoDetect
;
import
com.fasterxml.jackson.annotation.PropertyAccessor
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
@Configuration
public
class
RedisConfig
{
@Bean
@SuppressWarnings
(
"all"
)
public
RedisTemplate
<
String
,
Object
>
redisTemplate
(
RedisConnectionFactory
factory
)
{
System
.
out
.
println
(
"==================自定义的redisTemplate实例化了==================="
);
RedisTemplate
<
String
,
Object
>
template
=
new
RedisTemplate
<
String
,
Object
>();
template
.
setConnectionFactory
(
factory
);
Jackson2JsonRedisSerializer
jackson2JsonRedisSerializer
=
new
Jackson2JsonRedisSerializer
(
Object
.
class
);
ObjectMapper
om
=
new
ObjectMapper
();
om
.
setVisibility
(
PropertyAccessor
.
ALL
,
JsonAutoDetect
.
Visibility
.
ANY
);
om
.
enableDefaultTyping
(
ObjectMapper
.
DefaultTyping
.
NON_FINAL
);
jackson2JsonRedisSerializer
.
setObjectMapper
(
om
);
StringRedisSerializer
stringRedisSerializer
=
new
StringRedisSerializer
();
// key采用String的序列化方式
template
.
setKeySerializer
(
stringRedisSerializer
);
// hash的key也采用String的序列化方式
template
.
setHashKeySerializer
(
stringRedisSerializer
);
// value序列化方式采用jackson
template
.
setValueSerializer
(
jackson2JsonRedisSerializer
);
// hash的value序列化方式采用jackson
template
.
setHashValueSerializer
(
jackson2JsonRedisSerializer
);
template
.
afterPropertiesSet
();
return
template
;
}
}
src/main/java/com/kwan/springbootkwan/config/Swagger2Config.java
0 → 100644
浏览文件 @
e78d61a0
package
com.kwan.springbootkwan.config
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
springfox.documentation.builders.ApiInfoBuilder
;
import
springfox.documentation.builders.PathSelectors
;
import
springfox.documentation.builders.RequestHandlerSelectors
;
import
springfox.documentation.service.ApiInfo
;
import
springfox.documentation.service.Contact
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spring.web.plugins.Docket
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
/**
* 通过@Configuration注解,表明它是一个配置类 @EnableSwagger2开启swagger2。 apiINfo()配置一些基本的信息。apis()指定扫描的包会生成文档。
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2022/12/19 17:23
*/
@Configuration
@EnableSwagger2
public
class
Swagger2Config
{
@Bean
public
Docket
createRestApi
()
{
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
groupName
(
"SpringBoot学习"
)
.
apiInfo
(
apiInfo
())
.
select
()
.
apis
(
RequestHandlerSelectors
.
basePackage
(
"com.kwan.springbootkwan.controller"
))
//需要生成接口文档的包名
.
paths
(
PathSelectors
.
any
())
.
build
();
}
private
ApiInfo
apiInfo
()
{
return
new
ApiInfoBuilder
()
.
title
(
"SpringBoot学习"
)
.
description
(
"最怕一生碌碌无为,还安慰自己平凡可贵。"
)
.
termsOfServiceUrl
(
"http://qinyingjie.top/"
)
.
contact
(
new
Contact
(
"kwan"
,
"http://qinyingjie.top/"
,
"3327782001@qq.com"
))
.
version
(
"Apache 2.0"
)
.
build
();
}
}
\ No newline at end of file
src/main/java/com/kwan/springbootkwan/controller/BookController.java
浏览文件 @
e78d61a0
package
com.kwan.springbootkwan.controller
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.web.bind.annotation.*
;
/**
...
...
@@ -9,16 +11,18 @@ import org.springframework.web.bind.annotation.*;
* @version : 2.2.0
* @date : 2022/12/19 16:10
*/
@Api
(
description
=
"书籍信息"
,
tags
=
"BookController"
)
@RestController
public
class
BookController
{
@ApiOperation
(
value
=
"添加书籍"
,
notes
=
"添加书籍"
)
@CrossOrigin
(
value
=
"http://localhost:8081"
,
maxAge
=
1800
,
allowedHeaders
=
"*"
)
@PostMapping
(
"addBook"
)
public
String
addBook
(
String
name
)
{
return
"receive:"
+
name
;
}
@ApiOperation
(
value
=
"删除书籍"
,
notes
=
"删除书籍"
)
@CrossOrigin
(
value
=
"http://localhost:8081"
,
maxAge
=
1800
,
allowedHeaders
=
"*"
)
@DeleteMapping
(
"deleteBook/{id}"
)
public
String
deleteBook
(
@PathVariable
(
value
=
"id"
)
String
id
)
{
...
...
src/main/java/com/kwan/springbootkwan/controller/FileUploadController.java
浏览文件 @
e78d61a0
package
com.kwan.springbootkwan.controller
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestPart
;
import
org.springframework.web.bind.annotation.RestController
;
...
...
@@ -19,6 +21,7 @@ import java.util.UUID;
* @version : 2.2.0
* @date : 2022/12/19 16:07
*/
@Api
(
description
=
"文件上传信息"
,
tags
=
"FileUploadController"
)
@RestController
public
class
FileUploadController
{
...
...
@@ -29,6 +32,7 @@ public class FileUploadController {
* @param req
* @return
*/
@ApiOperation
(
value
=
"单个文件上传"
,
notes
=
"单个文件上传"
)
@PostMapping
(
"/upload"
)
public
String
upload
(
MultipartFile
uploadFile
,
HttpServletRequest
req
)
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
...
...
@@ -62,6 +66,7 @@ public class FileUploadController {
* @param req
* @return
*/
@ApiOperation
(
value
=
"批量上传"
,
notes
=
"批量上传"
)
@PostMapping
(
"/uploadBatch"
)
public
String
uploadBatch
(
@RequestPart
(
"uploadFile"
)
MultipartFile
[]
uploadFiles
,
HttpServletRequest
req
)
{
//遍历 uploadFiles 数组分别存储
...
...
src/main/java/com/kwan/springbootkwan/controller/PersonController.java
浏览文件 @
e78d61a0
...
...
@@ -3,6 +3,8 @@ package com.kwan.springbootkwan.controller;
import
com.kwan.springbootkwan.entity.Person
;
import
com.kwan.springbootkwan.entity.User
;
import
com.kwan.springbootkwan.service.IUserService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -16,6 +18,7 @@ import java.util.List;
* @version : 2.2.0
* @date : 2022/12/19 16:08
*/
@Api
(
description
=
"person用户信息"
,
tags
=
"PersonController"
)
@RestController
@RequestMapping
(
"/person"
)
public
class
PersonController
{
...
...
@@ -26,6 +29,7 @@ public class PersonController {
* "birthday": "2022-12-19"
* }
*/
@ApiOperation
(
value
=
"json返回"
,
notes
=
"json返回"
)
@GetMapping
(
"/person"
)
public
Person
person
()
{
Person
person
=
new
Person
();
...
...
src/main/java/com/kwan/springbootkwan/controller/RedisController.java
0 → 100644
浏览文件 @
e78d61a0
package
com.kwan.springbootkwan.controller
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
import
java.util.concurrent.TimeUnit
;
@Api
(
description
=
"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
);
//向对应的key值添加数据
redisTemplate
.
opsForValue
().
set
(
REDIS_KEY
,
"测试向redis中添加数据"
);
//设置过期时间
redisTemplate
.
expire
(
REDIS_KEY
,
2000000
,
TimeUnit
.
SECONDS
);
}
@ApiOperation
(
value
=
"redis获取数据"
,
notes
=
"redis获取数据"
)
@GetMapping
(
"/get"
)
public
void
get
()
{
//获取redis中的数据
String
str
=
(
String
)
redisTemplate
.
opsForValue
().
get
(
REDIS_KEY
);
System
.
out
.
println
(
"获取redis中的数据-->"
+
str
);
}
}
src/main/java/com/kwan/springbootkwan/controller/UserController.java
浏览文件 @
e78d61a0
package
com.kwan.springbootkwan.controller
;
import
com.kwan.springbootkwan.entity.Person
;
import
com.kwan.springbootkwan.entity.User
;
import
com.kwan.springbootkwan.service.IUserService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.Date
;
import
java.util.List
;
/**
...
...
@@ -16,6 +16,7 @@ import java.util.List;
* @version : 2.2.0
* @date : 2022/12/19 16:08
*/
@Api
(
description
=
"用户信息"
,
tags
=
"UserController"
)
@RestController
@RequestMapping
(
"/user"
)
public
class
UserController
{
...
...
@@ -23,11 +24,13 @@ public class UserController {
@Autowired
private
IUserService
userService
;
@ApiOperation
(
value
=
"获取所有用户"
,
notes
=
"获取所有用户"
)
@RequestMapping
(
value
=
"/all"
,
method
=
RequestMethod
.
GET
)
public
List
<
User
>
addAdvertise
()
{
return
userService
.
getUsers
();
}
@ApiOperation
(
value
=
"根据id获取用户信息"
,
notes
=
"根据id获取用户信息"
)
@RequestMapping
(
value
=
"/getUserById/{id}"
,
method
=
RequestMethod
.
GET
)
public
User
getUserById
(
@PathVariable
Integer
id
)
{
return
userService
.
getUserById
(
id
);
...
...
src/main/java/com/kwan/springbootkwan/entity/Person.java
浏览文件 @
e78d61a0
package
com.kwan.springbootkwan.entity
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
java.util.Date
;
@ApiModel
(
value
=
"用户基本信息"
)
public
class
Person
{
@ApiModelProperty
(
value
=
"姓名"
)
private
String
name
;
@ApiModelProperty
(
value
=
"年龄"
)
private
Integer
age
;
@ApiModelProperty
(
value
=
"生日"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd"
)
private
Date
birthday
;
...
...
src/main/java/com/kwan/springbootkwan/entity/User.java
浏览文件 @
e78d61a0
package
com.kwan.springbootkwan.entity
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Builder
;
import
lombok.Data
;
@Data
@Builder
@TableName
(
value
=
"user"
)
public
class
User
{
@ApiModel
(
value
=
"用户基本信息"
)
public
class
User
{
@ApiModelProperty
(
value
=
"主键id"
)
@TableId
(
value
=
"id"
,
type
=
IdType
.
AUTO
)
private
Integer
id
;
@ApiModelProperty
(
value
=
"姓名"
)
private
String
name
;
@ApiModelProperty
(
value
=
"性别"
)
private
String
sex
;
@ApiModelProperty
(
value
=
"密码"
)
private
String
pwd
;
@ApiModelProperty
(
value
=
"邮箱"
)
private
String
email
;
}
src/main/java/com/kwan/springbootkwan/mapper/UserMapper.java
浏览文件 @
e78d61a0
...
...
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import
com.kwan.springbootkwan.entity.User
;
import
org.apache.ibatis.annotations.Mapper
;
/**
* mapper文件
*
...
...
src/main/resources/application.yaml
浏览文件 @
e78d61a0
...
...
@@ -6,6 +6,17 @@ swagger:
#兼容swagger配置
spring
:
redis
:
database
:
0
# Redis数据库索引(默认为0)
host
:
120.79.36.53
#Redis服务器地址
port
:
6379
# Redis服务器连接端口
password
:
# Redis服务器连接密码(默认为空)
jedis
:
pool
:
max-active
:
200
# 连接池最大连接数(使用负值表示没有限制)
max-idle
:
10
# 连接池中的最大空闲连接
min-idle
:
0
# 连接池中的最小空闲连接
max-wait
:
-1
# 连接池最大阻塞等待时间(使用负值表示没有限制)
mvc
:
pathmatch
:
matching-strategy
:
ant_path_matcher
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录