📄 customeraction.java
字号:
package com.ghy.action;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.ghy.data.Customer;
import com.ghy.service.CustomerServiceIfc;
import com.opensymphony.xwork2.ActionSupport;
public class CustomerAction extends ActionSupport {
private Customer customer ;
private CustomerServiceIfc customerServiceIfc;
private ArrayList customers ;
public ArrayList getCustomers() {
return customers;
}
public void setCustomers(ArrayList customers) {
this.customers = customers;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public CustomerServiceIfc getCustomerServiceIfc() {
return customerServiceIfc;
}
public void setCustomerServiceIfc(CustomerServiceIfc customerServiceIfc) {
this.customerServiceIfc = customerServiceIfc;
}
public String execute() throws Exception {
// TODO Auto-generated method stub
ArrayList arrayList = customerServiceIfc.findAllCustomer();
customers = arrayList;
return SUCCESS;
}
public String add() throws Exception
{
customerServiceIfc.saveCustomer(customer);
ArrayList arrayList = customerServiceIfc.findAllCustomer();
customers = arrayList;
return SUCCESS;
}
public String find() throws Exception
{
HttpServletRequest request = ServletActionContext.getRequest();
String id = request.getParameter("id");
Customer customer = (Customer)customerServiceIfc.findCustomerById(id).get(0);
this.customer = customer ;
return "find" ;
}
public String update() throws Exception
{
customerServiceIfc.updateCustomer(customer);
ArrayList arrayList = customerServiceIfc.findAllCustomer();
customers = arrayList;
return SUCCESS;
}
public String delete() throws Exception
{
HttpServletRequest request = ServletActionContext.getRequest();
String id = request.getParameter("id");
Customer customer = (Customer)customerServiceIfc.findCustomerById(id).get(0);
customerServiceIfc.deleteCustomer(customer);
ArrayList arrayList = customerServiceIfc.findAllCustomer();
customers = arrayList;
return SUCCESS;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -