1. 程式人生 > >ssh練手(五)BatchAction

ssh練手(五)BatchAction

package com.chenjia.batchsys.action;

import java.util.List;

import com.chenjia.batchsys.domain.Batch;
import com.chenjia.batchsys.service.BatchService;
import com.opensymphony.xwork2.ActionSupport;
/**
 *
 * @author chenjia
 *
 */
public class BatchAction extends ActionSupport {
    private BatchService batchService;

    public void setBatchService(BatchService batchService) {
        this.batchService = batchService;
    }
    
    private Batch batch;
    private List<Batch> batchs;
    private int id;

    public Batch getBatch() {
        return batch;
    }
    public void setBatch(Batch batch) {
        this.batch = batch;
    }
    public List<Batch> getBatchs() {
        return batchs;
    }
    public void setBatchs(List<Batch> batchs) {
        this.batchs = batchs;
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    
    public String add()
    {
        // 呼叫業務邏輯元件的addBook()方法來處理使用者請求        
        int result = batchService.addBatch(batch);
        if(result > 0)
        {
            addActionMessage("恭喜您,新增成功!");
            return SUCCESS;
        }
        addActionError("新增失敗,請重新輸入!");
        return ERROR;
    }
    public String list()
    {
        setBatchs(batchService.getAllBatchs());
        return SUCCESS;
    }
    public String delete()
    {
        batchService.deleteBatch(id);
        return SUCCESS;
    }
}