File tree 2 files changed +43
-12
lines changed
spring-boot-jpa-hikari/src/main/java/com/springboot/springbootjpahikari
2 files changed +43
-12
lines changed Original file line number Diff line number Diff line change 1
1
package com .springboot .springbootjpahikari .controller ;
2
2
3
+ import com .springboot .springbootjpahikari .model .UserModel ;
4
+ import com .springboot .springbootjpahikari .repository .UserRepository ;
5
+ import org .springframework .beans .factory .annotation .Autowired ;
6
+ import org .springframework .data .domain .Sort ;
7
+ import org .springframework .web .bind .annotation .DeleteMapping ;
8
+ import org .springframework .web .bind .annotation .GetMapping ;
9
+ import org .springframework .web .bind .annotation .PostMapping ;
3
10
import org .springframework .web .bind .annotation .RestController ;
4
11
5
- /**
6
- * @Date: 2019/9/17 16:52
7
- * @Version: 1.0
8
- * @Desc:
9
- */
12
+ import java .util .List ;
13
+
10
14
@ RestController
11
15
public class UserController {
16
+
17
+ @ Autowired
18
+ UserRepository userRepository ;
19
+
20
+ /**
21
+ * 查询用户列表
22
+ * @return
23
+ */
24
+ @ GetMapping ("/user" )
25
+ public List <UserModel > user () {
26
+ return userRepository .findAll (Sort .by ("id" ).descending ());
27
+ }
28
+
29
+ /**
30
+ * 新增或更新用户信息
31
+ * @param user
32
+ * @return
33
+ */
34
+ @ PostMapping ("/user" )
35
+ public UserModel user (UserModel user ) {
36
+ return userRepository .save (user );
37
+ }
38
+
39
+ /**
40
+ * 根据id删除用户
41
+ * @param id
42
+ * @return
43
+ */
44
+ @ DeleteMapping ("/user" )
45
+ public String deleteUserById (Long id ) {
46
+ userRepository .deleteById (id );
47
+ return "success" ;
48
+ }
12
49
}
Original file line number Diff line number Diff line change @@ -16,14 +16,8 @@ public class UserModel {
16
16
@ Id
17
17
@ GeneratedValue
18
18
private Long id ;
19
- @ Column (nullable = false , unique = true )
20
- private String userName ;
21
- @ Column (nullable = false )
22
- private String passWord ;
23
- @ Column (nullable = false , unique = true )
24
- private String email ;
25
19
@ Column (nullable = true , unique = true )
26
20
private String nickName ;
27
21
@ Column (nullable = false )
28
- private String regTime ;
22
+ private int age ;
29
23
}
You can’t perform that action at this time.
0 commit comments