-4

class にある次のコードがありますcustomerModel。という別のクラスからこのメソッドを呼び出すにはどうすればよいcustomerControllerですか?

public ArrayList<Customer> search(Customer cust) {
    ArrayList<Customer> custs = new ArrayList<Customer>();
    Connection connection = GaritsConnectivity.connect();
    Tuple<ResultSet, Statement> trs = GaritsConnectivity.read("SELECT * FROM Customer     WHERE CustomerID=1", connection);
    ResultSet rs = trs.getFirst();
    try {
        //takes a customer, returns it with the correct ID set
        while (rs.next()) {
            custs.add(createFromRs(rs));
        }
    } catch (SQLException ex) {
        GaritsConnectivity.manageException("Customer search failure", ex);
    }
    GaritsConnectivity.doneReading(connection, trs);
    return custs;
}

クラス内で、customerControllerから検索メソッドを呼び出せる別のメソッドを作成したいと思いますCustomerModel

public class customerController....

public boolean search(){
//what goes in here im lost? how can i connect the above search from customerModel to      customerController?
}
4

2 に答える 2

0

同じパッケージ内に別のクラスを作成し、クラスのインスタンスを宣言します

customerModel cM = new customerModel();
cM.search(Customer cust);

これはあなたの後のものではないかもしれませんし、プリンシパルについてはほとんど答えませんでした。これは悪い質問ですが、それでもこれはあなたを助けるかもしれません

参考までに、ここでの構文は完璧ではありません。あなたのメソッドは何かを返すので、メソッド呼び出しにリストの宣言または以下の回答のようなものを作成したい場合があります(またはおそらく誰が知っているか)私のポイントは、この質問の完全なサンプル回答を提供したくないということです少し

于 2013-03-12T10:04:48.293 に答える
0

あなたCustomerControllerはこれを行います:-

CustomerModel model = new CustomerModel();
List<Customer> myList = model.search(customer);
于 2013-03-12T10:04:59.373 に答える