File tree 7 files changed +117
-13
lines changed
java/com/springcloud/springbootjpadruid
7 files changed +117
-13
lines changed Original file line number Diff line number Diff line change 15
15
<description >spring-boot-jpa-druid</description >
16
16
17
17
<properties >
18
+ <druid .version>1.1.20</druid .version>
18
19
<java .version>1.8</java .version>
19
20
</properties >
20
21
34
35
<scope >runtime</scope >
35
36
</dependency >
36
37
37
- <!-- https://mvnrepository.com/artifact/com.alibaba/druid-spring-boot-starter -->
38
38
<dependency >
39
39
<groupId >com.alibaba</groupId >
40
40
<artifactId >druid-spring-boot-starter</artifactId >
41
- <version >1.1.20</version >
41
+ <version >${druid.version} </version >
42
+ </dependency >
43
+ <dependency >
44
+ <groupId >org.projectlombok</groupId >
45
+ <artifactId >lombok</artifactId >
46
+ <optional >true</optional >
42
47
</dependency >
43
-
44
48
<dependency >
45
49
<groupId >org.springframework.boot</groupId >
46
50
<artifactId >spring-boot-starter-test</artifactId >
Original file line number Diff line number Diff line change
1
+ package com .springcloud .springbootjpadruid .controller ;
2
+
3
+ import com .springcloud .springbootjpadruid .model .UserModel ;
4
+ import com .springcloud .springbootjpadruid .repository .UserRepository ;
5
+ import org .springframework .beans .factory .annotation .Autowired ;
6
+ import org .springframework .data .domain .Sort ;
7
+ import org .springframework .web .bind .annotation .*;
8
+
9
+ import java .util .List ;
10
+
11
+ @ RestController
12
+ public class UserController {
13
+
14
+ @ Autowired
15
+ UserRepository userRepository ;
16
+
17
+ /**
18
+ * 查询用户列表
19
+ * @return
20
+ */
21
+ @ GetMapping ("/user" )
22
+ public List <UserModel > user () {
23
+ return userRepository .findAll (Sort .by ("id" ).descending ());
24
+ }
25
+
26
+ /**
27
+ * 新增或更新用户信息
28
+ * @param user
29
+ * @return
30
+ */
31
+ @ PostMapping ("/user" )
32
+ public UserModel user (@ RequestBody UserModel user ) {
33
+ return userRepository .save (user );
34
+ }
35
+
36
+ /**
37
+ * 根据id删除用户
38
+ * @param id
39
+ * @return
40
+ */
41
+ @ DeleteMapping ("/user" )
42
+ public String deleteUserById (String id ) {
43
+ userRepository .deleteById (id );
44
+ return "success" ;
45
+ }
46
+ }
Original file line number Diff line number Diff line change
1
+ package com .springcloud .springbootjpadruid .model ;
2
+
3
+ import lombok .Data ;
4
+ import org .hibernate .annotations .GenericGenerator ;
5
+
6
+ import javax .persistence .*;
7
+
8
+ /**
9
+ * @Date: 2019/9/17 16:49
10
+ * @Version: 1.0
11
+ * @Desc:
12
+ */
13
+ @ Entity
14
+ @ Data
15
+ @ Table (name = "user" )
16
+ public class UserModel {
17
+ @ Id
18
+ @ GeneratedValue (generator = "paymentableGenerator" )
19
+ @ GenericGenerator (name = "paymentableGenerator" , strategy = "uuid" )
20
+ @ Column (name = "ID" , nullable =false , length =36 )
21
+ private String id ;
22
+ @ Column (name = "nick_name" )
23
+ private String nickName ;
24
+ @ Column (nullable = false )
25
+ private int age ;
26
+ }
Original file line number Diff line number Diff line change
1
+ package com .springcloud .springbootjpadruid .repository ;
2
+
3
+ import com .springcloud .springbootjpadruid .model .UserModel ;
4
+ import org .springframework .data .jpa .repository .JpaRepository ;
5
+
6
+ import java .util .List ;
7
+
8
+ /**
9
+ * @Date: 2019/9/17 16:51
10
+ * @Version: 1.0
11
+ * @Desc:
12
+ */
13
+ public interface UserRepository extends JpaRepository <UserModel , String > {
14
+ UserModel getByIdIs (String id );
15
+
16
+ UserModel findByNickName (String nickName );
17
+
18
+ int countByAge (int age );
19
+
20
+ List <UserModel > findByNickNameLike (String nickName );
21
+ }
Original file line number Diff line number Diff line change 1
1
spring :
2
2
datasource :
3
3
type : com.alibaba.druid.pool.DruidDataSource
4
- url : jdbc:mysql://172.16.96.112 :3306/test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false
4
+ url : jdbc:mysql://192.168.0.128 :3306/test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false
5
5
username : root
6
6
# 加密后密文,原密码为 123456
7
- password : pJRm0wPfnOkjULnm8tCx5JFQHGCtgSs2MNkwWziN7luLIU2mmc5V3x7nylJEYMSjpKNoawal8Pe7oty0dSKSkg ==
7
+ password : Y464AerH8tabxQg5DlkUej6gQ64KY73ahgiPyaB0vguLBLjUEEkVu6VBueiXxcnMfVjh1Nbd+lJNUTnS1a3/xg ==
8
8
driverClassName : com.mysql.cj.jdbc.Driver
9
9
druid :
10
10
filter :
11
11
config :
12
12
enabled : true
13
- connection-properties : config.decrypt=true;config.decrypt.key=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKo5mHbMnE3/7DHKulE4lEQ/eq1vaWoO75WsydEENVaQwHLBpKO9VcE2aCxLhjkmcuHDwqBaQjMRAYctwmgGyaUCAwEAAQ ==
13
+ connection-properties : config.decrypt=true;config.decrypt.key=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAIddoZ2mbjHu+mG+KYu6IEgBDDnGr5s+wZaPA2MXoqcXmUIZ6154MXNIAEOjkZaHy1rQ5uku2yO8Hw09hBcv9g8CAwEAAQ ==
14
14
# 连接池的配置信息
15
15
# 初始化时建立物理连接的个数
16
16
initial-size : 3
@@ -39,11 +39,13 @@ spring:
39
39
# 当值大于0时poolPreparedStatements会自动修改为true
40
40
max-pool-prepared-statement-per-connection-size : 20
41
41
# 合并多个DruidDataSource的监控数据
42
- use-global-data-source-stat : true
42
+ use-global-data-source-stat : false
43
43
# 配置扩展插件
44
44
filters : stat,wall,slf4j
45
45
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
46
46
connect-properties : druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
47
+ # 定时输出统计信息到日志中,并每次输出日志会导致清零(reset)连接池相关的计数器。
48
+ time-between-log-stats-millis : 300000
47
49
# 配置DruidStatFilter
48
50
web-stat-filter :
49
51
enabled : true
@@ -63,4 +65,4 @@ spring:
63
65
# 登录名
64
66
login-username : admin
65
67
# 登录密码
66
- login-password : admin
68
+ login-password : admin
Original file line number Diff line number Diff line change 1
1
spring :
2
2
datasource :
3
3
type : com.alibaba.druid.pool.DruidDataSource
4
- url : jdbc:mysql://172.16.96.112 :3306/test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false
4
+ url : jdbc:mysql://192.168.0.128 :3306/test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false
5
5
username : root
6
6
password : 123456
7
7
driverClassName : com.mysql.cj.jdbc.Driver
@@ -34,11 +34,13 @@ spring:
34
34
# 当值大于0时poolPreparedStatements会自动修改为true
35
35
max-pool-prepared-statement-per-connection-size : 20
36
36
# 合并多个DruidDataSource的监控数据
37
- use-global-data-source-stat : true
37
+ use-global-data-source-stat : false
38
38
# 配置扩展插件
39
39
filters : stat,wall,slf4j
40
40
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
41
- connect-properties : druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
41
+ connect-properties : druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
42
+ # 定时输出统计信息到日志中,并每次输出日志会导致清零(reset)连接池相关的计数器。
43
+ time-between-log-stats-millis : 300000
42
44
# 配置DruidStatFilter
43
45
web-stat-filter :
44
46
enabled : true
Original file line number Diff line number Diff line change 9
9
database : mysql
10
10
show-sql : true
11
11
generate-ddl : true
12
- database-platform : org.hibernate.dialect.MySQL5Dialect
12
+ database-platform : org.hibernate.dialect.MySQL5InnoDBDialect
13
13
hibernate :
14
- ddl-auto : update
14
+ ddl-auto : update
15
+ properties :
16
+ hibernate :
17
+ format_sql : true
You can’t perform that action at this time.
0 commit comments