sgp node服務(wù)器端開發(fā)者教程_第1頁(yè)
sgp node服務(wù)器端開發(fā)者教程_第2頁(yè)
sgp node服務(wù)器端開發(fā)者教程_第3頁(yè)
sgp node服務(wù)器端開發(fā)者教程_第4頁(yè)
sgp node服務(wù)器端開發(fā)者教程_第5頁(yè)
已閱讀5頁(yè),還剩13頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

MySQL數(shù)據(jù) 引入jar SDKAPI的使用介 Aware系列接 Redis操 MongoDB操 RPC服務(wù)示 sgp-node服務(wù)端SDK為第開發(fā)者提供了簡(jiǎn)單易用的api調(diào)用服務(wù),以及常用的業(yè)務(wù)層node上面的應(yīng)用程序。在管理申請(qǐng)客戶端具體操作請(qǐng)參考開發(fā)者管理操作手冊(cè),這里主要介紹基于SDK開發(fā)應(yīng)用MySQL安裝 如果的版本在安裝后沒(méi)有MySQL服務(wù),在手動(dòng)添加服務(wù)時(shí),需注意必須以管理員啟動(dòng)命令必須切換到MySQL安裝路徑的bin 下執(zhí)行mysqld–installmysql,否則會(huì)出現(xiàn)系統(tǒng)安裝完成并解壓文件后,在bin\release下的解壓相應(yīng)版本的啟動(dòng)工具(如64位:redisbin64.zipredis-server.exeredisredis-cli.exe即SDK地址 該地址同時(shí)提供了MySQL、MongoDB、Redisjar引入SDK包中的sgp-node- packagepublicinterface Stringsay o(Stringname);}packageimportme.gall.gtzs.service. importme.gall.sgp.node.util.annotation.SgpService; publicclassoWorldServiceImplimplements publicStringsayo(Stringname){return"o"+name;}}sgp.node.service.package=右擊工程→RunAs→RunConfigurations…Java在Main選項(xiàng)卡中,設(shè)置Name,選擇Project,查找或輸入Mainclass如上圖所示是默認(rèn)參數(shù),分別是測(cè)試服務(wù)器端、MySQL數(shù)據(jù)庫(kù)的用戶名、。設(shè)置默認(rèn)為“test_sgpDEBUG運(yùn)行模式。.URL;importimportcom. publicclassServiceTest{publicvoidsay o(){try{

Stringurl=" =newJsonRpcHttp(newStringresult= o",newObject[]{"developer"}catch(Throwablee){}}}運(yùn)行單元測(cè)試,輸出“odeveloper”表示成功SDKAPIcontext自動(dòng)注入Context*@paramcontextContextpublicvoidsetContext(Context}*@paramappIdpublicvoidinit(String@paramcontextcontextpublicvoidinit(Context}initinit(StringappId),init(Contextcontext),可根據(jù)需要實(shí)現(xiàn)相應(yīng)的方法即可。通常實(shí)現(xiàn)第二個(gè)方法??梢訟PPID@paramvoidsetAppId(String}MySQL(CRUDOperatorCharacterEq(條件和值為等號(hào)關(guān)系@paramemEntityManager@paramexample@returnpublicstatic<T>Specification<T>create(finalEntityManagerem,finalT@paramemEntityManager@paramexample@paramlc@returnpublicstatic<T>Specification<T>create(finalEntityManagerem,finalTexample,finalOperatorCharacterlc);該類可用于封裝查詢條件。其中關(guān)系運(yùn)算符默認(rèn)為=,其他包含RedisRedisrediskey@paramappId@paramkey自定義的KEY@returnpublicstaticStringgetRedisKey(StringappId,Stringrediskey@paramappIdpublicstaticStringgetRedisKeyPrefix(StringrediskeyMongoDBMongoDB(CRUD都會(huì)被初始化一個(gè)實(shí)例,每個(gè)service都有一個(gè)名稱,該服務(wù)即使用這個(gè)名稱。如:sgp.node.service.package=me.gall.dev.a.service,me.gall.dev.b.serviceSGP中已經(jīng)提供了角色的基礎(chǔ)信息me.gall.sgp.sdk.entity.app.Sgp 提供包含有yerId屬性的普通的實(shí)其中,rpcServiceName即要的rpc服務(wù)的名稱,該名稱具體信息見(jiàn)下一節(jié)test_sgpappId。用戶自定義服務(wù)名約定業(yè)務(wù)實(shí)現(xiàn)類有@SqpServicenameRPCRPCpublicclassUserServiceImpl{}userServiceServiceManager如:類名 RPC這里提供一個(gè)關(guān)于信息服務(wù)的示例(僅用于展示RPC服務(wù)的創(chuàng)建和使用方法。packageimport*信@Table(name=publicclassWeaponInfoimplementsSerializable{privatestaticfinallongserialVersionUID=1L;/**IDprivateIntegerid;/**名@Column(name="name",length=30,nullable=false)privateStringname;/**@Column(name="`desc`",length=128,nullable=false)privateStringdesc;/**@Column(name="grade",nullable=false)privateIntegergrade;/**職業(yè)限定(可以考慮是否用以前的二進(jìn)制加法計(jì)算...)*/@Column(name="class",nullable=false)privateInteger/**@Column(name="level",nullable=false)privateIntegerlevel;/**下限@Column(name="damage_min",nullable=false)privateIntegerdamageMin;/**上限@Column(name="damage_max",nullable=false)privateIntegerdamageMax;/**固有屬性(調(diào)用屬性表)@Column(name="property",length=20,nullable=false)privateStringproperty;/**@Column(name="value",nullable=false)privateIntegervalue;/**下一對(duì)應(yīng)ID@Column(name="next_grade",nullable=false)privateIntegernextGrade;/**買入價(jià)(銀幣)@Column(name="buy",nullable=false)privateIntegerbuy;/**買入價(jià)(元寶)@Column(name="tokey",nullable=false)privateIntegertokey;/**賣出價(jià)(僅銀幣)*/@Column(name"sell",nullablefalse)privateIntegersell;/**@Column(name="icon",length=30,nullable=false)privateStringicon;//getter/setter}RPC服務(wù)接口如下packageimportimportpublicinterfaceWeaponService添加或修改信@param根據(jù)ID刪除信@paramvoiddeleteWeaponInfo(Integer根據(jù)ID獲取信@param獲取所有信@param@paramList<WeaponInfo>getAllWeaponInfo(intpageSize,int根據(jù)名稱查詢信@param}packageme.gall.gtzs.service.impl;importjava.util.List;importimportme.gall.gtzs.entity.WeaponInfo;importme.gall.sgp.node.context.Context;importme.gall.sgp.node.orm.repository.SgpJpaRepository;importme.gall.sgp.node.support.SgpContextAware;importorg.springframework.data.importorg.springframework.data..PageRequest;importorg.springframework.data..Pageable;importorg.springframework.data..Sort;importorg.springframework.data..Sort.Direction;importorg.springframework.data.jpa..Specifications;publicclassWeaponServiceImplimplementsWeaponService,SgpContextAware{privateSgpJpaRepository<WeaponInfo,Integer>dao;privateEntityManagerpublicvoidsetContext(Contextcontext)dao=context.getSgpJpaRepository(WeaponInfo.class);em=context.getEntityManager();}returndao.save(weaponInfo);}publicvoiddeleteWeaponInfo(Integerid){}publicWeaponInfogetWeaponById(Integerid){returndao.findOne(id);}publicList<WeaponInfo>getAllWeaponInfo(intpageSize,intpageNumber){Pageablepageable=newPageRequest(pageNumber,pageSize,newDirection.ASC,"name"));Page<WeaponInfo>page=dao.findAll(pageable);if(page!=null){return}return}publicList<WeaponInfo>getWeaponByName(Stringname){WeaponInfoweaponInfo=newWeaponInfo();returndao.findAll(Specifications.where(SgpSpecification.create(em,weaponInfo,OperatorCharacter.Like)));}}pertiesservice掃描的包:sgp.node.service.package=me.gall.dev.serviceRPCjava.io.Serializable實(shí)體上必須有@Entity和@Table必須通過(guò)@ID默認(rèn)情況下所有屬性會(huì)映射成表字段,就算沒(méi)有@Column如果屬性名和表字段名不一致的,可使用@Columnname如果屬性名和表中的關(guān)鍵字重名的,使用“`相同類型條件可以使用同一實(shí)體不同類型的條件必須分開比如根據(jù)的名稱模糊查詢,以及和等級(jí)相等來(lái)查詢:WeaponInfoweaponIn

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論