Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test #11

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: java
services:
- mysql

before_install:
- mysql -e 'CREATE DATABASE IF NOT EXISTS hello_test;'

env:
- DATABASE=jdbc:mysql://localhost:3306/hello_test DB_USERNAME=travis DB_PASSWORD=""
5 changes: 4 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>




<groupId>org.springframework</groupId>
<artifactId>hello-java</artifactId>
<version>0.1.0</version>
Expand Down Expand Up @@ -71,4 +74,4 @@
</plugins>
</build>

</project>
</project>
7 changes: 5 additions & 2 deletions src/main/java/hello/GreetingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import hello.GreetingTranslator ;

@Controller
public class GreetingController {
public class GreetingController{

@RequestMapping("/greeting")
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";
}

}
}
17 changes: 17 additions & 0 deletions src/main/java/hello/GreetingTranslator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package hello;

public class GreetingTranslator {

public static 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 ;
}

}
4 changes: 2 additions & 2 deletions src/main/resources/templates/greeting.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'Hello, ' + ${name} + '!'" />
<p th:text="${hello} + ', ' + ${name} + '!'" />
</body>
</html>
</html>