build.gradle
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'mysql:mysql-connector-java'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
//Describe the lombok settings below
compileOnly 'org.projectlombok:lombok:1.18.10'
annotationProcessor 'org.projectlombok:lombok:1.18.10'
}
Reload gradle
Open Gradle from Tool,
Press the update button
entity/Product.java
package com.example.reviewapiapp.entity;
import lombok.Data;
@Data
public class Product {}
If you can install it, you can use @Data. If you haven't installed it, you can't use @Data.
mysql
mysql> SELECT user, host FROM mysql.user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| hogehogehoge | % |
| hogehoge | % |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
5 rows in set (0.01 sec)
mysql> grant all on review_api_db.* to 'root'@'localhost';
Query OK, 0 rows affected (0.01 sec)
application.yml
spring:
datasource:
initialization-mode: always
sql-script-encoding: UTF-8
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
database: MYSQL
hibernate:
ddl-auto: none
profiles:
active: local
application-local.yml
spring:
profiles:
active: local
datasource:
url: jdbc:mysql://localhost:3306/review_api_db
username: root
driver-class-name: com.mysql.cj.jdbc.Driver
schema: classpath:schema.sql
schema.sql
create table if not exists products
(
id bigint unsigned not null auto_increment primary key comment 'Product ID',
title varchar(100) not null unique comment 'Product title',
description varchar(500) not null comment 'Product description',
price int unsigned not null comment 'Product price',
image_path text comment 'Product image path',
create_time datetime not null default current_timestamp comment 'Creation date and time',
update_time datetime not null default current_timestamp on update current_timestamp comment 'Update date and time'
) comment 'Product table' engine = innodb
charset = utf8mb4;
Recommended Posts