day06開發(fā)graphql服務(wù)以及前臺系統(tǒng)搭建講義_第1頁
day06開發(fā)graphql服務(wù)以及前臺系統(tǒng)搭建講義_第2頁
day06開發(fā)graphql服務(wù)以及前臺系統(tǒng)搭建講義_第3頁
day06開發(fā)graphql服務(wù)以及前臺系統(tǒng)搭建講義_第4頁
day06開發(fā)graphql服務(wù)以及前臺系統(tǒng)搭建講義_第5頁
已閱讀5頁,還剩42頁未讀 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

-haoke-manage-dubbo-server-house-resources-dubbo-interface中11234567*@paramHouseResourcesqueryHouseResourcesById(Long -haoke-manage-dubbo-server-house-resources-dubbo-service中publicHouseResourcesqueryHouseResourcesById(Longid)return 、業(yè)務(wù)Service112345678packageimportcn.importimportimportimport9importimportimplementsHouseResourcesService{@param@return1:輸入的參數(shù)不符合要求,0:數(shù)據(jù)插入數(shù)據(jù)庫失敗,1publicintsaveHouseResources(HouseResourceshouseResources)if(StringUtils.isBlank(houseResources.getTitle()))return-}return}HouseResourcesqueryCondition){QueryWrapperqueryWrapper=newIPageiPage=super.queryPageList(queryWrapper,page,returnnewPageInfo<HouseResources>(Long.valueOf(iPage.getTotal()).intValue(),page,pageSize,iPage.getRecords());}publicHouseResourcesqueryHouseResourcesById(Long{return}}、編寫haoke.graphqls在 下創(chuàng)建haoke.graphqls文件1123456789schemaquery:}type{}HouseResources{id:Long!title:String}、編寫1packagecn.23import4import5import6importorg.springframework.web.bind.annotation.GetMap7importorg.springframework.web.bind.annotation.RequestMap8import9importimportimport@RequestMappublicclassGraphQLControllerprivateGraphQLpublicMap<String,Object>graphql(@RequestParam("query")Stringquery)IOExceptionreturn}}、編寫1123456789packageimportimportimportgraphql.schema.GraphQLSchema;importgraphql.schema.idl.RuntimeWiring;importgraphql.schema.idl.SchemaParser;importimportorg.springframework.context.annotation.Bean;importimportimportjava.io.File;importpublicclassGraphQLProviderprivateGraphQLprivateHouseResourcesServicepublicvoidinit()throwsIOExceptionFilefile=GraphQLSchemagraphQLSchema=this.graphQL=}privateGraphQLSchemabuildSchema(Filefile)TypeDefinitionRegistrytypeRegistry=newRuntimeWiringruntimeWiring=SchemaGeneratorschemaGenerator=newreturnschemaGenerator.makeExecutableSchema(typeRegistry,}privateRuntimeWiringbuildWiring()return.type("HaokeQuery",builder-environment->Longid=return}}return}}、chrome安裝 插為chrome瀏覽器安裝Altair 插件安裝地址 /webstore/detail/altair- 112345packageimportpublicinterfaceMyDataFetcher6}*String@paramObjectdataFetcher(DataFetchingEnvironment7891123456789packageimportimportimportimport@Component//加入到SpringpublicclassHouseResourcesDataFetcherimplementsMyDataFetcherprivateHouseResourcesServicepublicString{return}publicObjectdataFetcher(DataFetchingEnvironment{Longid=environment.getArgument("id");}}11package23importimportimportimportimportimportimportimportimport importimportimportimportimportpublicclass{privateGraphQLgraphQL;privateList<MyDataFetcher>myDataFetchers;注入容器中所有的MyDataFetcher實現(xiàn)類publicvoidinit()throwsIOExceptionFilefile=GraphQLSchemagraphQLSchema=this.graphQL= privateGraphQLSchemabuildSchema(Filefile)TypeDefinitionRegistrytypeRegistry=newRuntimeWiringruntimeWiring=SchemaGeneratorschemaGenerator=newreturnschemaGenerator.makeExecutableSchema(typeRegistry, privateRuntimeWiringbuildWiring() return .type("HaokeQuery",builder-> for(MyDataFetchermyDataFetcher:myDataFetchers) environment- return }}returnschemaquery:34typeHaokeQueryHouseResourcesList(page:Int,89type 33typelist:pagination:38type}、新增HouseResourcesListDataFetcherimportimportimportorg.springframew importimportpublicclassHouseResourcesListDataFetcherimplements{privateHouseResourcesServicehouseResourcesService;return publicObjectdataFetcher(DataFetchingEnvironmentenvironment)Integerpage=if(page==page= IntegerpageSize=if(pageSize==pageSize= returnthis.houseResourcesService.queryList(null,page, 3611HouseResourcesList(page:1,{56789}}}} npmnpminstall#npmstart#前端團隊在開發(fā)時,沒有采用mock的方式,而是采用了使用node.js開發(fā)服務(wù)端的方式進行了emo 1123456789npminstall#安裝依賴npmrundev#啟動 "scripts":"test":"cross-envNODE_ENV=config-testnode"pro":"cross-envNODE_ENV=config-pronodeapp.js" 1123456789//設(shè)置全局的baseUrlaxios.defaults.baseURL=器erceptors.request.use(function(config)在發(fā)送請求之前獲取mytokenconfig.headers.Authorization=}return},function(error)//erceptors.response.use(function(response)//return},function(error)return在common.js112345678exportdefault//imgBaseUrl://apiBaseUrl://wsBaseUrl:apiBaseUrl:wsBaseUrl:}從代碼中可以看出,通過mise.al()方法獲取到所有的異步處理的結(jié)果,并且將結(jié)果保存到this.state然后,在ender中進行渲染:1123456789{{{{}]"status":"msg":"測試數(shù)據(jù)}""""""}CREATECREATETABLE`tb_ad``id`bigint(20)NOTNULL`type`int(10)DEFAULTNULLCOMMENT 類型`title`varchar(100)DEFAULTNULLCOMMENT'描述`url`varchar(200)DEFAULTNULLCOMMENT URL地址`created`datetimeDEFAULT`updated`datetimeDEFAULTPRIMARYKEY)ENGINE=InnoDBDEFAULTCHARSET=utf8 表'2018-11-26'2018-11-26/images/2018/11/26/15432029946721854.jpg','2018-11-26-海逸長洲'周邊嘉興'1',5INSERTINTO`tb_ad`(`id`,`type`,`title`,`url`,`created`,`updated`)VALUES('1','1','UniCity萬科天空之城',' /images/2018/11/26/15432029097062227.jpg','2018-11-26'2018-11-26INSERTINTO`tb_ad`(`id`,`type`,`title`,`url`,`created`,`updated`)VALUES('2','1','天和尚海庭前',' /images/2018/11/26/1543202958579877.jpg','2018-11-26'2018-11-26INSERTINTO`tb_ad`(`id`,`type`,`title`,`url`,`created`,`updated`)VALUES('3','1','[奉賢南橋]光語著',' /images/2018/11/26/15432029946721854.jpg','2018-11-26'2018-11-264321創(chuàng) -haoke- mon工程,將BasePojo、BaseServiceImpl移動至該工程其他工程,如 ms,需要依賴此工程,并且將自己工程中的相關(guān)類刪除。123456789<?xmlversion="1.0"encoding="UTF-<projectxmlns="<groupId>cn. 11234<?xmlversion="1.0"encoding="UTF-<project""56789-haoke-manage-dubbo-server-ad-service的pom.xml11234<?xmlversion="1.0"encoding="UTF-<project""56789、編寫12packagecn.3importcom.baomidou.mybatisplus.annotation.IdType;importcom.baomidou.mybatisplus.annotation.TableId;importlombok.AllArgsConstructor;importimportpublicclassAdextendsBasePojoprivatestaticfinallongserialVersionUID=@TableId(value="id",type=IdType.AUTO)privateLongid;privateIntegerprivateStringprivateString}4567891123456789packageimportimportpublicinterfaceApiAdService**@param @parampage@parampageSizePageInfo<Ad>queryAdList(Integertype,Integerpage,Integer}-haoke-manage-dubbo-server-ad--haoke-manage-dubbo-server-ad-1123456789packageimportcn.importimportimportimport@Service(version=publicclassApiAdServiceImplimplementsApiAdServiceprivateAdServicepublicPageInfo<Ad>queryAdList(Integertype,Integerpage,IntegerpageSize)Adad=newAd();returnthis.adService.queryAdList(ad,page,}}、實現(xiàn)1123456789packageimportimportpublicinterfaceAdServicePageInfo<Ad>queryAdList(Adad,Integerpage,Integer}112345678packageimportcn.importcn.importimportimportimport9publicclassAdServiceImplextendsBaseServiceImplimplementsAdServicepublicPageInfo<Ad>queryAdList(Adad,Integerpage,IntegerpageSize)IPage<Ad>iPage=super.queryPageListByWhere(ad,page,returnnewPageInfo(Long.valueOf(iPage.getTotal()).intValue(),pageSize,}}-haoke-manage-dubbo-server-ad-1123456789packageimportimportpublicinterfaceAdMapperextendsBaseMapper<Ad>}、編寫-haoke-manage-dubbo-server-ad-1123456789packageimportcom.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;importorg.mybatis.spring.annotation.MapperScan;importimportpublicPaginationInterceptor{returnnew}}1123456#S789#dubbo.scan.basePackages===tocol.port= dubbo.registry.address== 1123456789packageimportimportorg.springframework.boot.autoconfigure.SpringBootApplication;importpublicclassAdDubboProviderpublicstaticvoidmain(String[]args)new}}112345、編寫1123456789packageimportcn.importcn.importimportimportimportimportjava.util.HashMap;importjava.util.List;import}privateAdServicepublicWebResultqueryIndexAd()List<Ad>ads=pageInfo.getRecords();for(Adad:ads){map.put("original",ad.getUrl());}return}、編寫1123456789packageimportcn.importcn.importimportimportcom.alibaba.dubbo.config.annotation.Reference;importorg.springframework.stereotype.Service;publicclassAdService@Reference(version="1.0.0")publicWebResultqueryAdList(Integertype,Integerpage,Integer{PageInfo<Ad>adPageInfo=this.apiAdService.queryAdList(type,page,return}}、編寫123456789packagecn.importcom.fasterxml.jackson.annotation.JsonIgnore;importlombok.AllArgsConstructor;importimportjava.util.List;importjava.util.Map;publicclassWebResultprivateList<?>publicstaticWebResultok(List<?>{returnnewWebResult(200,"成功}{returnnewWebResult(200,msg,}publicMap<String,Object>getData()HashMap<String,Object>data=newHashMap<String,Object>();data.put("list",this.list);return}publicMap<String,Object>getMeta()HashMap<String,Object>meta=newHashMap<String,Object>();meta.put("msg",this.msg);meta.put("status",this.status);returnmeta;}}1123456letswipe=newPromise((resolve,reject)=>//1123456789{{{{}]"status":"msg":"測試數(shù)據(jù)}""""""}結(jié)合輪播圖組件的需求,只需要返回list數(shù)組,并且每個對象包含orgial11 "original":- "original":" "original":" }]}、編寫schemaquery:}12345typeHaokeQuery67HouseResourcesList(page:Int,89}type}typelist:pagination:}type}typelist:[IndexAdResu}}1packagecn.23import4import5import67import89privateList<IndexAdResuata>}3456、編寫1packagecn.234importcn.5importcn..haoke.dubbo.api.vo.ad.index.IndexAdResu6importcn.7importcn.8import9importimport importimportpublicclassIndexAdDataFetcherimplementsMyDataFetcherprivateAdServicereturn}publicObjectdataFetcher(DataFetchingEnvironmentenvironment)PageInfo<Ad>pageInfo

溫馨提示

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

評論

0/150

提交評論