customeraction.java

来自「SSH2实现增删改查的小DEMO」· Java 代码 · 共 80 行

JAVA
80
字号
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 + =
减小字号Ctrl + -
显示快捷键?