Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
springboot-study
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
周田
springboot-study
Commits
fcc292ab
Commit
fcc292ab
authored
May 16, 2024
by
周田
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(core): mybatis-plus 接入
parent
f3d00d84
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
153 additions
and
6 deletions
+153
-6
pom.xml
pom.xml
+19
-0
SpringbootApplication.java
...ain/java/org/linker/springboot/SpringbootApplication.java
+2
-0
SpringMVCConfiguration.java
.../org/linker/springboot/config/SpringMVCConfiguration.java
+6
-6
UserController.java
...java/org/linker/springboot/controller/UserController.java
+11
-0
UserMapper.java
src/main/java/org/linker/springboot/mapper/UserMapper.java
+7
-0
User.java
src/main/java/org/linker/springboot/pojo/User.java
+61
-0
UserService.java
src/main/java/org/linker/springboot/service/UserService.java
+15
-0
application.yml
src/main/resources/application.yml
+32
-0
No files found.
pom.xml
View file @
fcc292ab
...
...
@@ -26,12 +26,31 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<!--数据校验-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-validation
</artifactId>
</dependency>
<!--db-->
<dependency>
<groupId>
com.baomidou
</groupId>
<artifactId>
mybatis-plus-spring-boot3-starter
</artifactId>
<version>
3.5.6
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid-spring-boot-3-starter
</artifactId>
<version>
1.2.21
</version>
</dependency>
<dependency>
<groupId>
com.mysql
</groupId>
<artifactId>
mysql-connector-j
</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
...
...
src/main/java/org/linker/springboot/SpringbootApplication.java
View file @
fcc292ab
package
org
.
linker
.
springboot
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.annotation.EnableAspectJAutoProxy
;
@SpringBootApplication
@MapperScan
(
"org.linker.springboot.mapper"
)
public
class
SpringbootApplication
{
public
static
void
main
(
String
[]
args
)
{
...
...
src/main/java/org/linker/springboot/config/SpringMVCConfiguration.java
View file @
fcc292ab
...
...
@@ -32,11 +32,11 @@ public class SpringMVCConfiguration implements WebMvcConfigurer {
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
// 拦截器一
registry
.
addInterceptor
(
this
.
firstInterceptor
()).
addPathPatterns
(
"/**"
);
// 拦截器二
registry
.
addInterceptor
(
this
.
secondInterceptor
()).
addPathPatterns
(
"/users/current_user"
);
// 拦截器三
registry
.
addInterceptor
(
this
.
thirdInterceptor
()).
addPathPatterns
(
"/**"
);
//
// 拦截器一
//
registry.addInterceptor(this.firstInterceptor()).addPathPatterns("/**");
//
// 拦截器二
//
registry.addInterceptor(this.secondInterceptor()).addPathPatterns("/users/current_user");
//
// 拦截器三
//
registry.addInterceptor(this.thirdInterceptor()).addPathPatterns("/**");
}
}
src/main/java/org/linker/springboot/controller/UserController.java
View file @
fcc292ab
...
...
@@ -8,6 +8,7 @@ import org.linker.springboot.core.exception.ServiceException;
import
org.linker.springboot.core.vo.CommonResult
;
import
org.linker.springboot.dto.UserAddDTO
;
import
org.linker.springboot.dto.UserUpdateDTO
;
import
org.linker.springboot.pojo.User
;
import
org.linker.springboot.service.UserService
;
import
org.linker.springboot.vo.UserVO
;
import
org.slf4j.Logger
;
...
...
@@ -177,4 +178,14 @@ public class UserController {
logger
.
info
(
"[validate] userVO: {}"
,
userVO
.
toString
());
return
CommonResult
.
success
(
userVO
);
}
@GetMapping
(
"/get_all_users"
)
public
CommonResult
<
List
<
User
>>
getAllUsersFromDB
()
{
return
CommonResult
.
success
(
userService
.
getAllUserFromDB
());
}
@GetMapping
(
"/get_user_by_id"
)
public
CommonResult
<
User
>
getUserById
(
@Min
(
value
=
1
,
message
=
"用户编号必须大于 0"
)
Integer
id
)
{
return
CommonResult
.
success
(
userService
.
getUserById
(
id
));
}
}
src/main/java/org/linker/springboot/mapper/UserMapper.java
0 → 100644
View file @
fcc292ab
package
org
.
linker
.
springboot
.
mapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
org.linker.springboot.pojo.User
;
public
interface
UserMapper
extends
BaseMapper
<
User
>
{
}
src/main/java/org/linker/springboot/pojo/User.java
0 → 100644
View file @
fcc292ab
package
org
.
linker
.
springboot
.
pojo
;
public
class
User
{
private
Long
id
;
private
String
username
;
private
Integer
age
;
private
String
email
;
public
User
()
{
}
public
User
(
long
id
,
String
username
,
int
age
,
String
email
)
{
this
.
id
=
id
;
this
.
username
=
username
;
this
.
age
=
age
;
this
.
email
=
email
;
}
public
Long
getId
()
{
return
id
;
}
public
void
setId
(
Long
id
)
{
this
.
id
=
id
;
}
public
String
getusername
()
{
return
username
;
}
public
void
setusername
(
String
username
)
{
this
.
username
=
username
;
}
public
Integer
getAge
()
{
return
age
;
}
public
void
setAge
(
Integer
age
)
{
this
.
age
=
age
;
}
public
String
getEmail
()
{
return
email
;
}
public
void
setEmail
(
String
email
)
{
this
.
email
=
email
;
}
@Override
public
String
toString
()
{
return
"User{"
+
"id="
+
id
+
", username='"
+
username
+
'\''
+
", age="
+
age
+
", email='"
+
email
+
'\''
+
'}'
;
}
}
\ No newline at end of file
src/main/java/org/linker/springboot/service/UserService.java
View file @
fcc292ab
package
org
.
linker
.
springboot
.
service
;
import
org.linker.springboot.mapper.UserMapper
;
import
org.linker.springboot.pojo.User
;
import
org.linker.springboot.vo.UserVO
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
@Service
public
class
UserService
{
@Autowired
private
UserMapper
userMapper
;
public
UserVO
get
(
Integer
id
)
{
return
new
UserVO
().
setId
(
id
).
setUsername
(
"test"
);
}
public
List
<
User
>
getAllUserFromDB
()
{
return
userMapper
.
selectList
(
null
);
}
public
User
getUserById
(
Integer
id
)
{
return
userMapper
.
selectById
(
id
);
}
}
src/main/resources/application.yml
View file @
fcc292ab
spring
:
application
:
name
:
springboot
# DataSource Config
datasource
:
druid
:
driver-class-name
:
com.mysql.cj.jdbc.Driver
url
:
jdbc:mysql://192.168.0.210:3306/springboot_study?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
username
:
root
password
:
lhr
initial-size
:
1
# ?????
min-idle
:
1
# ???????
max-active
:
20
# ???????
max-wait
:
600000
# ???????????????????
time-between-eviction-runs-millis
:
60000
# ???????????????????????????????
min-evictable-idle-time-millis
:
300000
# ??????????????????????
max-evictable-idle-time-millis
:
900000
# ??????????????????????
validation-query
:
SELECT 1 FROM DUAL
# ??????????
test-while-idle
:
true
test-on-borrow
:
false
test-on-return
:
false
mybatis-plus
:
configuration
:
# MyBatis ??
map-underscore-to-camel-case
:
true
global-config
:
# ????
db-config
:
# ?????
id-type
:
auto
logging
:
level
:
org.linker.springboot.mapper
:
debug
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment