如何使用MySQL和JPA使用Spring Boot構建Rest API

Hi Everyone! For the past year, I have been learning JavaScript for full-stack web development. For a change, I started to master Java — the powerful Object Oriented Language.

嗨,大家好! 在過去的一年中,我一直在學習用于全棧Web開發JavaScript。 為了進行更改,我開始學習Java —功能強大的面向對象語言。

In that case, I found a very clean and elegant framework called Spring Boot to build a back end.

在那種情況下,我發現了一個非常干凈優雅的框架,稱為Spring Boot,用于構建后端。

Previously, in JavaScript development, I used:

以前,在JavaScript開發中,我使用了:

  1. Mongoose — an ORM (Object Relational Mapping) for Mongo DB

    貓鼬-Mongo DB的ORM(對象關系映射)
  2. Sequelize — an ORM for MySQL

    Sequelize — MySQL的ORM

For Java-related development, there are lot of ORM’s like Hibernate, JPA (Java Persistence API) & Java Object Oriented Querying.

對于Java相關的開發,有很多ORM,例如Hibernate,JPA (Java持久性API)和Java面向對象的查詢。

I choose to build with JPA which is traditionally used in Java applications.

我選擇使用傳統上在Java應用程序中使用的JPA進行構建。

It was very interesting, and took about one week to finish as I had to learn Spring Boot (There are a lot of annotations “@” and other cool kinds of stuff to learn), JPA, and Hibernate along the way.

這非常有趣,大約花了一個星期的時間,因為我必須學習Spring Boot(有很多注釋“ @ ”和其他很酷的東西要學習),JPA和Hibernate。

All this magic is mostly done by the annotations (“@” symbol) used in Spring Boot.

所有這些魔術主要是由Spring Boot中使用的注釋 (“ @ ”符號)完成的。

創建一個Spring Boot Maven項目 (Creating a Spring Boot Maven Project)

Let’s create a Spring Boot Maven Project Application using this link.

讓我們使用此鏈接創建一個Spring Boot Maven項目應用程序。

Maven” is a project management tool used to manage dependency management. It’s just like Node Package Manager (NPM) in the JS development environment.

Maven ”是用于管理依賴項管理的項目管理工具。 就像JS開發環境中的Node Package Manager( NPM )一樣。

We have package.json in NodeJS for dependency management and pom.xml in Spring Boot for dependency management.

在NodeJS中package.json用于依賴關系管理, 在Spring Boot中有pom.xml用于依賴關系管理。

In Group, write whatever the name you want. Usually, the domain name of the organization is written right to left.

在“組”中,寫下您想要的任何名稱。 通常,組織的域名是從右到左寫的。

For example our domain name is www.javaAPI.com, so the group name could be com.javaAPI.www

例如,我們的域名是www.javaAPI.com ,因此組名稱可以是com.javaAPI.www。

Then in the Artifact type the name of the folder you want.

然后在Artifact中輸入所需文件夾名稱

On the right side, add the following dependencies:

在右側,添加以下依賴項:

  1. WEB — To use the dependencies of Spring (The older framework of Spring Boot used to develop web applications)

    WEB —使用Spring的依賴項(用于開發Web應用程序的Spring Boot的舊框架)
  2. JPA — Java Persistence API

    JPA — Java持久性API
  3. MYSQL

    MySQL數據庫

Then click “Generate Project”. You will find a rar file — extract it. Then open that folder in your favorite IDE.

然后單擊“生成項目”。 您會找到一個rar文件-將其解壓縮。 然后在您喜歡的IDE中打開該文件夾。

Click on the com.rest.API and you will find an ApiApplication.java file as follows:

單擊com.rest.API ,您將找到一個ApiApplication.java文件,如下所示:

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

This code is enough to start your server. Normally spring boot runs on localhost:8080.

此代碼足以啟動您的服務器。 通常,Spring Boot在localhost:8080上運行。

Type in your terminal as follows:

在終端中輸入以下內容:

mvn spring-boot:run

mvn spring-boot:運行

See your localhost running in the web browser at port 8080. It looks blank as we haven’t done anything yet.

請查看運行在Web瀏覽器端口8080上的本地主機。由于我們尚未執行任何操作,因此它看起來空白。

讓我們探索文件及其標簽 (Let’s explore the files and their tags)

