|
@@ -1,13 +1,26 @@
|
1
|
1
|
package io.zipcoder.persistenceapp;
|
2
|
2
|
|
|
3
|
+import com.apple.eawt.Application;
|
3
|
4
|
import org.h2.server.web.WebServlet;
|
|
5
|
+import org.slf4j.Logger;
|
|
6
|
+import org.slf4j.LoggerFactory;
|
|
7
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
8
|
+import org.springframework.boot.CommandLineRunner;
|
4
|
9
|
import org.springframework.boot.SpringApplication;
|
5
|
10
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
6
|
11
|
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
7
|
12
|
import org.springframework.context.annotation.Bean;
|
|
13
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
14
|
+
|
|
15
|
+import java.util.Arrays;
|
|
16
|
+import java.util.List;
|
|
17
|
+import java.util.stream.Collectors;
|
8
|
18
|
|
9
|
19
|
@SpringBootApplication
|
10
|
|
-public class PersistenceStarterApplication {
|
|
20
|
+public class PersistenceStarterApplication implements CommandLineRunner {
|
|
21
|
+
|
|
22
|
+ private static final Logger log = LoggerFactory.getLogger(Application.class);
|
|
23
|
+
|
11
|
24
|
|
12
|
25
|
public static void main(String[] args) {
|
13
|
26
|
SpringApplication.run(PersistenceStarterApplication.class, args);
|
|
@@ -19,4 +32,26 @@ public class PersistenceStarterApplication {
|
19
|
32
|
registrationBean.addUrlMappings("/console/*");
|
20
|
33
|
return registrationBean;
|
21
|
34
|
}
|
|
35
|
+ @Autowired
|
|
36
|
+
|
|
37
|
+ JdbcTemplate jdbcTemplate;
|
|
38
|
+
|
|
39
|
+ @Override
|
|
40
|
+
|
|
41
|
+ public void run(String... strings) throws Exception {
|
|
42
|
+ log.info("Creating tables");
|
|
43
|
+ jdbcTemplate.execute("DROP TABLE Person IF EXISTS");
|
|
44
|
+ jdbcTemplate.execute("CREATE TABLE Person(" +
|
|
45
|
+ "id Integer(10), first_name VARCHAR(255), last_name VARCHAR(255),Mobile VARCHAR(255),Birthday DATE,Home_Id SMALLINT(5)");
|
|
46
|
+
|
|
47
|
+ jdbcTemplate.batchUpdate("INSERT INTO Person(id,first_name, last_name,Mobile,Birthday,Home_Id) VALUES ('1','hello','world','111-222-3333','01-2-1980','2')");
|
|
48
|
+ jdbcTemplate.batchUpdate("INSERT INTO Person(id,first_name, last_name,Mobile,Birthday,Home_Id) VALUES ('2','hai','world1','222-222-3333','02-3-1985','3')");
|
|
49
|
+ jdbcTemplate.batchUpdate("INSERT INTO Person(id,first_name, last_name,Mobile,Birthday,Home_Id) VALUES ('3','welcome','world','333-222-3333','03-5-1989','4')");
|
|
50
|
+ jdbcTemplate.batchUpdate("INSERT INTO Person(id,first_name, last_name,Mobile,Birthday,Home_Id) VALUES ('4','hai','','111-222-3333','01-2-1980','2')");
|
|
51
|
+
|
|
52
|
+// List<Object[]> splitUpNames = Arrays.asList("John Woo", "Jeff Dean", "Josh Bloch", "Josh Long").stream()
|
|
53
|
+// .map(name -> name.split(" "))
|
|
54
|
+// .collect(Collectors.toList());
|
|
55
|
+ //jdbcTemplate.query("select * from Person where id='1'");
|
|
56
|
+ }
|
22
|
57
|
}
|