多个表中的值 spring 验证概率
values in multiple tables spring validation prob
我在使用多个数据库时遇到问题 tables
我有什么:
输入:用户(table用户)
Inputfeld:Email(table 用户)
Input:Bookingnumber(table预订号)
仅使用输入字段表单 "user" 有效,从其他 table 添加预订号码会引发此错误:
Invalid target for Validator [shuttleservice.form.validator.UserFormValidator@1588512]: shuttleservice.form.model.Bookingnumber@18d7616
问题类似于
How insert values to multiple tables using spring and hibernate
和
Invalid target for Validator in spring error?
我只有两种形式
一个输出,只显示数据库数据
一个输入字段用于多个数据库 tables
我应该使用多个验证器吗?
// show add user form
@RequestMapping(value = "/users/add", method = RequestMethod.GET)
public String showAddUserForm(Model model) {
logger.debug("showAddUserForm()");
User user = new User();
Bookingnumber bookingnumber = new Bookingnumber();
// set default value
user.setName("setNewUserName");
user.setEmail("test123@gmail.com");
bookingnumber.setBookingnumber("123.456");
model.addAttribute("userForm", user);
//model.addAttribute("bookingnumberForm", bookingnumber);
model.addAttribute("userForm", bookingnumber);
populateDefaultModel(model);
System.out.println("#8");
return "users/userform";
}
创建一个模型 class 来包装您的所有表单字段并将这个新包装器的对象 class 传递给您的表单。然后编写一个验证器 class 来验证字段。
private class FormModel {
private User user;
private BookingNumber bookingNumber;
//Getter Setter ....
}
// show add user form
@RequestMapping(value = "/users/add", method = RequestMethod.GET)
public String showAddUserForm(Model model) {
logger.debug("showAddUserForm()");
FormModel formModel = new FormModel ();
User user = new User();
Bookingnumber bookingnumber = new Bookingnumber();
// set default value
user.setName("setNewUserName");
user.setEmail("test123@gmail.com");
bookingnumber.setBookingnumber("123.456");
formModel.setUser(user);
formModel.setBookingNumber(bookingNumber);
model.addAttribute("formModel", formModel);
return "users/userform";
}
我在使用多个数据库时遇到问题 tables 我有什么:
输入:用户(table用户) Inputfeld:Email(table 用户) Input:Bookingnumber(table预订号)
仅使用输入字段表单 "user" 有效,从其他 table 添加预订号码会引发此错误:
Invalid target for Validator [shuttleservice.form.validator.UserFormValidator@1588512]: shuttleservice.form.model.Bookingnumber@18d7616
问题类似于 How insert values to multiple tables using spring and hibernate
和 Invalid target for Validator in spring error?
我只有两种形式 一个输出,只显示数据库数据 一个输入字段用于多个数据库 tables
我应该使用多个验证器吗?
// show add user form
@RequestMapping(value = "/users/add", method = RequestMethod.GET)
public String showAddUserForm(Model model) {
logger.debug("showAddUserForm()");
User user = new User();
Bookingnumber bookingnumber = new Bookingnumber();
// set default value
user.setName("setNewUserName");
user.setEmail("test123@gmail.com");
bookingnumber.setBookingnumber("123.456");
model.addAttribute("userForm", user);
//model.addAttribute("bookingnumberForm", bookingnumber);
model.addAttribute("userForm", bookingnumber);
populateDefaultModel(model);
System.out.println("#8");
return "users/userform";
}
创建一个模型 class 来包装您的所有表单字段并将这个新包装器的对象 class 传递给您的表单。然后编写一个验证器 class 来验证字段。
private class FormModel {
private User user;
private BookingNumber bookingNumber;
//Getter Setter ....
}
// show add user form
@RequestMapping(value = "/users/add", method = RequestMethod.GET)
public String showAddUserForm(Model model) {
logger.debug("showAddUserForm()");
FormModel formModel = new FormModel ();
User user = new User();
Bookingnumber bookingnumber = new Bookingnumber();
// set default value
user.setName("setNewUserName");
user.setEmail("test123@gmail.com");
bookingnumber.setBookingnumber("123.456");
formModel.setUser(user);
formModel.setBookingNumber(bookingNumber);
model.addAttribute("formModel", formModel);
return "users/userform";
}