解决办法:我们对于要传值类的实例化后还必须对他进行set和get(红色字体是关键)
如果不进行set和get就就会出现只能从表单中读取String类型的数据。
一旦你的实体类中有int或其他类型的数据就会出现传输错误,活着传空值的情况
package bat.action;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import bat.entity.User;
import bat.service.CustomerService;
public class CustomerAction extends ActionSupport implements ModelDriven<User>{
//模型驱动 前提条件类中属性名称和表单中名称一样
private User customer=new User();
public User getModel() {
// TODO Auto-generated method stub
return customer;
}
private CustomerService customerService;
public void setCustomerService(CustomerService customerService) {
this.customerService = customerService;
}
public User getCustomer() {
return customer;
}
public void setCustomer(User customer) {
this.customer = customer;
}
//1到添加页面
public String toAddPage() {
return "toAddPage";
}
//2添加方法
public String add() {
customerService.add(customer);
return "add";
}
//3列表显示
public String list() {
return "list";
}
//删除和修改
}