If you have a look at the pom.xml file you may notice that the dependencies you put in when creating the application in Spring Initialize like MySQL, JPA, and Web will be inside a <dependency> tag.

如果查看pom.xml文件,您可能會注意到在Spring Initialize中創建應用程序時放入的依賴項(如MySQL,JPA和Web)將位于<dependen cy>標記內。

The starter and tester dependencies are the core for creating the Spring Boot Application to serve on the server.

啟動程序和測試程序依賴性是創建在服務器上服務的Spring Boot Application的核心。

Now, let’s move to APIApplication.java which is the main file.

現在,讓我們轉到主文件APIApplication.java。

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

Here the name of the package is in the first line of the code. Using that package name, you can import any class, method, or instances in another package file.

包的名稱在代碼的第一行。 使用該程序包名稱,可以將任何類,方法或實例導入另一個程序包文件中。

After that, two modules are imported from “org.springframework.boot” package.

之后,從“ org.springframework.boot”包中導入兩個模塊。

  1. SpringApplication

    Spring應用
  2. SpringBootApplication

    SpringBoot應用程序

Since Spring boot is the latest application developing framework of Spring, it needs the packages of Spring Application as well as its specific packages.

由于Spring Boot是Spring的最新應用程序開發框架,因此它需要Spring Application的軟件包及其特定的軟件包。

After that @SpringBootApplication Annotation is used. This Annotation consists of annotation which is used in Spring:

之后,使用@SpringBootApplication Annotation。 該注釋包含在Spring中使用的注釋:

  1. @Component — Tells the compiler that the following class is a component which should be included when compiling the whole application.

    @Component —告訴編譯器以下類是在編譯整個應用程序時應包括的組件。

  2. @ComponentScan — This one does the Scan of which packages we are going to use in the following Java class.

    @ComponentScan —這將掃描以下Java類中要使用的軟件包。

  3. @EnableAutoConfiguration — enables Spring Boot’s autoconfiguration mechanism to import important modules for the Spring Boot to run.

    @EnableAutoConfiguration-使Spring Boot的自動配置機制能夠導入重要模塊以供Spring Boot運行。

These are the annotations used to start the Spring Boot Application to run on a server.

這些是用于啟動Spring Boot Application以便在服務器上運行的注釋。

Here is an article I have written about Annotation & their uses in Java.

這是我寫的有關注解及其在Java中的用法的文章。

讓我們為數據創建模型 (Let’s create Model for our data)

Let’s create a Model class to save, retrieve, update and delete the details of a book.

讓我們創建一個Model類來保存,檢索,更新和刪除書籍的詳細信息。

For that, I have to create a new package named model and inside that creating a Book.java class to put my code.

為此,我必須創建一個名為model的新程序包,并在其中創建一個Book.java類來放置我的代碼。

package com.rest.API.model;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
@Entity
@Table(name = "books")
public class Book {@Id@GeneratedValueprivate Long id;
@NotBlankprivate String book_name;
@NotBlankprivate String author_name;
@NotBlankprivate String isbn;
public Book(){super();}
public Book(Long id, String book_name, String author_name, String isbn) {super();this.id = id;this.book_name = book_name;this.author_name = author_name;this.isbn=isbn;}
public Long getId() {return id;}
public void setId(Long id) {this.id = id;}
public String getBook_name() {return book_name;}
public void setBook_name(String book_name) {this.book_name = book_name;}
public String getAuthor_name() {return author_name;}
public void setAuthor_name(String author_name) {this.author_name = author_name;}
public String getIsbn() {return isbn;}
public void setIsbn(String isbn) {this.isbn = isbn;}
}

Here I’m using JPA (Java Persistence API) which is a collection of classes and methods to continuously store data into a database.

在這里,我使用的是JPA(Java持久性API),它是用于將數據連續存儲到數據庫中的類和方法的集合。

@Entity — used to denote that this class is going to be an Entity in the database.

@Entity —用來表示該類將成為數據庫中的一個Entity。

@Table — which takes some values like the name you are going to name your table

@Table —它帶有一些值,例如您要為表命名的名稱

@Id — denotes that the id is the primary key / identifying key for this table

@Id —表示id是此表的主鍵/標識鍵

@NotBlank — is used to say that these attributes should not be blank.

