Skip to content

Commit ad820ba

Browse files
committed
feat: 项目调整
1 parent 0e9ded6 commit ad820ba

File tree

120 files changed

+14430
-3026
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+14430
-3026
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ insert_final_newline = true
1919
[*.{bat, cmd}]
2020
end_of_line = crlf
2121

22-
[*.{java, gradle, groovy, kt, sh}]
22+
[*.{java, gradle, groovy, kt, sh, xml}]
2323
indent_size = 4
2424

2525
[*.md]

codes/javadb/javadb-h2/pom.xml

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,53 @@
1-
<?xml version="1.0"?>
2-
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4-
xmlns="http://maven.apache.org/POM/4.0.0">
5-
<modelVersion>4.0.0</modelVersion>
6-
<groupId>io.github.dunwu</groupId>
7-
<artifactId>javadb-h2</artifactId>
8-
<version>1.0.0</version>
9-
<packaging>jar</packaging>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
105

11-
<properties>
12-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13-
<java.version>1.8</java.version>
14-
<maven.compiler.source>${java.version}</maven.compiler.source>
15-
<maven.compiler.target>${java.version}</maven.compiler.target>
6+
<parent>
7+
<groupId>org.springframework.boot</groupId>
8+
<artifactId>spring-boot-starter-parent</artifactId>
9+
<version>2.6.3</version>
10+
</parent>
1611

17-
<junit.version>4.13.1</junit.version>
18-
</properties>
12+
<groupId>io.github.dunwu</groupId>
13+
<artifactId>javadb-h2</artifactId>
14+
<version>1.0.0</version>
15+
<packaging>jar</packaging>
1916

20-
<dependencies>
21-
<!-- db begin -->
22-
<dependency>
23-
<groupId>com.h2database</groupId>
24-
<artifactId>h2</artifactId>
25-
</dependency>
26-
<!-- db end -->
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.springframework.boot</groupId>
20+
<artifactId>spring-boot-starter-data-rest</artifactId>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-data-jpa</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-test</artifactId>
29+
<scope>test</scope>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.projectlombok</groupId>
33+
<artifactId>lombok</artifactId>
34+
</dependency>
2735

28-
<!-- test begin -->
29-
<dependency>
30-
<groupId>junit</groupId>
31-
<artifactId>junit</artifactId>
32-
</dependency>
33-
<!-- test end -->
34-
</dependencies>
36+
<!-- db begin -->
37+
<dependency>
38+
<groupId>com.h2database</groupId>
39+
<artifactId>h2</artifactId>
40+
<version>2.1.210</version>
41+
</dependency>
42+
<!-- db end -->
43+
</dependencies>
3544

