diff --git a/codes/javadb/javadb-h2/pom.xml b/codes/javadb/javadb-h2/pom.xml
index da00858..cac313f 100644
--- a/codes/javadb/javadb-h2/pom.xml
+++ b/codes/javadb/javadb-h2/pom.xml
@@ -14,7 +14,7 @@
${java.version}
${java.version}
- 4.12
+ 4.13.1
@@ -39,7 +39,7 @@
com.h2database
h2
- 1.4.197
+ 2.0.206
test
diff --git a/codes/javadb/javadb-hbase/pom.xml b/codes/javadb/javadb-hbase/pom.xml
index cec9525..cec530c 100644
--- a/codes/javadb/javadb-hbase/pom.xml
+++ b/codes/javadb/javadb-hbase/pom.xml
@@ -15,7 +15,7 @@
${java.version}
1.3.1
- 4.12
+ 4.13.1
0.5.7
diff --git a/codes/javadb/javadb-mysql/pom.xml b/codes/javadb/javadb-mysql/pom.xml
index 3b52b19..03292c8 100644
--- a/codes/javadb/javadb-mysql/pom.xml
+++ b/codes/javadb/javadb-mysql/pom.xml
@@ -1,6 +1,6 @@
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
@@ -15,111 +15,32 @@
1.0.0
jar
-
- UTF-8
- 1.8
- ${java.version}
- ${java.version}
-
- 4.3.13.RELEASE
- 1.2.3
- 4.12
-
-
org.springframework.boot
spring-boot-starter-jdbc
-
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
mysql
mysql-connector-java
- 8.0.21
- org.apache.commons
- commons-pool2
- 2.5.0
+ org.projectlombok
+ lombok
-
-
-
-
- ch.qos.logback
- logback-classic
-
-
-
-
-
- org.springframework
- spring-context-support
-
-
- org.springframework
- spring-test
- test
-
-
-
-
-
- junit
- junit
-
-
-
-
-
- org.springframework
- spring-framework-bom
- ${spring.version}
- pom
- import
-
-
-
-
- redis.clients
- jedis
- ${jedis.version}
-
-
-
-
-
- ch.qos.logback
- logback-parent
- ${logback.version}
- pom
- import
-
-
-
-
-
- junit
- junit
- ${junit.version}
- test
-
-
-
-
-
- ${project.artifactId}
-
-
- true
- src/main/resources
-
- logback.xml
-
-
-
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
diff --git a/codes/javadb/javadb-mysql/src/main/java/io/github/dunwu/javadb/SpringBootDataJdbcApplication.java b/codes/javadb/javadb-mysql/src/main/java/io/github/dunwu/javadb/SpringBootDataJdbcApplication.java
new file mode 100644
index 0000000..7ac12f2
--- /dev/null
+++ b/codes/javadb/javadb-mysql/src/main/java/io/github/dunwu/javadb/SpringBootDataJdbcApplication.java
@@ -0,0 +1,45 @@
+package io.github.dunwu.javadb;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import java.sql.Connection;
+import javax.sql.DataSource;
+
+@Slf4j
+@SpringBootApplication
+public class SpringBootDataJdbcApplication implements CommandLineRunner {
+
+ private final JdbcTemplate jdbcTemplate;
+
+ public SpringBootDataJdbcApplication(JdbcTemplate jdbcTemplate) {
+ this.jdbcTemplate = jdbcTemplate;
+ }
+
+ public static void main(String[] args) {
+ SpringApplication.run(SpringBootDataJdbcApplication.class, args);
+ }
+
+ @Override
+ public void run(String... args) throws Exception {
+ DataSource dataSource = jdbcTemplate.getDataSource();
+
+ Connection connection;
+ if (dataSource != null) {
+ connection = dataSource.getConnection();
+ } else {
+ log.error("连接数据源失败!");
+ return;
+ }
+
+ if (connection != null) {
+ log.info("数据源 Url: {}", connection.getMetaData().getURL());
+ } else {
+ log.error("连接数据源失败!");
+ }
+ }
+
+}
diff --git a/codes/javadb/javadb-mysql/src/main/java/io/github/dunwu/javadb/User.java b/codes/javadb/javadb-mysql/src/main/java/io/github/dunwu/javadb/User.java
new file mode 100644
index 0000000..c70c5f6
--- /dev/null
+++ b/codes/javadb/javadb-mysql/src/main/java/io/github/dunwu/javadb/User.java
@@ -0,0 +1,63 @@
+package io.github.dunwu.javadb;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+import java.util.Objects;
+
+/**
+ * 用户实体,对应 user 表
+ *
+ * @author Zhang Peng
+ * @since 2019-11-18
+ */
+@Data
+@ToString
+@NoArgsConstructor
+@AllArgsConstructor
+public class User {
+
+ private Long id;
+
+ private String name;
+
+ private Integer age;
+
+ private String address;
+
+ private String email;
+
+ public User(String name, Integer age, String address, String email) {
+ this.name = name;
+ this.age = age;
+ this.address = address;
+ this.email = email;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, name);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+
+ if (!(o instanceof User)) {
+ return false;
+ }
+
+ User user = (User) o;
+
+ if (id != null && id.equals(user.id)) {
+ return true;
+ }
+
+ return name.equals(user.name);
+ }
+
+}
diff --git a/codes/javadb/javadb-mysql/src/main/java/io/github/dunwu/javadb/UserDao.java b/codes/javadb/javadb-mysql/src/main/java/io/github/dunwu/javadb/UserDao.java
new file mode 100644
index 0000000..1bc9d97
--- /dev/null
+++ b/codes/javadb/javadb-mysql/src/main/java/io/github/dunwu/javadb/UserDao.java
@@ -0,0 +1,41 @@
+package io.github.dunwu.javadb;
+
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import java.util.List;
+
+/**
+ * user 表 Dao 接口
+ *
+ * @author Zhang Peng
+ * @since 2019-11-18
+ */
+public interface UserDao {
+
+ // DML
+ // -------------------------------------------------------------------
+ void insert(User user);
+
+ void batchInsert(List users);
+
+ void deleteByName(String name);
+
+ void deleteAll();
+
+ void update(User user);
+
+ Integer count();
+
+ List list();
+
+ User queryByName(String name);
+
+ JdbcTemplate getJdbcTemplate();
+
+ // DDL
+ // -------------------------------------------------------------------
+ void truncate();
+
+ void recreateTable();
+
+}
diff --git a/codes/javadb/javadb-mysql/src/main/java/io/github/dunwu/javadb/UserDaoExecutor.java b/codes/javadb/javadb-mysql/src/main/java/io/github/dunwu/javadb/UserDaoExecutor.java
new file mode 100644
index 0000000..44ff00f
--- /dev/null
+++ b/codes/javadb/javadb-mysql/src/main/java/io/github/dunwu/javadb/UserDaoExecutor.java
@@ -0,0 +1,36 @@
+package io.github.dunwu.javadb;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import javax.annotation.PostConstruct;
+
+/**
+ * @author Zhang Peng
+ * @since 2020-10-11
+ */
+@Slf4j
+@Component
+public class UserDaoExecutor {
+
+ private final UserDao userDao;
+
+ public UserDaoExecutor(UserDao userDao) {
+ this.userDao = userDao;
+ }
+
+ @PostConstruct
+ public void method() {
+ if (userDao != null) {
+ log.info("Connect to datasource success.");
+ } else {
+ log.error("Connect to datasource failed!");
+ return;
+ }
+
+ List list = userDao.list();
+ list.forEach(item -> log.info(item.toString()));
+ }
+
+}
diff --git a/codes/javadb/javadb-mysql/src/main/java/io/github/dunwu/javadb/UserDaoImpl.java b/codes/javadb/javadb-mysql/src/main/java/io/github/dunwu/javadb/UserDaoImpl.java
new file mode 100644
index 0000000..f558f9d
--- /dev/null
+++ b/codes/javadb/javadb-mysql/src/main/java/io/github/dunwu/javadb/UserDaoImpl.java
@@ -0,0 +1,114 @@
+package io.github.dunwu.javadb;
+
+import org.springframework.dao.EmptyResultDataAccessException;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * user 表 Dao 接口实现类
+ *
+ * @author Zhang Peng
+ * @since 2019-11-18
+ */
+@Repository
+public class UserDaoImpl implements UserDao {
+
+ private final JdbcTemplate jdbcTemplate;
+
+ public UserDaoImpl(JdbcTemplate jdbcTemplate) {
+ this.jdbcTemplate = jdbcTemplate;
+ }
+
+ @Override
+ public void insert(User user) {
+ jdbcTemplate.update("INSERT INTO user(name, age, address, email) VALUES(?, ?, ?, ?)",
+ user.getName(), user.getAge(), user.getAddress(), user.getEmail());
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void batchInsert(List users) {
+ String sql = "INSERT INTO user(name, age, address, email) VALUES(?, ?, ?, ?)";
+
+ List
diff --git a/codes/redis/redis-in-action/pom.xml b/codes/redis/redis-in-action/pom.xml
index 5a19dba..3c2c2ed 100644
--- a/codes/redis/redis-in-action/pom.xml
+++ b/codes/redis/redis-in-action/pom.xml
@@ -16,7 +16,7 @@
1.2.3
2.9.0
- 4.12
+ 4.13.1