@NotBlank-用來表示這些屬性不應為空。

Other than that there is an empty constructor which has a super method to satisfy the JPA customs. Getter and setter methods are usually in a POJO class (Plain old Java object).

除此之外,還有一個空的構造函數,該構造函數具有滿足JPA習慣的超級方法。 Getter和setter方法通常在POJO類( 普通的舊Java對象 )中。

創建存儲庫 (Creating the Repository)

Next, we are going to create a repository package to deal with database management in Java.

接下來,我們將創建一個存儲庫包來處理Java中的數據庫管理。

Create an Interface called BookRepository.java inside the repository package.

存儲庫包中創建一個名為BookRepository.java的接口。

package com.rest.API.repository;
import com.rest.API.model.Book;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface BookRepository extends JpaRepository<Book, Long> {
}

I have imported the JpaRepository package to use that repository in the BookRepository interface by connecting my most recently coded Book model to do CRUD operations.

我已導入JpaRepository包,以通過連接我最近編碼的Book模型進行CRUD操作來在BookRepository界面中使用該存儲庫。

There are already built-in methods in those repositories to do CRUD operations.

這些存儲庫中已經有內置方法可以執行CRUD操作。

Eg:

例如:

.findAll() - to get All datas
.save()    - to save the got Data
.delete()  - to delete the data

Inside the <> tag we are taking the Model name we are going to use and the Primary key’s datatype.

在<>標記內,我們將使用將要使用的Model名稱和主鍵的數據類型。

@Repository: Annotation used to Indicate the DAO (Data Access Object) component in the persistence layer.

@Repository :用于指示持久層中的DAO( 數據訪問對象 )組件的注釋。

It tells the compiler that the interface is going to use the Repository to do database activities.

它告訴編譯器該接口將使用存儲庫來執行數據庫活動。

創建控制器和異常處理 (Creating Controller and Exception Handling)

Create a new package called controller, and inside that create a BookController.java file which contains the endpoints.

創建一個名為controller的新程序包 在其中創建一個包含端點的BookController.java文件。

package com.rest.API.controller;import com.rest.API.exception.BookNotFoundException;
import com.rest.API.model.Book;
import com.rest.API.repository.BookRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.ResponseEntity;
import javax.validation.Valid;
import java.util.List;@RestController
public class BookController {@AutowiredBookRepository bookRepository;// Get All Notes@GetMapping("/books")public List<Book> getAllNotes() {return bookRepository.findAll();}// Create a new Note@PostMapping("/books")public Book createNote(@Valid @RequestBody Book book) {return bookRepository.save(book);}// Get a Single Note@GetMapping("/books/{id}")public Book getNoteById(@PathVariable(value = "id") Long bookId) throws BookNotFoundException {return bookRepository.findById(bookId).orElseThrow(() -> new BookNotFoundException(bookId));}// Update a Note@PutMapping("/books/{id}")public Book updateNote(@PathVariable(value = "id") Long bookId,@Valid @RequestBody Book bookDetails) throws BookNotFoundException {Book book = bookRepository.findById(bookId).orElseThrow(() -> new BookNotFoundException(bookId));book.setBook_name(bookDetails.getBook_name());book.setAuthor_name(bookDetails.getAuthor_name());book.setIsbn(bookDetails.getIsbn());Book updatedBook = bookRepository.save(book);return updatedBook;}// Delete a Note@DeleteMapping("/books/{id}")public ResponseEntity<?> deleteBook(@PathVariable(value = "id") Long bookId) throws BookNotFoundException {Book book = bookRepository.findById(bookId).orElseThrow(() -> new BookNotFoundException(bookId));bookRepository.delete(book);return ResponseEntity.ok().build();}
}

The first imported package is for the Book Not Found exception (for which we are going to create a file in a bit).

第一個導入的程序包用于“找不到書”異常(我們將稍后為其創建文件)。

Explanation of Annotations we used here:

我們在此處使用的注釋說明:

  1. RestController: This annotation is used to denote every method in the annotated class as Domain Object.

    RestController:此注釋用于將帶注釋的類中的每個方法表示為Domain Object。

So what is Domain Object…?

那么什么是域對象……?

It simply says that Domain Object == Business Object.

它只是說域對象==業務對象。

