diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..5e29d40 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: java + +notifications: + email: + recipients: + - dmunnoz96@gmail.com + on_success: always # default: change + on_failure: always # default: always + diff --git a/README.md b/README.md new file mode 100644 index 0000000..7cf2ff5 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# hello-java +This is just a hello world example for the students of EGC course + +[![Build Status](https://travis-ci.org/DominMuda/hello-java.svg?branch=add-languages)](https://travis-ci.org/DominMuda/hello-java) diff --git a/src/main/java/hello/Application.java b/src/main/java/hello/Application.java index 8cf206d..5be2676 100644 --- a/src/main/java/hello/Application.java +++ b/src/main/java/hello/Application.java @@ -17,4 +17,4 @@ public static void main(String[] args) { SpringApplication.run(Application.class, args); } -} \ No newline at end of file +} diff --git a/src/main/java/hello/GreetingController.java b/src/main/java/hello/GreetingController.java index 2a1631c..5d4fd7f 100644 --- a/src/main/java/hello/GreetingController.java +++ b/src/main/java/hello/GreetingController.java @@ -8,11 +8,13 @@ @Controller public class GreetingController { + private GreetingTranslator greetingTranslator; + @RequestMapping("/greeting") - public String greeting(@RequestParam(value="name", required=false, defaultValue="World") String name, - Model model) { + public String greeting(@RequestParam(value="name", required=false, defaultValue="World") String name,@RequestParam(value="lang", required=false, defaultValue="en") String lang, Model model) { + model.addAttribute("hello", greetingTranslator.sayHelloIn(lang)); model.addAttribute("name", name); return "greeting"; } -} \ No newline at end of file +} diff --git a/src/main/java/hello/GreetingTranslator.java b/src/main/java/hello/GreetingTranslator.java new file mode 100644 index 0000000..c1ac86d --- /dev/null +++ b/src/main/java/hello/GreetingTranslator.java @@ -0,0 +1,17 @@ +package hello; + +public class GreetingTranslator { + + public String sayHelloIn(String lang) { + String hello; + if ("en".equals(lang)) { + hello = "hello"; + } else if ("es".equals(lang)) { + hello = "hola"; + } else { + hello = "no hablo tu idioma"; + } + return hello; + } + +} diff --git a/src/main/resources/templates/greeting.html b/src/main/resources/templates/greeting.html index aaeba56..0488fc9 100644 --- a/src/main/resources/templates/greeting.html +++ b/src/main/resources/templates/greeting.html @@ -7,4 +7,4 @@

- \ No newline at end of file +