Skip to content
Open

Test #11

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>