? ? 現(xiàn)在需要一個(gè)第三方接口提供數(shù)據(jù),就要訪問第三方接口 并且傳遞參數(shù)給接口 然后接收到接口返回的數(shù)據(jù) 現(xiàn)在就是不知道調(diào)用第三方接口具體實(shí)現(xiàn)怎么寫,在百度查了感覺看的沒有頭緒,希望會(huì)的您指點(diǎn)一下,不勝感激!
2 回答
已采納

大咪
TA貢獻(xiàn)785條經(jīng)驗(yàn) 獲得超332個(gè)贊
給你舉個(gè)例子,比如我要實(shí)現(xiàn)用戶登錄的例子,首先編寫的是自己用戶業(yè)務(wù)邏輯接口
public?interface?UsersDAO?{ //用戶登錄方法 public?boolean?usersLogin(Users?u); }
然后實(shí)現(xiàn)他的接口類
public?class?UserDAOImpl?implements?UsersDAO{ public?boolean?usersLogin(Users?u)?{ //事物對(duì)象 Transaction?tx?=?null; String?hql?=?""; try{ Session?session?=?myHibernateSessionFactory.getSessionFactory().getCurrentSession(); tx?=?session.beginTransaction(); hql?=?"from?Users?where?username=??and?password=??"; Query?query?=?session.createQuery(hql); query.setParameter(0,?u.getUsername()); query.setParameter(1,?u.getPassword()); List?list?=?query.list(); tx.commit();//提交事務(wù) if(list.size()>0){ return?true; }else{ return?false; } }catch(Exception?ex){ ex.printStackTrace(); return?false; }finally{ if(tx!=null){ // tx.commit(); tx?=?null; } }
這是我之前寫項(xiàng)目里的一個(gè)業(yè)務(wù)類和他的實(shí)現(xiàn)類,拿來給你作參考。??纯词遣皇悄阏f的那種。。。
添加回答
舉報(bào)
0/150
提交
取消