2013-03-12 82 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

相关问题