⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addressbookaction.java

📁 使用struts2及Spring框架对数据库表进行增删改查操作
💻 JAVA
字号:
package crud;

import crud.dao.AddressDao;
import crud.model.Address;
import crud.model.StatesList;

import java.util.Collection;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

/**
 *	Address form handler.
 */
public class AddressBookAction extends ActionSupport 
{
	static final long serialVersionUID = -726287915382955298L;

	/**	adddress information is stored in this object.
 	 *	@see crud.model.Address
	 */
	private Address address;

	/** provider of data access to the Address records table.
	 */
    private AddressDao dao;


	/** The Spring injected Address data access object.
	 */
    public void setAddressDao(AddressDao dao) 
	{
        this.dao = dao;
    }


	/**	a collection of US States.
 	 *	@see crud.model.StatesList
	 */
	StatesList statesList;


	/**	Spring injected list of states.
	 * @param a list of State objects.
	 * @see crud.model.StatesList
	 * @see crud.model.State
	 */
	public void setStatesList( StatesList list )
	{
		this.statesList = list;
	}


	/**	Accessor for a collection os US States names and abbreviations.
 	 *	@see crud.model.States
 	 *	@see crud.model.State
	 *	@return a collection of States.
	 */
	public StatesList getStatesList()
	{
		return this.statesList;
	}


	/**	Accessor for the address entry object.
 	 *	@see crud.model.Address
	 */
	public Address getAddress()
	{
		return this.address;
	}


	/**	Accessor for the address entry object.
 	 *	@see crud.model.Address
	 */
	public void setAddress( Address ae )
	{
		this.address = ae;
	}


	/**	reset (clear) the current Address.
	 */
    public String reset() throws Exception 
	{
		super.clearErrorsAndMessages();

		this.address = null;

        setMessage( getText(MESSAGE) );
		return SUCCESS;
	}

	/**	update (save) the current Address. 
	 */
    public String update() throws Exception 
	{
		dao.updateAddress( this.address );
		setMessage( getText(ADDRESS_SAVED) );
		return SUCCESS;
	}

	/** find an address (by example).
	 */
    public String find() throws Exception 
	{
		List list = dao.getAddress( this.address );
		if( list.size() > 0 )
			setAddress( (Address) list.get(0) );
        setMessage(getText(ADDRESS_FOUND, "0", new String[] { String.valueOf(list.size() ) }));
		return SUCCESS;
	}


	/**	remove an address.
	 */
    public String remove() throws Exception 
	{
		int rowCount = dao.deleteAddress( this.address );
		if( rowCount > 0 )
			this.address = null;

        setMessage(getText(ADDRESS_DELETED, "0", new String[] { String.valueOf(rowCount) }));
		return SUCCESS;
 	}

    public String execute() throws Exception 
	{
        setMessage(getText(MESSAGE));
        return SUCCESS;
    }


    /**	Default 'ready' message.
     */
    public static final String MESSAGE = "addressbook.default.message";

    /**	Operation 'successful' message.
     */
    public static final String ADDRESS_SAVED = "addressbook.updated.message";

    /**	Delete operation 'successful' message.
     */
    public static final String ADDRESS_DELETED = "addressbook.deleted.message";

    /**	Find operation 'successful' message.
     */
    public static final String ADDRESS_FOUND = "addressbook.found.message";


    /**
     * Field for Message property.
     */
    private String message;

    /**	Accessor for  the Message property.
     *	@return Message property
     */
    public String getMessage() { return message; }

    /**	Accessor for the Message property.
     *	@param message Text to display on the AddressForm page.
     */
    public void setMessage(String message) { this.message = message; }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -