版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qgnczmnmn/article/details/86629400
struts2中实现ModelDriven接口作用
以下边的代码为例来介绍该接口作用:
public class CustomerAction extends ActionSupport implements ModelDriven<Customer> {
private Customer customer=new Customer();
@Override
public Customer getModel() {
return customer;
}
//添加客户信息
public String addCustomer(){
customerService.saveCustomer(customer);
return "addCustomer";
}
当接收提交的表单信息时,实现了ModelDriven接口的action可以直接获取对应的Customer实例对象,它会将Object getModel()方法取得的输入数据的对象模型,这样就不用实现实体类中属性的getter()和setter()方法了。但是使用要注意:必须在action中对实体类进行new操作。