由于某种原因,我的新用户的ID未生成。
userRepository.save(user); //id = null and i can't create user
控制器:
@GetMapping("/createuser")
public String creatingForm(Model model) {
model.addAttribute("user", new User());
return "createuser";
}
@PostMapping("/createuser")
public String creatingSubmit(@ModelAttribute("user") User user) {
userRepository.save(user);
return "login";
}
型号:
@Entity
@Table(name = "user")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(nullable = false, unique = true)
private Integer id;
从控制台登录:
User{id=null, email='example data', password='example data', name='example data', surname='example data', country='example data'}