Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
SpringBoot-kwan
提交
3d06f36f
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看板
提交
3d06f36f
编写于
12月 19, 2022
作者:
Q
qinyingjie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:添加springboot功能
上级
d0df4171
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
235 addition
and
5 deletion
+235
-5
pom.xml
pom.xml
+6
-0
src/main/java/com/kwan/springbootkwan/config/MyBatisPlusConfig.java
...ava/com/kwan/springbootkwan/config/MyBatisPlusConfig.java
+8
-1
src/main/java/com/kwan/springbootkwan/config/MyWebMvcConfig.java
...n/java/com/kwan/springbootkwan/config/MyWebMvcConfig.java
+31
-0
src/main/java/com/kwan/springbootkwan/controller/BookController.java
...va/com/kwan/springbootkwan/controller/BookController.java
+27
-0
src/main/java/com/kwan/springbootkwan/controller/FileUploadController.java
.../kwan/springbootkwan/controller/FileUploadController.java
+71
-0
src/main/java/com/kwan/springbootkwan/controller/PersonController.java
.../com/kwan/springbootkwan/controller/PersonController.java
+37
-0
src/main/java/com/kwan/springbootkwan/controller/UserController.java
...va/com/kwan/springbootkwan/controller/UserController.java
+9
-1
src/main/java/com/kwan/springbootkwan/entity/Person.java
src/main/java/com/kwan/springbootkwan/entity/Person.java
+37
-0
src/main/java/com/kwan/springbootkwan/mapper/UserMapper.java
src/main/java/com/kwan/springbootkwan/mapper/UserMapper.java
+9
-3
未找到文件。
pom.xml
浏览文件 @
3d06f36f
...
@@ -69,6 +69,12 @@
...
@@ -69,6 +69,12 @@
<version>
1.3.0.Final
</version>
<version>
1.3.0.Final
</version>
<scope>
compile
</scope>
<scope>
compile
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-devtools
</artifactId>
<optional>
true
</optional>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
src/main/java/com/kwan/springbootkwan/config/MyBatisPlusConfig.java
浏览文件 @
3d06f36f
...
@@ -9,13 +9,20 @@ import org.springframework.context.annotation.Bean;
...
@@ -9,13 +9,20 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
/**
* mybatisplus配置
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2022/12/19 16:11
*/
@MapperScan
(
"com.kwan.springbootkwan.mapper"
)
//扫描我们的mapper文件夹 这里添加了@MapperScan注解就不需要Springboot启动类上加入@MapperScan注解了
@MapperScan
(
"com.kwan.springbootkwan.mapper"
)
//扫描我们的mapper文件夹 这里添加了@MapperScan注解就不需要Springboot启动类上加入@MapperScan注解了
@EnableTransactionManagement
//事务控制
@EnableTransactionManagement
//事务控制
@Configuration
//配置类
@Configuration
//配置类
public
class
MyBatisPlusConfig
{
public
class
MyBatisPlusConfig
{
@Bean
@Bean
public
MybatisPlusInterceptor
mybatisPlusInterceptor
(){
public
MybatisPlusInterceptor
mybatisPlusInterceptor
()
{
MybatisPlusInterceptor
interceptor
=
new
MybatisPlusInterceptor
();
MybatisPlusInterceptor
interceptor
=
new
MybatisPlusInterceptor
();
//注册乐观锁插件
//注册乐观锁插件
interceptor
.
addInnerInterceptor
(
new
OptimisticLockerInnerInterceptor
());
interceptor
.
addInnerInterceptor
(
new
OptimisticLockerInnerInterceptor
());
...
...
src/main/java/com/kwan/springbootkwan/config/MyWebMvcConfig.java
0 → 100644
浏览文件 @
3d06f36f
package
com.kwan.springbootkwan.config
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.CorsRegistry
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
/**
* 全局拦截器-跨域配置
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2022/12/19 16:11
*/
@Configuration
public
class
MyWebMvcConfig
implements
WebMvcConfigurer
{
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
registry
.
addResourceHandler
(
"/static/**"
)
.
addResourceLocations
(
"classpath:/static/"
);
}
@Override
public
void
addCorsMappings
(
CorsRegistry
registry
)
{
registry
.
addMapping
(
"/book/**"
)
.
allowedHeaders
(
"*"
)
.
allowedMethods
(
"*"
)
.
maxAge
(
1800
)
.
allowedOrigins
(
"http://localhost:8081"
);
}
}
src/main/java/com/kwan/springbootkwan/controller/BookController.java
0 → 100644
浏览文件 @
3d06f36f
package
com.kwan.springbootkwan.controller
;
import
org.springframework.web.bind.annotation.*
;
/**
* 方法上跨域配置
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2022/12/19 16:10
*/
@RestController
public
class
BookController
{
@CrossOrigin
(
value
=
"http://localhost:8081"
,
maxAge
=
1800
,
allowedHeaders
=
"*"
)
@PostMapping
(
"addBook"
)
public
String
addBook
(
String
name
)
{
return
"receive:"
+
name
;
}
@CrossOrigin
(
value
=
"http://localhost:8081"
,
maxAge
=
1800
,
allowedHeaders
=
"*"
)
@DeleteMapping
(
"deleteBook/{id}"
)
public
String
deleteBook
(
@PathVariable
(
value
=
"id"
)
String
id
)
{
return
"receive:"
+
id
;
}
}
src/main/java/com/kwan/springbootkwan/controller/FileUploadController.java
0 → 100644
浏览文件 @
3d06f36f
package
com.kwan.springbootkwan.controller
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestPart
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.File
;
import
java.io.IOException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.UUID
;
/**
* 文件上传
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2022/12/19 16:07
*/
@RestController
public
class
FileUploadController
{
/**
* 单文件上传
*
* @param uploadFile
* @param req
* @return
*/
@PostMapping
(
"/upload"
)
public
String
upload
(
MultipartFile
uploadFile
,
HttpServletRequest
req
)
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
String
realPath
=
req
.
getSession
().
getServletContext
().
getRealPath
(
"/uploadFile/"
);
String
format
=
sdf
.
format
(
new
Date
());
File
folder
=
new
File
(
realPath
+
format
);
if
(!
folder
.
isDirectory
())
{
folder
.
mkdirs
();
}
String
oldName
=
uploadFile
.
getOriginalFilename
();
String
newName
=
UUID
.
randomUUID
().
toString
()
+
oldName
.
substring
(
oldName
.
lastIndexOf
(
"."
),
oldName
.
length
());
try
{
//文件保存操作
uploadFile
.
transferTo
(
new
File
(
folder
,
newName
));
//生成上传文件的访问路径, 并将访问路径返回
String
filePath
=
req
.
getScheme
()
+
"://"
+
req
.
getServerName
()
+
":"
+
req
.
getServerPort
()
+
"/uploadFile/"
+
format
+
newName
;
return
filePath
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
"文件上传失败"
;
}
/**
* 多文件上传
*
* @param uploadFiles
* @param req
* @return
*/
@PostMapping
(
"/uploadBatch"
)
public
String
uploadBatch
(
@RequestPart
(
"uploadFile"
)
MultipartFile
[]
uploadFiles
,
HttpServletRequest
req
)
{
//遍历 uploadFiles 数组分别存储
return
"success"
;
}
}
src/main/java/com/kwan/springbootkwan/controller/PersonController.java
0 → 100644
浏览文件 @
3d06f36f
package
com.kwan.springbootkwan.controller
;
import
com.kwan.springbootkwan.entity.Person
;
import
com.kwan.springbootkwan.entity.User
;
import
com.kwan.springbootkwan.service.IUserService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.Date
;
import
java.util.List
;
/**
* Person相关
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2022/12/19 16:08
*/
@RestController
@RequestMapping
(
"/person"
)
public
class
PersonController
{
/**
* {
* "name": "zhang san",
* "age": 24,
* "birthday": "2022-12-19"
* }
*/
@GetMapping
(
"/person"
)
public
Person
person
()
{
Person
person
=
new
Person
();
person
.
setName
(
"zhang san"
);
person
.
setAge
(
24
);
person
.
setBirthday
(
new
Date
());
return
person
;
}
}
\ No newline at end of file
src/main/java/com/kwan/springbootkwan/controller/UserController.java
浏览文件 @
3d06f36f
package
com.kwan.springbootkwan.controller
;
package
com.kwan.springbootkwan.controller
;
import
com.kwan.springbootkwan.entity.Person
;
import
com.kwan.springbootkwan.entity.User
;
import
com.kwan.springbootkwan.entity.User
;
import
com.kwan.springbootkwan.service.IUserService
;
import
com.kwan.springbootkwan.service.IUserService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
/**
* 用户相关
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2022/12/19 16:08
*/
@RestController
@RestController
@RequestMapping
(
"/user"
)
@RequestMapping
(
"/user"
)
public
class
UserController
{
public
class
UserController
{
...
...
src/main/java/com/kwan/springbootkwan/entity/Person.java
0 → 100644
浏览文件 @
3d06f36f
package
com.kwan.springbootkwan.entity
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
java.util.Date
;
public
class
Person
{
private
String
name
;
private
Integer
age
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd"
)
private
Date
birthday
;
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
Integer
getAge
()
{
return
age
;
}
public
void
setAge
(
Integer
age
)
{
this
.
age
=
age
;
}
public
Date
getBirthday
()
{
return
birthday
;
}
public
void
setBirthday
(
Date
birthday
)
{
this
.
birthday
=
birthday
;
}
}
src/main/java/com/kwan/springbootkwan/mapper/UserMapper.java
浏览文件 @
3d06f36f
...
@@ -2,10 +2,16 @@ package com.kwan.springbootkwan.mapper;
...
@@ -2,10 +2,16 @@ package com.kwan.springbootkwan.mapper;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.kwan.springbootkwan.entity.User
;
import
com.kwan.springbootkwan.entity.User
;
import
org.
springframework.stereotype.Repository
;
import
org.
apache.ibatis.annotations.Mapper
;
//@Mapper
/**
@Repository
// 代表持久层
* mapper文件
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2022/12/19 16:12
*/
@Mapper
public
interface
UserMapper
extends
BaseMapper
<
User
>
{
public
interface
UserMapper
extends
BaseMapper
<
User
>
{
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录