diff --git a/build.gradle b/build.gradle index cc369a9..14f8edb 100644 --- a/build.gradle +++ b/build.gradle @@ -20,6 +20,7 @@ repositories { } dependencies { + implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-web' developmentOnly 'org.springframework.boot:spring-boot-devtools' testImplementation('org.springframework.boot:spring-boot-starter-test') { diff --git a/src/main/java/org/launchcode/hellospring/HelloSpringApplication.java b/src/main/java/org/launchcode/hellospring/HelloSpringApplication.java index 4fa4665..e8a20dc 100644 --- a/src/main/java/org/launchcode/hellospring/HelloSpringApplication.java +++ b/src/main/java/org/launchcode/hellospring/HelloSpringApplication.java @@ -3,11 +3,14 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; + @SpringBootApplication public class HelloSpringApplication { - public static void main(String[] args) { + public static void main(String[] args) + { SpringApplication.run(HelloSpringApplication.class, args); } + } diff --git a/src/main/java/org/launchcode/hellospring/controllers/HelloSpringController.java b/src/main/java/org/launchcode/hellospring/controllers/HelloSpringController.java new file mode 100644 index 0000000..65f6bb8 --- /dev/null +++ b/src/main/java/org/launchcode/hellospring/controllers/HelloSpringController.java @@ -0,0 +1,47 @@ +package org.launchcode.hellospring.controllers; + +import org.springframework.stereotype.Controller; +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.ResponseBody; + +//added thymeleaf template +@Controller +public class HelloSpringController { + + @RequestMapping(value="hello", method = {RequestMethod.GET, RequestMethod.POST}) + @ResponseBody + public String helloPost(@RequestParam String name, @RequestParam String language) { + if (name == null) { + name = "World"; + } + + return createMessage(name, language); + + // For a bonus mission, students can change this response text to look nicer. + // This is subjective, but students should be modifying the HTML of the response string. + } + + public static String createMessage(String n, String l) { + String greeting = ""; + + if (l.equals("english")) { + greeting = "Hello"; + } + else if (l.equals("french")) { + greeting = "Bonjour"; + } + else if (l.equals("italian")) { + greeting = "Bonjourno"; + } + else if (l.equals("spanish")) { + greeting = "Hola"; + } + else if (l.equals("german")) { + greeting = "Hallo"; + } + + return greeting + " " + n; + } +} diff --git a/src/main/resources/templates/form.html b/src/main/resources/templates/form.html new file mode 100644 index 0000000..e69de29