我想做一个简单的注册页面,插入的内容有问题。
我尝试调试,问题出在哪里,但我没有找到(我看到executeAndReturnKey出了点问题,但我不明白为什么):/
UserJdbcDao:
public User insert(User u) {
Map<String, Object> parameters = new HashMap();
parameters.put("name", u.getName());
parameters.put("nick_name", u.getNickName());
parameters.put("birth_date", u.getBirthDate());
parameters.put("password", u.getPassword());
parameters.put("email", u.getEmail());
parameters.put("created_date", u.getCreatedDate());
parameters.put("last_logged_in", u.getLastLoggedIn());
parameters.put("active", u.getActive());
SqlParameterSource parameterSource = new MapSqlParameterSource(parameters);
Long result = (long)simpleJdbcInsert.executeAndReturnKey(parameterSource);
u.setId(result.intValue());
return u;
}
UserService:
public User createNew(RegistrationDto registrationDto) {
User user = new User();
ModelMapper modelMapper = new ModelMapper();
modelMapper.map(registrationDto, user);
user.setName(registrationDto.getName());
user.setNickName(registrationDto.getNickName());
user.setEmail(registrationDto.getEmail());
user.setPassword(registrationDto.getPassword());
user.setActive(false);
user.setCreatedDate(new Date());
user.setBirthDate(null);
user.setLastLoggedIn(null);
user = save(user);
return user;
}
public User save(User user) {
if (user.getId() == null) {
user = userJdbcDao.insert(user);
} else {
user = userJdbcDao.update(user);
}
return user;
}
RegistrationController:
@RequestMapping(value = "/registration",method = RequestMethod.POST)
public String registration( RegistrationDto registrationDto) {
userService.createNew(registrationDto);
return "reg";
}
}
java.lang.NullPointerException:空 在hu.wilderness.homesystem.jdbc.dao.UserJdbcDao.insert(UserJdbcDao.java:39)〜[classes /:na] 在hu.wilderness.homesystem.service.UserService.save(UserService.java:39)〜[classes /:na] 在hu.wilderness.homesystem.service.UserService.createNew(UserService.java:32)〜[classes /:na] 在hu.wilderness.homesystem.controller.RegistrationController.registration(RegistrationController.java:27)〜[classes /:na]