2013-03-12 37 views
-4

我有以下代碼在類customerModel。如何從另一個類customerController調用此方法?如何將arraylist方法調用到另一個類?

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? 
} 
+9

** **儘快被BADD .... – PermGenError 2013-03-12 10:02:14

+1

來創建此方法屬於和使用對象調用該方法的類的對象。 – Meherzad 2013-03-12 10:03:19

+4

如果你已經嘗試了很長時間......爲什麼現在你需要的是儘快? – 2013-03-12 10:03:55

回答

0

使在同一包裝的另一個類,聲明類

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

這個實例可能不是你後和校長几乎didnt答案這是一個多麼壞的問題,但仍這可能幫助你

FYI語法在這裏並不完美,例如。你的方法返回一些東西,所以你可能想讓這個方法調用一個列表聲明或者類似於下面的答案(或者上面的人知道)我的觀點是我不想給這個問題一個完整的樣本答案只是幫助有點

0

在你CustomerController做到這一點: -

CustomerModel model = new CustomerModel(); 
List<Customer> myList = model.search(customer); 
+0

我要創建它裏面的CustomerController即 「公共類CustomerCOntroller內的另一種方法無意見或upvotes .... 公共布爾搜索???? – user2160326 2013-03-12 11:37:02

+0

然後將該代碼放入該方法中。就如此容易。 – SudoRahul 2013-03-12 13:43:58

相關問題