Я сталкиваюсь с проблемой при использовании Spring / Mybatis для вставки данных через форму: путь ввода, я использую 2 class / table и хочу вставить данные в оба (User и DetailUserJapan). Это мой источник:
Класс пользователя:
public class User {
private Long user_id;
private DetailUserJapan detail_user_japan_id;
private String login_name;
private String password;
private String full_name;
private String full_name_kana;
private String email;
private String tel;
private Date birthday;
private boolean rule;
private String salt;
// getter and setter
}
Класс DetailUserJapan:
public class DetailUserJapan {
private Long detail_user_japan_id;
private Set<User> user_id = new HashSet<User>();
private Date start_date;
private Date end_date;
private int total;
// setter and getter
}
Класс контроллера:
@RequestMapping(value = "/showFormAddUser", method = RequestMethod.GET)
public ModelAndView showFormAddNewUser(HttpServletRequest request, HttpServletResponse response,
ModelMap model) throws ServletException, IOException {
ModelAndView mav = new ModelAndView("add_user");
User createUser = new User();
model.addAttribute("createUser", createUser);
return mav;
}
@RequestMapping(value = "/addUser", method = RequestMethod.POST)
public String submitAddNewUser(HttpServletRequest request, HttpServletResponse response,
@RequestParam("groupSelected") Integer groupSelected,
@RequestParam("japanMasterSelected") String japanMasterSelected,
@ModelAttribute("createUser") User createUser, BindingResult result, ModelMap model) throws SQLException, IOException {
if (result.hasErrors()) {
return "add_user";
}
GroupMaster myGroupMaster = userService.getGroupById(groupSelected);
JapanMaster myJapanMaster = userService.getJapanMasterById(japanMasterSelected);
createUser.setGroup_id(myGroupMaster);
createUser.setCode_level(myJapanMaster);
userService.insertUser(createUser);
return "redirect:/";
}
Класс Mapper:
public interface UserMapper {
@Insert("INSERT INTO users(group_id, code_level, login_name, password, full_name,"
+ "full_name_kana, birthday, email, tel, rule, salt) VALUES"
+ "(#{group_id.group_id}, #{code_level.code_level}, #{login_name},#{password}, #{full_name}, #{full_name_kana},"
+ "#{birthday}, #{email}, #{tel}, #{rule}, #{salt})")
@Options(useGeneratedKeys=true, keyProperty="id", flushCache=true, keyColumn="id")
public void insertUser(User user);
}
add_user.jsp file
<form:form action="${pageContext.request.contextPath}/addUser.html" method="POST" modelAttribute="createUser" commandName="createUser">
<span>login name<span class="required">*</span></span>
<form:input type="text" path="login_name" class="input-field" />
<span>password<span class="required">*</span></span>
<form:input type="text" path="password" class="input-field" />
<br>
<span>full name<span class="required">*</span></span>
<form:input type="text" path="full_name" class="input-field" />
<br>
<span>birthday<span class="required">*</span></span>
<form:input type="text" path="birthday" class="input-field" />
<br>
<span>email<span class="required">*</span></span>
<form:input type="text" path="email" class="input-field" />
<br>
<span>tel<span class="required">*</span></span>
<form:input type="text" path="tel" class="input-field" />
<br>
<span>Salt<span class="required">*</span></span>
<form:input type="text" path="salt" class="input-field" />
<span>End Date<span class="required">*</span></span>
<form:input type="text" path="detail_user_japan_id.end_date" class="input-field" />
<br>
<span>Total<span class="required">*</span></span>
<form:input type="text" path="detail_user_japan_id.total" class="input-field" />
<br>
<label>
<span></span>
<input type="Submit" value="Add new user" />
</label>
Когда я ввожу данные на странице формы и нажимаю кнопку отправить, я могу вставить данныев 2 таблицы нормально, но только 2 текстовых поля является 'end_date' и 'total' не может вставлять, кажется, нулевые или пустые данные
<span>End Date<span class="required">*</span></span>
<form:input type="text" path="detail_user_japan_id.end_date" class="input-field" />
<br>
<span>Total<span class="required">*</span></span>
<form:input type="text" path="detail_user_japan_id.total" class="input-field" />
<br>
Как решить проблему?