36-
<dependencyManagement>
37-
<dependencies>
38-
<!-- database begin -->
39-
<dependency>
40-
<groupId>com.h2database</groupId>
41-
<artifactId>h2</artifactId>
42-
<version>2.0.206</version>
43-
<scope>test</scope>
44-
</dependency>
45-
<!-- database end -->
46-
47-
<!-- test begin -->
48-
<dependency>
49-
<groupId>junit</groupId>
50-
<artifactId>junit</artifactId>
51-
<version>${junit.version}</version>
52-
<scope>test</scope>
53-
</dependency>
54-
<!-- test end -->
55-
</dependencies>
56-
</dependencyManagement>
45+
<build>
46+
<plugins>
47+
<plugin>
48+
<groupId>org.springframework.boot</groupId>
49+
<artifactId>spring-boot-maven-plugin</artifactId>
50+
</plugin>
51+
</plugins>
52+
</build>
5753
</project>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package io.github.dunwu.javadb.h2.springboot;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.boot.CommandLineRunner;
6+
import org.springframework.boot.SpringApplication;
7+
import org.springframework.boot.autoconfigure.SpringBootApplication;
8+
9+
import javax.sql.DataSource;
10+
import java.sql.Connection;
11+
import java.sql.SQLException;
12+
13+
@SpringBootApplication
14+
public class SpringBootDataJpaApplication implements CommandLineRunner {
15+
16+
private final Logger log = LoggerFactory.getLogger(this.getClass());
17+
18+
private final DataSource dataSource;
19+
20+
public SpringBootDataJpaApplication(DataSource dataSource) {
21+
this.dataSource = dataSource;
22+
}
23+
24+
public static void main(String[] args) {
25+
SpringApplication.run(SpringBootDataJpaApplication.class, args);
26+
}
27+
28+
@Override
29+
public void run(String... args) throws Exception {
30+
31+
if (dataSource != null) {
32+
printDataSourceInfo(dataSource);
33+
log.info("Connect to datasource success.");
34+
} else {
35+
log.error("Connect to datasource failed!");
36+
}
37+
}
38+
39+
private void printDataSourceInfo(DataSource dataSource) throws SQLException {
40+
41+
Connection connection;
42+
if (dataSource != null) {
43+
connection = dataSource.getConnection();
44+
} else {
45+
log.error("Get dataSource failed!");
46+
return;
47+
}
48+
49+
if (connection != null) {
50+
log.info("DataSource Url: {}", connection.getMetaData().getURL());
51+
} else {
52+
log.error("Connect to datasource failed!");
53+
}
54+
}
55+
56+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package io.github.dunwu.javadb.h2.springboot;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
import lombok.ToString;
7+
8+
import javax.persistence.Entity;
9+
import javax.persistence.GeneratedValue;
10+
import javax.persistence.GenerationType;
11+
import javax.persistence.Id;
12+
import java.util.Objects;
13+
14+
/**
15+
* 用户实体,对应 user 表
16+
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
17+
* @since 2019-11-18
18+
*/
19+
@Entity
20+
@Data
21+
@ToString
22+
@NoArgsConstructor
23+
@AllArgsConstructor
24+
public class User {
25+
26+
@Id
27+
@GeneratedValue(strategy = GenerationType.AUTO)
28+
private Long id;
29+
30+
private String name;
31+
32+
private Integer age;
33+
34+
private String address;
35+
36+
private String email;
37+
38+
public User(String name, Integer age, String address, String email) {
39+
this.name = name;
40+
this.age = age;
41+
this.address = address;
42+
this.email = email;
43+
}
44+
45+
@Override
46+
public int hashCode() {
47+
return Objects.hash(id, name);
48+
}
49+
50+
@Override
51+
public boolean equals(Object o) {
52+
if (this == o) {
53+
return true;
54+
}
55+
56+
if (!(o instanceof User)) {
57+
return false;
58+
}
59+
60+
User user = (User) o;
61+
62+
if (id != null && id.equals(user.id)) {
63+
return true;
64+
}
65+
66+
return name.equals(user.name);
67+
}
68+
69+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package io.github.dunwu.javadb.h2.springboot;
2+
3+
import org.springframework.data.jpa.repository.JpaRepository;
4+
import org.springframework.data.jpa.repository.Query;
5+
import org.springframework.data.repository.query.Param;
6+
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
7+
8+
/**
9+
* JPA Rest 接口,对应 user 表
10+
* <p>
11+
* 启动 Application 后,直接访问:http://<host:ip>/user
12+
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
13+
* @since 2019-10-12
14+
*/
15+
@RepositoryRestResource(collectionResourceRel = "user", path = "user")
16+
public interface UserRepository extends JpaRepository<User, Long> {
17+
18+
/**
19+
* 根据用户名查找用户
20+
* <p>
21+
* 示例:http://localhost:8080/user/search/findByName?name=lisi
22+
* @param name 用户名
23+
* @return {@link User}
24+
*/
25+
User findByName(@Param("name") String name);
26+
27+
/**
28+
* 根据邮箱查找用户
29+
* @param email 邮箱
30+
* @return {@link User}
31+
*/
32+
@Query("from User u where u.email=:email")
33+
User findByEmail(@Param("email") String email);
34+
35+
/**
36+
* 根据用户名删除用户
37+
* @param name 用户名
38+
*/
39+
void deleteByName(@Param("name") String name);
40+
41+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
spring.datasource.url = jdbc:h2:mem:test
2+
spring.datasource.driver-class-name = org.h2.Driver
3+
spring.datasource.username = sa
4+
spring.datasource.password =
5+
spring.datasource.schema = classpath:sql/schema-h2.sql
6+
spring.datasource.data = classpath:sql/data-h2.sql
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
${AnsiColor.BRIGHT_YELLOW}${AnsiStyle.BOLD}
2+
________ ___ ___ ________ ___ __ ___ ___
3+
|\ ___ \|\ \|\ \|\ ___ \|\ \ |\ \|\ \|\ \
4+
\ \ \_|\ \ \ \\\ \ \ \\ \ \ \ \ \ \ \ \ \\\ \
5+
\ \ \ \\ \ \ \\\ \ \ \\ \ \ \ \ __\ \ \ \ \\\ \
6+
\ \ \_\\ \ \ \\\ \ \ \\ \ \ \ \|\__\_\ \ \ \\\ \
7+
\ \_______\ \_______\ \__\\ \__\ \____________\ \_______\
8+
\|_______|\|_______|\|__| \|__|\|____________|\|_______|
9+
${AnsiColor.CYAN}${AnsiStyle.BOLD}
10+
:: Java :: (v${java.version})
11+
:: Spring Boot :: (v${spring-boot.version})
12+
${AnsiStyle.NORMAL}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<configuration scan="true" scanPeriod="60 seconds" debug="false">
3+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
4+
<encoder>
5+
<pattern>%d{HH:mm:ss.SSS} [%boldYellow(%thread)] [%highlight(%-5level)] %boldGreen(%c{36}.%M) - %boldBlue(%m%n)
6+
</pattern>
7+
</encoder>
8+
</appender>
9+
10+
<logger name="io.github.dunwu.spring" level="INFO" />
11+
12+
<root level="INFO">
13+
<appender-ref ref="CONSOLE" />
14+
</root>
15+
</configuration>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- -------------------------------------------------------------------
2+
-- 运行本项目的初始化 DML 脚本
3+
-- H2 知识点可以参考:
4+
-- https://dunwu.github.io/db-tutorial/#/sql/h2
5+
-- -------------------------------------------------------------------
6+
7+
INSERT INTO user (name, age, address, email)
8+
VALUES ('张三', 18, '北京', 'xxx@163.com');
9+
INSERT INTO user (name, age, address, email)
10+
VALUES ('李四', 19, '上海', 'xxx@163.com');
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- -------------------------------------------------------------------
2+
-- 运行本项目的初始化 DDL 脚本
3+
-- H2 知识点可以参考:
4+
-- https://dunwu.github.io/db-tutorial/#/sql/h2
5+
-- -------------------------------------------------------------------
6+
CREATE TABLE user (
7+
id INT NOT NULL AUTO_INCREMENT,
8+
name VARCHAR(100),
9+
age INT,
10+
address VARCHAR(50),
11+
email VARCHAR(50),
12+
PRIMARY KEY (id)
13+
);

0 commit comments

Comments
 (0)