예: Java + SpringBoot + Hibernate 및 IRIS 데이터베이스를 사용하여 REST API 생성
6590 단어 javabeginnersjavascripttutorial

참고: SpringBoot에 대해 알아보려면 공식 사이트https://spring.io/quickstart를 참조하십시오.
웹 API 애플리케이션을 생성하려면 하나 이상의 마이크로 서비스와 함께 Eclipse 또는 VSCode용 Spring IDE를 사용하고 마법사를 사용하여 앱에 사용될 위의 기술을 구성할 수 있습니다. 다음을 참조하세요.

기술을 선택하고 프로젝트를 만듭니다. 모든 기술은 maven을 사용하여 가져옵니다. 이것은 비주얼 zpm과 같습니다.
생성된 프로젝트에는 내부에 필요한 모든 것(웹 및 애플리케이션 서버, 모든 종속성, 마이크로 서비스 개념)을 포함하는 애플리케이션을 구성하는 클래스가 있습니다.
이 프로젝트의 전체 소스 코드는 공개 교환 프로젝트https://openexchange.intersystems.com/package/springboot-iris-crud에 있습니다.
가장 먼저 할 일은 IRIS JDBC 드라이버 및 IRIS Hibernate 지원을 구성하는 것입니다. 이렇게 하려면 jar 파일을 리소스 폴더에 복사합니다. 다음을 참조하세요.

pom.xml을 열어 이러한 jar 파일에 대한 종속성을 구성합니다. 다음을 참조하세요.
<dependency>
<groupId>com.intersystems</groupId>
<artifactId>intersystems-jdbc</artifactId>
<version>3.2.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/intersystems-jdbc-3.2.0.jar</systemPath>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-iris</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/hibernate-iris-1.0.0.jar</systemPath>
</dependency>이제 IRIS 데이터베이스와의 연결을 application.properties로 구성할 수 있습니다. 다음을 참조하십시오.
spring.datasource.username=_SYSTEM
spring.datasource.url=jdbc:IRIS://iris:1972/USER
spring.datasource.password=SYS
spring.jpa.properties.hibernate.default_schema=dc_Sample
#spring.jpa.hibernate.ddl-auto=update
spring.datasource.driver-class-name=com.intersystems.jdbc.IRISDriver
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
spring.jpa.database-platform=org.hibernate.dialect.InterSystemsIRISDialect
spring.datasource.sql-script-encoding=utf-8
server.tomcat.relaxed-query-chars=|,{,},[,]
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.format_sql=trueIRIS 테이블에 대한 영구 Java 클래스 매핑을 생성하는 다음 단계는 다음을 참조하십시오.
package community.intersystems.springboot.app.model;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import com.fasterxml.jackson.annotation.JsonFormat;
@Entity
@Table(name = "Product")
public class Product implements Serializable {
private static final long serialVersionUID = 1L;
@GeneratedValue (strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String description;
private Double height;
private Double width;
private Double weight;
@Column(name="releasedate")
(TemporalType.DATE)
@JsonFormat(pattern = "dd/MM/yyyy")
private Date releaseDate;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Double getHeight() {
return height;
}
public void setHeight(Double height) {
this.height = height;
}
public Double getWidth() {
return width;
}
public void setWidth(Double width) {
this.width = width;
}
public Double getWeight() {
return weight;
}
public void setWeight(Double weight) {
this.weight = weight;
}
public Date getReleaseDate() {
return releaseDate;
}
public void setReleaseDate(Date releaseDate) {
this.releaseDate = releaseDate;
}
}마지막 단계는 crud 작업을 사용하여 영구 클래스를 REST 서비스(HATEOAS 패턴)로 노출하는 저장소 인터페이스를 생성하는 것입니다. 다음과 같이 작성할 필요가 없습니다.
패키지 community.intersystems.springboot.app.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import community.intersystems.springboot.app.model.Product;
public interface ProductRepository extends JpaRepository<Product, Long> {
}이제 앱을 Spring Boot 앱으로 실행합니다.

내부 서버가 작동할 때까지 기다렸다가 localhost:8080을 엽니다. Spring Boot는 API REST HAL 브라우저를 엽니다. 이 이미지 레코드를 참조하십시오.

내 앱 샘플에서 자세한 내용을 확인하세요. IRIS와 SpringBoot라는 두 가지 서비스를 포함하는 Docker 프로젝트에 모두 함께 패키징합니다.
HATEOAS 패턴은 api URL, 경로 및 탐색에 대한 매우 좋은 패턴입니다. 자세한 내용은 다음을 참조하십시오. https://en.wikipedia.org/wiki/HATEOAS
즐기다!
Reference
이 문제에 관하여(예: Java + SpringBoot + Hibernate 및 IRIS 데이터베이스를 사용하여 REST API 생성), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/intersystems/example-using-java-springboot-hibernate-and-iris-database-to-create-rest-api-2fol텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)