当前位置: 首页 > news >正文

推荐几个用vue做的网站/合肥推广外包公司

推荐几个用vue做的网站,合肥推广外包公司,我的网站为什么,郑州做音响网站的公司Spring Cloud MyBatis Plus GraphQL 完整示例 1、创建Spring Boot子项目1.1 配置POM,添加必要的依赖1.2 配置MyBatis-Plus 2、集成GraphQL2.1 定义schema.graphqls2.2 添加GraphQL解析器2.3 配置schame文件配置 3、访问测试3.1 查询测试(演示&#xff…

Spring Cloud + MyBatis Plus + GraphQL 完整示例

  • 1、创建Spring Boot子项目
    • 1.1 配置POM,添加必要的依赖
    • 1.2 配置MyBatis-Plus
  • 2、集成GraphQL
    • 2.1 定义schema.graphqls
    • 2.2 添加GraphQL解析器
    • 2.3 配置schame文件配置
  • 3、访问测试
    • 3.1 查询测试(演示)
    • 3.2 添加测试(演示)
    • 3.3 修改测试(演示)
    • 3.4 删除测试(演示)

为了创建一个完整的Spring Cloud应用,结合MyBatis-Plus和GraphQL,构建一个简单的微服务项目。这个示例将包括以下几个部分:- 创建Spring Boot子项目。
- 配置MyBatis-Plus以进行数据库操作。
- 集成GraphQL以提供查询接口。
- 我们将假设有一个简单的实体类Person,并为其创建CRUD操作和GraphQL查询。

1、创建Spring Boot子项目

1.1 配置POM,添加必要的依赖

  • 首先,我们需要创建一个新的Spring Boot项目,并添加必要的依赖项。以下是Maven pom.xml配置文件的内容:
          <!--graphql--><dependency><groupId>com.graphql-java-kickstart</groupId><artifactId>graphql-spring-boot-starter</artifactId><version>11.0.0</version></dependency><dependency><groupId>com.graphql-java-kickstart</groupId><artifactId>graphiql-spring-boot-starter</artifactId><version>11.0.0</version></dependency><!--mybatisPlus&mysql--><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><version>8.2.0</version></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.4.1</version></dependency>

1.2 配置MyBatis-Plus

  • 接下来,我们配置MyBatis-Plus来处理我们的数据访问层。首先,定义一个Person实体类:
package com.springboot.demo.domain;import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;/*** 用户表** @author water* @version 1.0.0* @date 2024-12-04 17:45*/
@Data
@TableName("demo_person")
public class Person {private Long id;private String name;private int age;}
  • 然后,创建对应的Mapper接口:
package com.springboot.demo.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.springboot.demo.domain.Person;/*** @author water* @version 1.0.0* @date 2024-12-05 08:11*/
public interface PersonMapper extends BaseMapper<Person> {
}
  • 最后,在Spring Boot主类上启用MyBatis-Plus扫描器:
package com.springboot.demo;import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;/*** springboot -demo** @Author: water* @Date: 2024/12/4 18:09* @Version : 1.0.0*/
@SpringBootApplication
@MapperScan("com.springboot.demo.mapper")
@EnableDiscoveryClient
@EnableFeignClients
public class SpringbootDemoApp {public static void main(String[] args) {SpringApplication.run(SpringbootDemoApp.class, args);}}
  • 同时,配置application.yml文件来设置数据库连接信息:
spring:profiles:active: clouddatasource:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://127.0.0.1:3306/spring-dmeo?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=falseusername: demopassword: Spring@demo24hikari:maximum-pool-size: 10minimum-idle: 1idle-timeout: 30000max-lifetime: 1800000transaction:default-timeout: 30graphql:graphiql:enabled: true#mybatis-plus
mybatis-plus:mapper-locations: classpath:mapper/*.xmltype-aliases-package: com.springboot.demo.**.domainconfiguration:map-underscore-to-camel-case: true# 默认日志输出: org.apache.ibatis.logging.slf4j.Slf4jImpl# 更详细的日志输出 会有性能损耗: org.apache.ibatis.logging.stdout.StdOutImpllog-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl #关闭日志记录 (可单纯使用 p6spy 分析)cache-enabled: falseauto-mapping-behavior: fullglobal-config:banner: falsedb-config:id-type: assign_id# 默认1删除logic-delete-value: 1# 正常0logic-not-delete-value: 0
#  日志
logging:level:com:example: debugorg:springframework:security: debugsecurity.access: debugsecurity.web: debugsecurity.web.access: debugweb: debugmanagement:endpoints:web:exposure:include: health,info

2、集成GraphQL

2.1 定义schema.graphqls

接下来,我们集成GraphQL以暴露API供客户端查询使用。首先,创建一个GraphQL schema文件schema.graphqls:
# src/main/resources/schema.graphqls
type Query {users: [Person]personById(id: ID!): Person
}type Mutation {addUser(name: String!, age: Int!): PersonupdateUser(id: ID!, name: String, age: Int): PersondeleteUser(id: ID!): Boolean
}type Person {id: ID!name: String!age: Int!
}

2.2 添加GraphQL解析器

  • 然后,为这些GraphQL查询和变更创建解析器:
package com.springboot.demo.resolver;import com.springboot.demo.domain.Person;
import com.springboot.demo.mapper.PersonMapper;
import graphql.kickstart.tools.GraphQLMutationResolver;
import graphql.kickstart.tools.GraphQLQueryResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;import java.util.List;/*** GraphQL 查询创建解析器。** @author water* @version 1.0.0* @date 2024-12-05 11:29*/
@Component
public class UserQuery implements GraphQLQueryResolver, GraphQLMutationResolver {@Autowiredprivate PersonMapper personMapper;public List<Person> users() {return personMapper.selectList(null);}public Person personById(String id) {personMapper.selectById(id);return personMapper.selectById(id);}public Person addUser(String name, int age) {Person user = new Person();user.setName(name);user.setAge(age);personMapper.insert(user);return user;}public Person updateUser(Long id, String name, Integer age) {Person user = personMapper.selectById(id);if (user != null) {if (name != null) {user.setName(name);}if (age != null) {user.setAge(age);}personMapper.updateById(user);}return user;}public boolean deleteUser(Long id) {return personMapper.deleteById(id) > 0;}}

2.3 配置schame文件配置

  • 最后,配置GraphQL工具包以加载schema文件和其他相关配置:
package com.springboot.demo.config;import graphql.schema.idl.SchemaParser;
import graphql.schema.idl.TypeDefinitionRegistry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;/*** @author water* @version 1.0.0* @date 2024-12-05 14:30*/
@Configuration
public class GraphQLConfig {@Beanpublic Resource graphQLSchemaFile() {return new ClassPathResource("schema.graphqls");}@Beanpublic TypeDefinitionRegistry typeDefinitionRegistry(Resource resource) throws Exception {SchemaParser parser = new SchemaParser();return parser.parse(resource.getInputStream());}
}

至此,我们就完成了一个整合了Spring Cloud、MyBatis-Plus和GraphQL的简单示例项目的搭建。 您可以启动应用程序并在浏览器中访问http://localhost:8080/graphiql来测试GraphQL API。
在这里插入图片描述

3、访问测试

  • 测试请求的脚本
# Welcome to GraphiQL
#
# GraphiQL is an in-browser tool for writing, validating, and
# testing GraphQL queries.
#
# Type queries into this side of the screen, and you will see intelligent
# typeaheads aware of the current GraphQL type schema and live syntax and
# validation errors highlighted within the text.
#
# GraphQL queries typically start with a "{" character. Lines that start
# with a # are ignored.
#
# An example GraphQL query might look like:
#
#     {
#       field(arg: "value") {
#         subField
#       }
#     }
#
# Keyboard shortcuts:
#
#  Prettify Query:  Shift-Ctrl-P (or press the prettify button above)
#
#     Merge Query:  Shift-Ctrl-M (or press the merge button above)
#
#       Run Query:  Ctrl-Enter (or press the play button above)
#
#   Auto Complete:  Ctrl-Space (or just start typing)
#
query select {personById(id:"1"){idnameage}}
query selectList {users{idnameage}}
mutation addUser{addUser(name:"王麻子", age:22){idnameage}
}mutation updateUser{updateUser(id:1864582448746012673,name:"钢蛋", age:31){idnameage}
}mutation updateUserById{updateUser(id:1864569571339378690,name:"赵六六"){idname}
}mutation deleteUser{deleteUser(id:1864582448746012673)
}

3.1 查询测试(演示)

  • 根据Id查询
    在这里插入图片描述
  • 查询所有
    在这里插入图片描述

3.2 添加测试(演示)

在这里插入图片描述

3.3 修改测试(演示)

在这里插入图片描述

3.4 删除测试(演示)

在这里插入图片描述

http://www.ho-use.cn/article/557.html

相关文章:

  • 效益成本原则网站建设/今日桂林头条新闻
  • 制作公司网站视频/seo全国最好的公司
  • 荆门网站建设公司/智谋网站优化公司
  • 帝国cms怎么做网站地图/适合小学生摘抄的新闻2022年
  • 做外贸网站需要注意些什么手续/搜索引擎优化网页
  • 怎么做网站弹幕/市场运营和市场营销的区别
  • 苏州网站建设制作管理培训
  • 做海报的软件/安徽新站优化
  • asp网站栏目修改/优化服务公司
  • 华为云建站怎么样/免费推广广告链接
  • 综合门户网站什么意思/广东seo网站优化公司
  • 网站开发毕业设计书/seo搜索引擎工具
  • 如何用ftp做网站/网页在线客服免费版
  • 网站制作的电话/登封网络推广公司
  • 宿迁网站建设价位/百度一下首页官网百度
  • 做农产品的网站名称/软件外包公司排行榜
  • 自己怎么做短视频网站/互联网营销模式有哪些
  • 注册了域名后怎么设计网站/弹窗广告最多的网站
  • 自己做的小网站分享/新闻头条新闻
  • 简单网站建设流程图/18种最有效推广的方式
  • 网站app服务器租用/优化手机流畅度的软件
  • 化妆品应如何网站建设定位/如何去做网络营销
  • 马鞍山哪里做网站/企业关键词大全
  • 常州市建设工程质量监督站网站/优化排名工具
  • 著名建筑设计作品解析/牛排seo
  • 做网站IP/想学销售去哪培训
  • 在什么网站做公司人员增减/百度推广的步骤
  • 专门做辅助的网站/保定百度seo排名
  • 媒体网站推广方法/百度提交入口网址是什么
  • 公司网站制作公司倒闭/软文推广的100个范例