<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>learn-haoke-manage</artifactId><groupId>cn.learn.haoke.manage</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>learn-haoke-manage-api-server</artifactId><dependencies><!-- springboot的web支持 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>cn.learn.haoke.manage</groupId><artifactId>learn-haoke-manage-dubbo-server-house-resources-dubbo-interface</artifactId><version>1.0-SNAPSHOT</version></dependency><dependency><groupId>com.graphql-java</groupId><artifactId>graphql-java</artifactId><version>11.0</version></dependency></dependencies></project>
schema {query: HaokeQuery
}type HaokeQuery {HouseResources(id:Long) : HouseResourcesHouseResourcesList(page:Int, pageSize:Int) : TableResultIndexAdList:IndexAdResult
}type HouseResources {id:Long!title:StringestateId:LongbuildingNum:StringbuildingUnit:StringbuildingFloorNum:Stringrent:IntrentMethod:IntpaymentMethod:InthouseType:StringcoveredArea:StringuseArea:Stringfloor:Stringorientation:Stringdecoration:Intfacilities:Stringpic:StringhouseDesc:Stringcontact:Stringmobile:Stringtime:IntpropertyCost:String
}type TableResult{list:[HouseResources]pagination:Pagination
}type Pagination{current:IntpageSize:Inttotal:Int
}type IndexAdResult{list:[IndexAdResultData]
}type IndexAdResultData{original:String
}
package cn.learn.haoke.dubbo.api.controller;import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import graphql.GraphQL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;import java.io.IOException;
import java.util.HashMap;
import java.util.Map;@RequestMapping("graphql")
@Controller
@CrossOrigin
public class GraphQLController {@Autowiredprivate GraphQL graphQL;private static final ObjectMapper MAPPER = new ObjectMapper();/*** 实现GraphQL查询** @param query* @return*/@GetMapping@ResponseBodypublic Map<String, Object> query(@RequestParam("query") String query) {return this.graphQL.execute(query).toSpecification();}@PostMapping@ResponseBodypublic Map<String, Object> postQuery(@RequestBody String json) {try {JsonNode jsonNode = MAPPER.readTree(json);if(jsonNode.has("query")){String query = jsonNode.get("query").textValue();return this.graphQL.execute(query).toSpecification();}} catch (IOException e) {e.printStackTrace();}Map<String, Object> error = new HashMap<>();error.put("status", 500);error.put("msg", "查询出错");return error;}}
package cn.learn.haoke.dubbo.api.service;import cn.learn.haoke.dubbo.api.vo.Pagination;
import cn.learn.haoke.dubbo.api.vo.TableResult;
import cn.learn.haoke.dubbo.server.api.ApiHouseResourcesService;
import cn.learn.haoke.dubbo.server.pojo.HouseResources;
import cn.learn.haoke.dubbo.server.vo.PageInfo;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;@Service
public class HouseResourcesService {@Reference(version = "1.0.0")private ApiHouseResourcesService apiHouseResourcesService;public boolean save(HouseResources houseResources) {int result =this.apiHouseResourcesService.saveHouseResources(houseResources);return result == 1;}public TableResult<HouseResources> queryList(HouseResources houseResources, Integer currentPage, Integer pageSize) {PageInfo<HouseResources> pageInfo = this.apiHouseResourcesService.queryHouseResourcesList(currentPage, pageSize, houseResources);return new TableResult<>(pageInfo.getRecords(), new Pagination(currentPage, pageSize, pageInfo.getTotal()));}/*** 根据id查询房源数据** @param id* @return*/public HouseResources queryHouseResourcesById(Long id){// 调用dubbo中的服务进行查询数据return this.apiHouseResourcesService.queryHouseResourcesById(id);}
}
package cn.learn.haoke.dubbo.api.graphql;import graphql.GraphQL;
import graphql.schema.GraphQLSchema;
import graphql.schema.idl.RuntimeWiring;
import graphql.schema.idl.SchemaGenerator;
import graphql.schema.idl.SchemaParser;
import graphql.schema.idl.TypeDefinitionRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;import javax.annotation.PostConstruct;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;// 实现的功能:将GraphQL对象载入到Spring容器,并且完成GraphQL对象的初始化的功能
@Component
public class GraphQLProvider {private GraphQL graphQL;@Autowiredprivate List<MyDataFetcher> myDataFetchers;//实现对GraphQL对象的初始化@PostConstructpublic void init() throws FileNotFoundException {File file = ResourceUtils.getFile("classpath:haoke.graphqls");this.graphQL = GraphQL.newGraphQL(buildGraphQLSchema(file)).build();}private GraphQLSchema buildGraphQLSchema(File file) {TypeDefinitionRegistry typeRegistry = new SchemaParser().parse(file);return new SchemaGenerator().makeExecutableSchema(typeRegistry, buildWiring());}private RuntimeWiring buildWiring() {return RuntimeWiring.newRuntimeWiring().type("HaokeQuery", builder -> {for (MyDataFetcher myDataFetcher : myDataFetchers) {builder.dataFetcher(myDataFetcher.fieldName(),environment -> myDataFetcher.dataFetcher(environment));}return builder;}).build();}@Beanpublic GraphQL graphQL() {return this.graphQL;}}
package cn.learn.haoke.dubbo.api.graphql;import graphql.schema.DataFetchingEnvironment;public interface MyDataFetcher {/*** GraphQL中查询的名称** @return*/String fieldName();/*** 数据的查询** @param environment* @return*/Object dataFetcher(DataFetchingEnvironment environment);}

实现根据id查询房源数据的GraphQL服务相关推荐

