Skip to content

Commit 92478f2

Browse files
committed
更新代码
1 parent e1d0855 commit 92478f2

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,49 @@
11
package com.springboot.springbootjpahikari.controller;
22

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;
310
import org.springframework.web.bind.annotation.RestController;
411

5-
/**
6-
* @Date: 2019/9/17 16:52
7-
* @Version: 1.0
8-
* @Desc:
9-
*/
12+
import java.util.List;
13+
1014
@RestController
1115
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+
}
1249
}

spring-boot-jpa-hikari/src/main/java/com/springboot/springbootjpahikari/model/UserModel.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,8 @@ public class UserModel {
1616
@Id
1717
@GeneratedValue
1818
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;
2519
@Column(nullable = true, unique = true)
2620
private String nickName;
2721
@Column(nullable = false)
28-
private String regTime;
22+
private int age;
2923
}

0 commit comments

Comments
 (0)