They are usually represented by entities and value objects related to the endpoint we are giving to get the data from the database.

它們通常由與我們要從數據庫獲取數據的端點相關的實體和值對象表示。

2. Autowired: This annotation is used to wire the bean classes automatically.

2. Autowired :此注釋用于自動連接Bean類。

For that, you need to know about “What is a bean Class..?

為此,您需要了解“ 什么是bean類..?

Basically, a Java Bean Class is a simple class which encapsulates many objects into it.

基本上,Java Bean類是一個簡單的類,它將許多對象封裝到其中。

This is an article I wrote on Java Bean Classes.

這是我寫的關于Java Bean類的文章。

The following are the Mapping Annotations for the endpoints to perform CRUD Operations.

以下是端點執行CRUD操作的映射注釋。

3. GetMapping: This is an interface which contains the path of the endpoint to perform a Get method. This GetMapping interface uses the RequestMapping interface which can have the “path, value, params, headers” method to perform the Get method in earlier Spring versions.

3. GetMapping:這是一個接口 ,其中包含執行Get方法的端點的路徑。 此GetMapping接口使用RequestMapping接口,該接口可以具有“路徑,值,參數,標頭”方法,以在早期的Spring版本中執行Get方法。

Now it’s simplified by using GetMapping.

現在,使用GetMapping對其進行了簡化

4. PostMapping: This is an interface which contains the path of the endpoint to perform the Post method.

4. PostMapping :這是一個接口 ,其中包含執行Post方法的端點的路徑。

5. PutMapping: This is an interface which contains the path of the endpoint to perform the Put method to Update.

5. PutMapping:這是一個接口 ,其中包含執行Put方法更新的端點的路徑。

6. DeleteMapping: This is an interface which contains the path of the endpoint to perform the Delete method.

6. DeleteMapping:這是一個接口 ,其中包含執行Delete方法的端點的路徑。

In the final lines, you probably noticed the “ResponseEntity” keyword.

在最后幾行中,您可能會注意到“ ResponseEntity ”關鍵字。

What is that…??

是什么...?

It’s a Java class which inherits HttpEntity class to manipulate the HTTP Responses. Whether the request of the connection is “OK” or if there are any problems, throw an exception from the HttpEntity class.

這是一個Java類,繼承了HttpEntity類來操縱HTTP響應。 無論連接請求是“ OK ”還是存在任何問題,請從HttpEntity類引發異常

orElseThrow(): This is a method found in the Optional class in Java8 which was introduced to handle Exceptions. The optional class provides various utility methods to check the presence or absence of an object, which helps to deal with NullPointerException.

orElseThrow():這是在Java8Optional類中找到的一種方法,該方法被引入來處理異常。 可選類提供了各種實用程序方法來檢查對象的存在或不存在,這有助于處理NullPointerException。

orElseThrow is a method that Returns value if present, otherwise invokes an exception.

orElseThrow是一種返回值(如果存在)的方法,否則調用異常。

如果沒有這樣的book_id,則創建一個NotFoundException (Creating a NotFoundException if there is no such book_id)

As orElseThrow method throws a NotFound Exception. The following is the Exception Handling part. Create a BookNotFoundException.java file inside exception package.

由于orElseThrow方法引發NotFound異常。 以下是異常處理部分。 在異常包中創建一個BookNotFoundException.java文件。

package com.rest.API.exception;
public class BookNotFoundException extends Exception {
private long book_id;
public BookNotFoundException(long book_id) {super(String.format("Book is not found with id : '%s'", book_id));}
}

The created class extends the Superclass of Exception. In the constructor, I’m passing the book_id & prints the exception.

創建的類擴展了Exception的超類。 在構造函數中,我傳遞了book_id并打印異常。

So, that’s it…

就是這樣了…

We have finished the REST API part. Now you can build the app (which was explained in Part 1) and do some Testings with Postman.

我們已經完成了REST API部分。 現在,您可以構建應用程序(在第1部分中進行了說明),并使用Postman進行一些測試。

與MySql數據庫連接 (Connecting with MySql Database)

Inside the application.properties of your resources folder, add the following:

資源文件夾的application.properties中,添加以下內容:

## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.url = jdbc:mysql://localhost:3306/library
spring.datasource.username = root //normally put your MySQL username 
spring.datasource.password = YOUR_MYSQL_PASSWORD
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = update

