-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathInitCreateTable.java
More file actions
38 lines (32 loc) · 972 Bytes
/
InitCreateTable.java
File metadata and controls
38 lines (32 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package gift.Controller;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
//app실행 했을 때 테이블 생성
@Service
public class InitCreateTable {
private final JdbcTemplate jdbcTemplate;
@Autowired
public InitCreateTable(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
@PostConstruct
public void init() {
//System.out.println("init");
createProductTable();
//System.out.println("create");
}
public void createProductTable() {
var sql = """
create table product (
id bigint auto_increment,
name varchar(255),
price int,
image_url varchar(255),
primary key (id)
)
""";
jdbcTemplate.execute(sql);
}
}