diff --git a/guest/spring-mvc/pom.xml b/guest/spring-mvc/pom.xml new file mode 100644 index 0000000000..9974a76e8a --- /dev/null +++ b/guest/spring-mvc/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + com.forketyfork.guest + spring-mvc + 0.0.1-SNAPSHOT + jar + + spring-mvc + Spring MVC sample project + + + org.springframework.boot + spring-boot-starter-parent + 2.0.0.M5 + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + UTF-8 + UTF-8 + 1.8 + + + diff --git a/guest/spring-mvc/src/main/java/com/forketyfork/guest/springmvc/Spring5Application.java b/guest/spring-mvc/src/main/java/com/forketyfork/guest/springmvc/Spring5Application.java new file mode 100644 index 0000000000..d9af7c8ac9 --- /dev/null +++ b/guest/spring-mvc/src/main/java/com/forketyfork/guest/springmvc/Spring5Application.java @@ -0,0 +1,15 @@ +package com.forketyfork.guest.springmvc; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.boot.SpringApplication; + +@SpringBootApplication +@ComponentScan(basePackages = {"com.forketyfork.guest.springmvc"}) +public class Spring5Application { + + public static void main(String[] args) { + SpringApplication.run(Spring5Application.class, args); + } + +} diff --git a/guest/spring-mvc/src/main/java/com/forketyfork/guest/springmvc/model/LoginData.java b/guest/spring-mvc/src/main/java/com/forketyfork/guest/springmvc/model/LoginData.java new file mode 100644 index 0000000000..a9140da4f9 --- /dev/null +++ b/guest/spring-mvc/src/main/java/com/forketyfork/guest/springmvc/model/LoginData.java @@ -0,0 +1,27 @@ +package com.forketyfork.guest.springmvc.model; + +public class LoginData { + + private String login; + + private String password; + + public LoginData() { + } + + public String getLogin() { + return login; + } + + public void setLogin(String login) { + this.login = login; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } +} diff --git a/guest/spring-mvc/src/main/java/com/forketyfork/guest/springmvc/web/InternalsController.java b/guest/spring-mvc/src/main/java/com/forketyfork/guest/springmvc/web/InternalsController.java new file mode 100644 index 0000000000..c39da4e3e5 --- /dev/null +++ b/guest/spring-mvc/src/main/java/com/forketyfork/guest/springmvc/web/InternalsController.java @@ -0,0 +1,31 @@ +package com.forketyfork.guest.springmvc.web; + +import com.forketyfork.guest.springmvc.model.LoginData; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.servlet.ModelAndView; + +import java.util.Collections; + +@Controller +public class InternalsController { + + private static final String LOGIN = "jack"; + private static final String PASSWORD = "halloween"; + + @GetMapping("/") + public String hello() { + return "login"; + } + + @PostMapping("/login") + public ModelAndView login(LoginData loginData) { + if (LOGIN.equals(loginData.getLogin()) && PASSWORD.equals(loginData.getPassword())) { + return new ModelAndView("success", Collections.singletonMap("login", loginData.getLogin())); + } else { + return new ModelAndView("failure", Collections.singletonMap("login", loginData.getLogin())); + } + } + +} diff --git a/guest/spring-mvc/src/main/resources/templates/failure.html b/guest/spring-mvc/src/main/resources/templates/failure.html new file mode 100644 index 0000000000..f319652ede --- /dev/null +++ b/guest/spring-mvc/src/main/resources/templates/failure.html @@ -0,0 +1,10 @@ + + + + Login Failure + +

+ User with login not found, please try again. +

+ \ No newline at end of file diff --git a/guest/spring-mvc/src/main/resources/templates/login.html b/guest/spring-mvc/src/main/resources/templates/login.html new file mode 100644 index 0000000000..d031ac8825 --- /dev/null +++ b/guest/spring-mvc/src/main/resources/templates/login.html @@ -0,0 +1,13 @@ + + +Login Form + + +
+ + + +
+ + + \ No newline at end of file diff --git a/guest/spring-mvc/src/main/resources/templates/success.html b/guest/spring-mvc/src/main/resources/templates/success.html new file mode 100644 index 0000000000..6966385f2e --- /dev/null +++ b/guest/spring-mvc/src/main/resources/templates/success.html @@ -0,0 +1,10 @@ + + + + Login Success + +

+ Hello, ! +

+ \ No newline at end of file