我尝试使用下一个代码将我的用户保存到MySQL数据库中:
queueTstST :: Int -> State (S.Seq Int) (Maybe Int)
queueTstST n = go n Nothing
where
go :: Int -> Maybe Int -> State (S.Seq Int) (Maybe Int)
go n v =
if (n > 1)
then if even n
then pushS' (100 + n) >> go (n - 1) Nothing
else popS' >>= go (n - 1)
else return v
这是我对UserService的实现:
@RequestMapping(value = "/registration", method = RequestMethod.POST)
public String registration(@ModelAttribute("userForm") User userForm, BindingResult bindingResult, Model model) {
userValidator.validate(userForm, bindingResult);
if (bindingResult.hasErrors()) {
return "registration";
}
userService.save(userForm);
securityService.autoLogin(userForm.getUsername(), userForm.getConfirmPassword());
return "redirect:/welcome";
}
这是用户实体
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserRepository userRepository;
@Autowired
private RoleRepository roleRepository;
@Autowired
private BCryptPasswordEncoder bCryptPasswordEncoder;
@Override
public void save(User user) {
user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
Set<Role> roles = new HashSet<>();
roles.add(roleRepository.getOne(1L));
user.setRoles(roles);
userRepository.save(user);
}
@Override
public User findByUsername(String username) {
return userRepository.findByUsername(username);
}
}
使用相应的getter和setter代替......
这是堆栈跟踪,出现在执行时。
@Entity
@Table(name = "users")
public class User {
@Id
@Column(name = "user_id")
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "username")
private String username;
@Column(name = "password")
private String password;
@Column(name = "email")
private String email;
@Transient
private String confirmPassword;
@ManyToMany
@JoinTable(name = "user_roles", joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "role_id"))
private Set<Role> roles;
...
...
}