diff --git a/README.md b/README.md
index c7c38ff..271b3af 100644
--- a/README.md
+++ b/README.md
@@ -16,4 +16,4 @@
## Run
- Run command `docker-compose up`
-- Access to http://localhost/
+- Access to http://localhost:8084/
diff --git a/app/pom.xml b/app/pom.xml
index 0c98b9f..c8d4939 100644
--- a/app/pom.xml
+++ b/app/pom.xml
@@ -5,14 +5,17 @@
dockercompose-springboot-mysql-nginx
dockercompose-springboot-mysql-nginx
- org.springframework.boot
- spring-boot-starter-parent
- 1.5.8.RELEASE
-
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.0.0.RELEASE
+
+
- 1.8
-
+ UTF-8
+ UTF-8
+ 1.8
+
@@ -23,10 +26,23 @@
org.springframework.boot
spring-boot-starter-data-jpa
+
+ org.flywaydb
+ flyway-core
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
mysql
mysql-connector-java
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
diff --git a/app/src/main/java/com/hellokoding/springboot/controller/UserController.java b/app/src/main/java/com/hellokoding/springboot/controller/UserController.java
new file mode 100644
index 0000000..3d0aba1
--- /dev/null
+++ b/app/src/main/java/com/hellokoding/springboot/controller/UserController.java
@@ -0,0 +1,23 @@
+package com.hellokoding.springboot.controller;
+
+import com.hellokoding.springboot.domain.User;
+import com.hellokoding.springboot.service.UserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+
+@RestController
+public class UserController {
+
+ @Autowired
+ private UserService UserService;
+
+ @RequestMapping(value = "/api/user", method = RequestMethod.GET)
+ public User findOneUser(@RequestParam(value = "userName", required = true) String userName) {
+ return UserService.findUserByName(userName);
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/hellokoding/springboot/domain/User.java b/app/src/main/java/com/hellokoding/springboot/domain/User.java
new file mode 100644
index 0000000..481b7d1
--- /dev/null
+++ b/app/src/main/java/com/hellokoding/springboot/domain/User.java
@@ -0,0 +1,57 @@
+package com.hellokoding.springboot.domain;
+
+import javax.persistence.*;
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.Size;
+
+@Entity
+@Table(name = "users")
+public class User {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+ @NotBlank
+ @Column(unique = true)
+ @Size(min = 1, max = 100)
+ private String username;
+
+ @NotBlank
+ @Size(max = 50)
+ private String firstName;
+
+ @Size(max = 50)
+ private String lastName;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/hellokoding/springboot/repository/UserRepository.java b/app/src/main/java/com/hellokoding/springboot/repository/UserRepository.java
new file mode 100644
index 0000000..f568d39
--- /dev/null
+++ b/app/src/main/java/com/hellokoding/springboot/repository/UserRepository.java
@@ -0,0 +1,8 @@
+package com.hellokoding.springboot.repository;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+import com.hellokoding.springboot.domain.User;
+@Repository
+public interface UserRepository extends JpaRepository {
+ User findByUsername(String username);
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/hellokoding/springboot/service/UserService.java b/app/src/main/java/com/hellokoding/springboot/service/UserService.java
new file mode 100644
index 0000000..18e7af4
--- /dev/null
+++ b/app/src/main/java/com/hellokoding/springboot/service/UserService.java
@@ -0,0 +1,9 @@
+package com.hellokoding.springboot.service;
+
+import com.hellokoding.springboot.domain.User;
+
+
+public interface UserService {
+
+ User findUserByName(String username);
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/hellokoding/springboot/service/impl/UserServiceImpl.java b/app/src/main/java/com/hellokoding/springboot/service/impl/UserServiceImpl.java
new file mode 100644
index 0000000..e58d5d3
--- /dev/null
+++ b/app/src/main/java/com/hellokoding/springboot/service/impl/UserServiceImpl.java
@@ -0,0 +1,19 @@
+package com.hellokoding.springboot.service.impl;
+
+import com.hellokoding.springboot.repository.UserRepository;
+import com.hellokoding.springboot.domain.User;
+import com.hellokoding.springboot.service.UserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class UserServiceImpl implements UserService {
+
+ @Autowired
+ private UserRepository UserRepository;
+
+ public User findUserByName(String username) {
+ return UserRepository.findByUsername(username);
+ }
+
+}
diff --git a/app/src/main/resources/application.properties b/app/src/main/resources/application.properties
index ccc21b3..9180e9e 100644
--- a/app/src/main/resources/application.properties
+++ b/app/src/main/resources/application.properties
@@ -1,12 +1,19 @@
-spring.freemarker.template-loader-path: classpath:/templates
-spring.freemarker.suffix: .ftl
+
+spring.freemarker.suffix=.ftl
+spring.freemarker.cache=false
+spring.freemarker.charset=UTF-8
+spring.freemarker.check-template-location=true
+spring.freemarker.content-type=text/html
+spring.freemarker.expose-request-attributes=true
+spring.freemarker.expose-session-attributes=true
+spring.freemarker.request-context-attribute=request
spring.datasource.url=jdbc:mysql://mysql:3306/test?useSSL=false
spring.datasource.username=root
spring.datasource.password=hellokoding
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
-spring.jpa.hibernate.ddl-auto=create
+spring.jpa.hibernate.ddl-auto=validate
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true
\ No newline at end of file
diff --git a/app/src/main/resources/db/migration/V1__init.sql b/app/src/main/resources/db/migration/V1__init.sql
new file mode 100644
index 0000000..26643b8
--- /dev/null
+++ b/app/src/main/resources/db/migration/V1__init.sql
@@ -0,0 +1,8 @@
+CREATE TABLE users (
+ id bigint(20) NOT NULL AUTO_INCREMENT,
+ username varchar(100) NOT NULL,
+ first_name varchar(50) NOT NULL,
+ last_name varchar(50) DEFAULT NULL,
+ PRIMARY KEY (id),
+ UNIQUE KEY UK_username (username)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
\ No newline at end of file
diff --git a/app/src/main/resources/db/migration/V2__testdata.sql b/app/src/main/resources/db/migration/V2__testdata.sql
new file mode 100644
index 0000000..7e3434f
--- /dev/null
+++ b/app/src/main/resources/db/migration/V2__testdata.sql
@@ -0,0 +1,2 @@
+INSERT INTO users(username, first_name, last_name) VALUES('jeffer', 'yun', 'zhao');
+INSERT INTO users(username, first_name, last_name) VALUES('codeyu', 'wukong', 'sun');
\ No newline at end of file
diff --git a/app/src/main/resources/templates/index.ftl b/app/src/main/resources/templates/index.ftl
index 6e29a58..cf3810b 100644
--- a/app/src/main/resources/templates/index.ftl
+++ b/app/src/main/resources/templates/index.ftl
@@ -1,11 +1,14 @@
+<#assign base = request.contextPath />
Docker Compose with Spring Boot, MySQL, NGINX
+
+
- Docker Compose with Spring Boot, MySQL, NGINX
+ Docker Compose with Spring Boot, MySQL, NGINX
\ No newline at end of file
diff --git a/docker-compose.yaml b/docker-compose.yaml
index aecf61b..af60e1b 100644
--- a/docker-compose.yaml
+++ b/docker-compose.yaml
@@ -5,10 +5,12 @@ services:
image: nginx:1.13
restart: always
ports:
- - 80:80
- - 443:443
+ - "8084:80"
+ - "443:443"
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d
+ depends_on:
+ - app
mysql:
container_name: some-mysql
@@ -32,5 +34,4 @@ services:
- "8080"
command: mvn clean spring-boot:run
depends_on:
- - nginx
- mysql