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

做网站的新闻sem工资

做网站的新闻,sem工资,苏州做网站企业,网站策划案45001 安装插件 我这边使用的是IDEA,需要先按照Graphql插件,步骤如下: (1)打开插件管理 在IDEA中,打开主菜单,选择 "File" -> "Settings" (或者使用快捷键 Ctrl Alt S …

1 安装插件

我这边使用的是IDEA,需要先按照Graphql插件,步骤如下:

(1)打开插件管理

在IDEA中,打开主菜单,选择 "File" -> "Settings" (或者使用快捷键 Ctrl + Alt + S 或 Cmd + ,),然后在弹出的对话框中选择 "Plugins"。

(2)搜索GraphQL插件

在插件管理器中,你会看到一个搜索框。在搜索框中输入 "GraphQL" 或者其他相关的关键词,然后按下回车键或者点击搜索图标。

(3)安装插件

(4)重启IDEA

安装完成以后重启IDEA

2 新建数据库

脚本如下:


CREATE DATABASE IF NOT EXISTS `BOOK_API_DATA`;
USE `BOOK_API_DATA`;CREATE TABLE IF NOT EXISTS `Book` (`id` int(20) NOT NULL AUTO_INCREMENT,`name` varchar(255) DEFAULT NULL,`pageCount` varchar(255) DEFAULT NULL,PRIMARY KEY (`id`),UNIQUE KEY `Index_name` (`name`)) ENGINE=InnoDB AUTO_INCREMENT=235 DEFAULT CHARSET=utf8;CREATE TABLE `Author` (`id` INT(20) NOT NULL AUTO_INCREMENT,`firstName` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8_general_ci',`lastName` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8_general_ci',`bookId` INT(20) NULL DEFAULT NULL,PRIMARY KEY (`id`) USING BTREE,UNIQUE INDEX `Index_name` (`firstName`) USING BTREE,INDEX `FK_Author_Book` (`bookId`) USING BTREE,CONSTRAINT `FK_Author_Book` FOREIGN KEY (`bookId`) REFERENCES `BOOK_API_DATA`.`Book` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
)COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=6
;INSERT INTO `Book` (`id`, `name`, `pageCount`) VALUES (1, 'the golden ticket', '255');
INSERT INTO `Book` (`id`, `name`, `pageCount`) VALUES (2, 'coding game', '300');INSERT INTO `Author` (`id`, `firstName`, `LastName`, `bookId`) VALUES (4, 'Brendon', 'Bouchard', 1);
INSERT INTO `Author` (`id`, `firstName`, `LastName`, `bookId`) VALUES (5, 'John', 'Doe', 2);

3 代码实现

下面实现一个简单的查询

3.1 引入依赖

        <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-graphql</artifactId><version>3.3.0</version></dependency>

完整pom文件如下:

<?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"><modelVersion>4.0.0</modelVersion><groupId>org.example</groupId><artifactId>springbootgraphql</artifactId><version>1.0-SNAPSHOT</version><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.5</version><relativePath /></parent><properties><java.version>1.8</java.version>
<!--        <kotlin.version>1.1.16</kotlin.version>--></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-graphql</artifactId><version>3.3.0</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId></exclusion></exclusions></dependency><dependency><groupId>com.google.guava</groupId><artifactId>guava</artifactId><version>26.0-jre</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><excludes><exclude><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></exclude></excludes></configuration></plugin></plugins></build></project>

3.2 新建实体类

新建Author实体类

package com.example.demo.model;import javax.persistence.*;@Entity
@Table(name = "Author", schema = "BOOK_API_DATA")
public class Author {@Id@GeneratedValue(strategy = GenerationType.AUTO)Integer id;@Column(name = "firstname")String firstName;@Column(name = "lastname")String lastName;@Column(name = "bookid")Integer bookId;public Author(Integer id, String firstName, String lastName, Integer bookId) {this.id = id;this.firstName = firstName;this.lastName = lastName;this.bookId = bookId;}public Author() {}public Integer getId() {return id;}public String getFirstName() {return firstName;}public String getLastName() {return lastName;}public void setId(Integer id) {this.id = id;}public void setFirstName(String firstName) {this.firstName = firstName;}public void setLastName(String lastName) {this.lastName = lastName;}public Integer getBookId() {return bookId;}public void setBookId(Integer bookId) {this.bookId = bookId;}
}

新建Book实体类

package com.example.demo.model;import javax.persistence.*;@Entity
@Table(name = "Book", schema = "BOOK_API_DATA")
public class Book {@Id@GeneratedValue(strategy = GenerationType.AUTO)private Integer id;private String name;@Column(name = "pagecount")private String pageCount;public Book(Integer id, String name, String pageCount) {this.id = id;this.name = name;this.pageCount = pageCount;}public Book() {}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getPageCount() {return pageCount;}public void setPageCount(String pageCount) {this.pageCount = pageCount;}
}

新建输入AuthorInput实体

package com.example.demo.model.Input;public class AuthorInput {String firstName;String lastName;Integer bookId;public String getFirstName() {return firstName;}public String getLastName() {return lastName;}public void setFirstName(String firstName) {this.firstName = firstName;}public void setLastName(String lastName) {this.lastName = lastName;}public Integer getBookId() {return bookId;}public void setBookId(Integer bookId) {this.bookId = bookId;}
}

3.3 新建repository类

新建AuthorRepository类

package com.example.demo.repository;import com.example.demo.model.Author;
import org.springframework.data.repository.CrudRepository;public interface AuthorRepository extends CrudRepository<Author, Integer> {Author findAuthorByBookId(Integer bookId);
}

新建BookRepository类

package com.example.demo.repository;import com.example.demo.model.Book;
import org.springframework.data.repository.CrudRepository;public interface BookRepository extends CrudRepository<Book, Integer> {Book findBookByName(String name);
}

3.4 新建Service层

package com.example.demo.service;import com.example.demo.model.Author;
import com.example.demo.repository.AuthorRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service
public class AuthorSevice {@Autowiredprivate AuthorRepository authorRepository;public void addAuthon(Author author) {authorRepository.save(author);}public Author queryAuthorByBookId(int bookid) {Author author = authorRepository.findAuthorByBookId(bookid);return author;}}

3.5 新建控制器

package com.example.demo.controller;import com.example.demo.model.Author;
import com.example.demo.model.Input.AuthorInput;
import com.example.demo.service.AuthorSevice;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.graphql.data.method.annotation.Argument;
import org.springframework.graphql.data.method.annotation.MutationMapping;
import org.springframework.graphql.data.method.annotation.QueryMapping;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RestController;@CrossOrigin
@RestController
public class AuthorController {@Autowiredprivate AuthorSevice authorSevice;/*** 经典 hollo graphql*/@QueryMappingpublic String hello(){return "hello graphql";}@QueryMappingpublic Author getAuthorBybookId(@Argument int bookid) {System.out.println("bookid:"+bookid);return authorSevice.queryAuthorByBookId(bookid);}@MutationMappingpublic Author createUser(@Argument AuthorInput authorInput) {Author author = new Author();BeanUtils.copyProperties(authorInput,author);authorSevice.addAuthon(author);return author;}
}

3.6 新建graphql文件

在resource文件中新建graphql文件

编写root.graphql文件

schema {query: Querymutation: Mutation
}
type Mutation{
}
type Query{
}

编写books.graphql文件

extend type Query {hello:StringgetAuthorBybookId(bookid:Int): Author
}extend type Mutation {createUser(authorInput: AuthorInput):Author
}input AuthorInput {firstName: StringlastName: StringbookId: Int
}type Author {id: IntfirstName: StringlastName: StringbookId: Int
}type Book {id: Intname: StringpageCount: Stringauthor: Author
}

3.7 编写yml配置文件

spring:jpa:hibernate:use-new-id-generator-mappings: falsegraphql:graphiql:enabled: truewebsocket:path: /graphqlschema:printer:enabled: truelocations: classpath:/graphql   #test.graphql文件位置file-extensions: .graphqldatasource:url: jdbc:mysql://192.168.222.156:3306/book_api_data?useUnicode=true&characterEncoding=utf-8&useSSL=falsepassword: 123456username: root
server:port: 8088

3.8 编写启动类

package com.example.demo;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class graphqlApplication {public static void main(String[] args) {SpringApplication.run(graphqlApplication.class,args);}
}

4 启动测试

启动后访问http://localhost:8088/graphiql?path=/graphql&wsPath=/graphql

 测试查询功能

测试新增功能

http://www.khdw.cn/news/32268.html

相关文章:

  • 网站建设推广唯心磁遁8站内营销推广方案
  • 广州网站设计公司兴田德润在那里最佳搜索引擎磁力
  • 网站外包 多少钱如何做网站推广广告
  • 青岛日文网站制作搜索引擎谷歌入口
  • 做网站买房可靠吗英雄联盟世界排名
  • logo图案生成器seo教学网站
  • 诗词门户网站今日国际新闻头条15条简短
  • 做垃圾网站 盈利小程序开发一个多少钱啊
  • 沈阳旅游集团网站建设百度网盘官方
  • 网站基本流程班级优化大师app下载学生版
  • 帮黄色网站做推广烟台网站建设
  • 最好的设计师网站百度如何发布作品
  • 上海网站备案注销百度百科合作模式
  • 担保公司网站模板品牌运营中心
  • 公司做网站图片google chrome download
  • 建设企业网站官网企业百度广告推广费用一年多少钱
  • 淘宝二官方网站是做啥的平台推广费用
  • 网站提交搜索引擎深圳sem竞价托管
  • 网站设计潮流长春网站制作系统
  • 做个自己的影院网站怎么做长沙网站关键词排名
  • 何苦做游戏网站中国企业网官方网站
  • 那家公司做网站企业网站营销优缺点
  • 专门做会议的网站so导航 抖音
  • 现在哪个网站可以做外贸百度联盟项目看广告挣钱
  • 简述一个网站开发流程手机广告推广软件
  • 网站站外引流怎么做教育培训机构加盟十大排名
  • 网站优化 推广网络营销策划方案ppt模板
  • 江门网站建设定制百度搜索排名规则
  • 平台网站做数据维护需要多久网上永久视频会员是真的吗
  • 网站二级域名 权重 卢松松怎样才能被百度秒收录