That’s it.

而已。

We have built a basic REST API in Spring Boot. Congrats!

我們在Spring Boot中構建了一個基本的REST API。 恭喜!

If anything is wrong or need to be corrected, please let me know in the comments section.

如果有任何錯誤或需要更正,請在評論部分讓我知道。

Get in touch with me on twitter.

在Twitter上與我聯系。

Happy Coding!

編碼愉快!

翻譯自: https://www.freecodecamp.org/news/how-to-build-a-rest-api-with-spring-boot-using-mysql-and-jpa-f931e348734b/

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/392149.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/392149.shtml
英文地址,請注明出處:http://en.pswp.cn/news/392149.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

翻譯

令 $m>n>1$ 為正整數. 一個集合含有 $m$ 個給定的實數. 我們從中選取任意 $n$ 個數, 記作 $a_1$, $a_2$, $\dotsc$, $a_n$, 并提問: 是否 $a_1<a_2<\dotsb < a_n$ 正確? 證明: 我們可以最多問 $n!-n^22n-2m(n-1)(1\lfloor \log_{n} m \rfloor)-m$ 個問題&#…

720 智能硬件與 LeanCloud 云端的默契協作

【 玩轉 LeanCloud 】開發者經驗分享&#xff1a; 作者&#xff1a;謝子超 720技術負責人&#xff0c;從業十余年&#xff0c;一直負責軟件開發工作。 我們的產品是與監控和改善室內空氣質量相關的智能硬件&#xff0c;我們使用 LeanCloud 平臺已經有 2 年多了&#xff0c;借此…

linux cifs windows 慢,windows上使用dockerIO特別慢有沒有更優的解決方案?

復制一個大佬的回答Docker for Windows是在Hyper-V虛擬機上跑Linux&#xff0c;文件掛載是通過SMB協議從Windows掛載到Linux&#xff0c;文件讀寫都經過網絡&#xff0c;遇到Laravel這種每次啟動就要加載幾百個文件的框架&#xff0c;文件性能問題就尤其明顯。最好的驗證方法就…

編譯原理—詞法分析器(Java)

1.當運行程序時&#xff0c;程序會讀取項目下的program.txt文件 2. 程序將會逐行讀取program.txt中的源程序&#xff0c;進行詞法分析&#xff0c;并將分析的結果輸出。 3. 如果發現錯誤&#xff0c;程序將會中止讀取文件進行分析&#xff0c;并輸出錯誤提示 所用單詞的構詞規…

【BZOJ4653】[Noi2016]區間 雙指針法+線段樹

【BZOJ4653】[Noi2016]區間 Description 在數軸上有 n個閉區間 [l1,r1],[l2,r2],...,[ln,rn]。現在要從中選出 m 個區間&#xff0c;使得這 m個區間共同包含至少一個位置。換句話說&#xff0c;就是使得存在一個 x&#xff0c;使得對于每一個被選中的區間 [li,ri]&#xff0c;都…

為什么我們需要使用Pandas新字符串Dtype代替文本數據對象

We have to represent every bit of data in numerical values to be processed and analyzed by machine learning and deep learning models. However, strings do not usually come in a nice and clean format and require a lot preprocessing.我們必須以數值表示數據的每…

遞歸方程組解的漸進階的求法——代入法

遞歸方程組解的漸進階的求法——代入法 用這個辦法既可估計上界也可估計下界。如前面所指出&#xff0c;方法的關鍵步驟在于預先對解答作出推測&#xff0c;然后用數學歸納法證明推測的正確性。 例如&#xff0c;我們要估計T(n)的上界&#xff0c;T(n)滿足遞歸方程&#xff1a;…

【轉載】C# 理解泛型

術語表 generics&#xff1a;泛型type-safe&#xff1a;類型安全collection: 集合compiler&#xff1a;編譯器run time&#xff1a;程序運行時object: 對象.NET library&#xff1a;.Net類庫value type: 值類型box: 裝箱unbox: 拆箱implicity: 隱式explicity: 顯式linked list:…

javascript 作用_JavaScript承諾如何從內到外真正發揮作用

javascript 作用One of the most important questions I faced in interviews was how promises are implemented. Since async/await is becoming more popular, you need to understand promises.我在采訪中面臨的最重要的問題之一是如何實現承諾。 由于異步/等待變得越來越流…