  1. 实现根据id查询房源数据的dubbo服务

    package cn.learn.haoke.dubbo.server.api;import cn.learn.haoke.dubbo.server.pojo.HouseResources; impo ...

  2. SpringDataJpa根据多个id物品清单id查询房源编号

    需求:根据多个物品清单id去重查询房源编号 sql语句: select DISTINCT f.house_bill_no from financial_style_productitem_detail ...

  3. sql根据父id查询子项数据

    查询所属id及其子项数据 with CategoryIds as (   select id from ProductCategory where ParentId=102 or id=102   u ...

  4. 【微信小程序-原生开发】实用教程09 - 可滚动选项,动态列表-步骤条(含事件传参),动态详情(含微信云查询单条数据 doc)

    开始前,请先完成圆梦宝典中滚动公告栏的开发,详见 [微信小程序-原生开发]实用教程 08 - 开通微信云开发,操作云数据库新增数据(含修改数据权限),初始化云服务(含获取微信云环境 id),获取云数据 ...

  5. 实现房源列表的Dubbo服务的开发

    package cn.learn.haoke.dubbo.server.api;import cn.learn.haoke.dubbo.server.pojo.HouseResources; impo ...

  6. [译] Medium 的 GraphQL 服务设计

    原文地址:GraphQL Server Design @ Medium 原文作者:Sasha Solomon 译文出自:掘金翻译计划 本文永久链接:github.com/xitu/gold-m- 译者 ...

  7. MySQL 查询重复数据,删除重复数据保留id最小的一条作为唯一数据

    MySQL 查询重复数据,删除重复数据保留id最小的一条作为唯一数据 目录导航: 开发背景: 实战: 表结构如下图所示: 操作: 总结: 回到顶部 开发背景: 最近在做一个批量数据导入到MySQL数据 ...

  8. 基于Springboot外卖系统16:菜品修改模块+菜品信息回显+ID查询口味列表+组装数据并返回

    4.1 菜品修改模块需求分析 在菜品管理列表页面点击修改按钮,跳转到修改菜品页面,在修改页面回显菜品相关信息并进行修改,最后点击确定按钮完成修改操作. 4.2 菜品修改模块前端页面(add.html) ...

  9. 如何通过多个id查询多条数据

    如何通过多个id查询多条数据 如何通过多个id查询多条数据 List<Integer> list = Arrays.asList(1,2,3); List<ProductCatego ...

最新文章

  1. 网管常犯的十个错误-转载
  2. 什么是shell,shell基础由浅入深,常用的shell命令、用法、技巧
  3. bootstrap select多选
  4. PS效果教程——冒充手绘效果
  5. 跨域访问-JSONP
  6. python不能安装怎么办_python3安装不上怎么办
  7. python 删除sheet_python操作excel
  8. jfinal中Interceptor拦截器的使用
  9. [转]前端HTML书写不得不掌握的Emmet缩写语法
  10. 计算机语言中下划线表示什么,下划线是什么
  11. 【Excel 教程系列第 15 篇】Excel 中的简单排序(升序 / 降序)、多条件排序、按颜色排序、自定义排序、以及巧用“升序“制作工资条
  12. python函数——Bunch配置加载
  13. React 如何快速上手
  14. Unity中鼠标的锁定与解锁
  15. SQLMAP进阶使用 --tamper
  16. admin.php生成地址,FastAdmin隐藏后台登录入口地址的方法
  17. oracle 11g失败,求助,oracle 11g 启动失败,求大神帮忙看看,谢谢
  18. Tomcat部署与优化
  19. 基于JavaWeb的新闻发布管理系统设计与实现
  20. JS-文字上下滚动(多行停顿)

热门文章

  1. JS的隐式转换 从 [] ==false 说起
  2. IIS上的web service调用AX服务问题
  3. postgres循环sql
  4. MyBatis对于Java对象里的枚举类型处理
  5. springmvc中的全注解模式
  6. hdu 2825 Wireless Password AC自动机+状态DP
  7. 多张表数据导入到execl中
  8. java io复用_学习Java编程-IO复用
  9. linux系统 opt扩容,Linux系统扩容根目录磁盘空间的操作方法
  10. c++语言标准 pdf,C++14标准.pdf