From e61d5d564f267bd5695b50d6de0cba9ba3bc4527 Mon Sep 17 00:00:00 2001 From: Ballarja Date: Fri, 10 Feb 2023 22:27:13 -0600 Subject: [PATCH 1/3] exercise commit --- build.gradle | 1 + .../hellospring/HelloSpringApplication.java | 41 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) 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..fc9518c 100644 --- a/src/main/java/org/launchcode/hellospring/HelloSpringApplication.java +++ b/src/main/java/org/launchcode/hellospring/HelloSpringApplication.java @@ -2,12 +2,51 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +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; @SpringBootApplication public class HelloSpringApplication { - public static void main(String[] args) { + public static void main(String[] args) + { SpringApplication.run(HelloSpringApplication.class, args); } + @RequestMapping(value="hello", method = 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; + } } From 17a4c4486c62744ed02105b9952ebdba7ec5f121 Mon Sep 17 00:00:00 2001 From: Ballarja Date: Sat, 11 Feb 2023 00:10:01 -0600 Subject: [PATCH 2/3] practice with thymeleaf --- .../hellospring/HelloSpringApplication.java | 38 +-------------- .../controllers/HelloSpringController.java | 46 +++++++++++++++++++ src/main/resources/templates/form.html | 0 3 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/main/java/org/launchcode/hellospring/controllers/HelloSpringController.java create mode 100644 src/main/resources/templates/form.html diff --git a/src/main/java/org/launchcode/hellospring/HelloSpringApplication.java b/src/main/java/org/launchcode/hellospring/HelloSpringApplication.java index fc9518c..e8a20dc 100644 --- a/src/main/java/org/launchcode/hellospring/HelloSpringApplication.java +++ b/src/main/java/org/launchcode/hellospring/HelloSpringApplication.java @@ -2,10 +2,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -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; + @SpringBootApplication public class HelloSpringApplication { @@ -14,39 +11,6 @@ public static void main(String[] args) { SpringApplication.run(HelloSpringApplication.class, args); } - @RequestMapping(value="hello", method = 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/java/org/launchcode/hellospring/controllers/HelloSpringController.java b/src/main/java/org/launchcode/hellospring/controllers/HelloSpringController.java new file mode 100644 index 0000000..ce4bb88 --- /dev/null +++ b/src/main/java/org/launchcode/hellospring/controllers/HelloSpringController.java @@ -0,0 +1,46 @@ +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; + +@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 From a922a076d6887b48e19167280acf1c9791833817 Mon Sep 17 00:00:00 2001 From: Ballarja Date: Sun, 12 Feb 2023 21:01:26 -0600 Subject: [PATCH 3/3] added thymeleaf template --- .../hellospring/controllers/HelloSpringController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/launchcode/hellospring/controllers/HelloSpringController.java b/src/main/java/org/launchcode/hellospring/controllers/HelloSpringController.java index ce4bb88..65f6bb8 100644 --- a/src/main/java/org/launchcode/hellospring/controllers/HelloSpringController.java +++ b/src/main/java/org/launchcode/hellospring/controllers/HelloSpringController.java @@ -6,6 +6,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; +//added thymeleaf template @Controller public class HelloSpringController {