linux 文件理解,對linux中文件系統的理解

首先在linux系統當中一個可被掛在的數據為一個文件系統1.在安裝linux過程中我們要進行磁盤分區&#xff0c;可以分根目錄/,‘/home‘&#xff0c;‘/boot’,swap等等這些分區&#xff0c;每一個分區(’/(根目錄)‘&#xff0c;’/home‘...)就是一個文件系統。2.文件系統分配完…

編譯原理—語法分析器(Java)

遞歸下降語法分析 1. 語法成分說明 <語句塊> :: begin<語句串> end <語句串> :: <語句>{&#xff1b;<語句>} <語句> :: <賦值語句> | <循環語句> | <條件語句> <關系運算符> :: < | < | > | > | |…

老筆記整理四:字符串的完美度

今天在寵果網上發現一道題目&#xff0c;求一個字符串的完美度http://hero.pongo.cn/home/index覺得這道題很有趣就挑戰了一下&#xff0c;結果沒有在規定的1小時里面寫完&#xff08;笑&#xff09;&#xff0c;多花了10分鐘終于做出來了。題目是這樣的&#xff1a;我們要給每…

nlp構建_使用NLP構建自殺性推文分類器

nlp構建Over the years, suicide has been one of the major causes of death worldwide, According to Wikipedia, Suicide resulted in 828,000 global deaths in 2015, an increase from 712,000 deaths in 1990. This makes suicide the 10th leading cause of death world…

域名跳轉

案例&#xff1a;當訪問lsx.com網站&#xff0c;是我最早論壇的域名。回車之后會自動跳轉到lshx.com。 為什么藥lsx跳轉到lshx.com呢&#xff1f; 為了統一品牌。建議換成了lshx.com。所有之前的lsx.com就不要用了&#xff0c;就讓它跳轉到lshx.com。是因為之前lsx.com上有很多…

Elastic Stack 安裝

Elastic Stack 是一套支持數據采集、存儲、分析、并可視化全面的分析工具&#xff0c;簡稱 ELK&#xff08;Elasticsearch&#xff0c;Logstash&#xff0c;Kibana&#xff09;的縮寫。 安裝Elastic Stack 時&#xff0c;必須相關組件使用相同的版本&#xff0c;例如&#xff1…

區塊鏈去中心化分布式_為什么漸進式去中心化是區塊鏈的最大希望

區塊鏈去中心化分布式by Arthur Camara通過亞瑟卡馬拉(Arthur Camara) 為什么漸進式去中心化是區塊鏈的最大希望 (Why Progressive Decentralization is blockchain’s best hope) 不變性是區塊鏈的最大優勢和最大障礙。 逐步分權可能是答案。 (Immutability is blockchain’s…

編譯原理—語義分析(Java)

遞歸下降語法制導翻譯 實現含多條簡單賦值語句的簡化語言的語義分析和中間代碼生成。 測試樣例 begin a:2; b:4; c:c-1; area:3.14*a*a; s:2*3.1416*r*(hr); end #詞法分析 public class analyzer {public static List<String> llistnew ArrayList<>();static …

linux問題總結

linux問題總結 編寫后臺進程的管理腳本&#xff0c;使用service deamon-name stop的時候&#xff0c;出現如下提示&#xff1a;/sbin/service: line 66: 23299 Terminated env -i LANG"$LANG" PATH"$PATH" TERM"$TERM" "${SERVICEDIR}/${SE…

linux vi行尾總是顯示顏色,【轉載】Linux 下使用 vi 沒有顏色的解決辦法

vi 是沒有顏色的&#xff0c;vim 是有顏色的。我們可以通過 rpm -qa |grep vim 看看系統中是否安裝了下面 3 個 rpm 包&#xff0c;如果有就是安裝了 vim 。[rootBetty ~]# rpm -qa |grep vimvim-minimal-7.0.109-7.el5vim-enhanced-7.0.109-7.el5vim-common-7.0.109-7.el5如果…

時間序列分析 lstm_LSTM —時間序列分析

時間序列分析 lstmNeural networks can be a hard concept to wrap your head around. I think this is mostly due to the fact that they can be used for so many different things such as classification, identification or just simply regression.神經網絡可能是一個難…