diff --git a/pom.xml b/pom.xml index d2db787c64..b76c9b8ddd 100644 --- a/pom.xml +++ b/pom.xml @@ -185,6 +185,7 @@ xstream struts2 + diff --git a/spring-mobile/pom.xml b/spring-mobile/pom.xml new file mode 100644 index 0000000000..a62234e63f --- /dev/null +++ b/spring-mobile/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + com.baeldung + spring-mobile + 1.0-SNAPSHOT + spring-mobile + war + http://maven.apache.org + + + 1.8 + + + + org.springframework.boot + spring-boot-starter-parent + 1.4.3.RELEASE + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.mobile + spring-mobile-device + + + org.springframework.boot + spring-boot-starter-freemarker + + + + + + + src/main/resources + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + spring-releases + Spring Milestone Repository + https://repo.spring.io/libs-release + + + + + + spring-releases + Spring Milestone Repository + https://repo.spring.io/libs-release + + + + diff --git a/spring-mobile/src/main/java/com/baeldung/Application.java b/spring-mobile/src/main/java/com/baeldung/Application.java new file mode 100644 index 0000000000..2e460b0f98 --- /dev/null +++ b/spring-mobile/src/main/java/com/baeldung/Application.java @@ -0,0 +1,13 @@ +package com.baeldung; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} \ No newline at end of file diff --git a/spring-mobile/src/main/java/com/baeldung/controller/IndexController.java b/spring-mobile/src/main/java/com/baeldung/controller/IndexController.java new file mode 100644 index 0000000000..a6a0bd6e3c --- /dev/null +++ b/spring-mobile/src/main/java/com/baeldung/controller/IndexController.java @@ -0,0 +1,40 @@ +package com.baeldung.controller; + +import java.util.logging.Logger; + +import org.springframework.mobile.device.Device; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class IndexController { + + private final static Logger LOGGER = Logger.getLogger(IndexController.class.getName()); + + @GetMapping("/") + public String greeting(Device device) { + + String deviceType = "browser"; + String platform = "browser"; + + if (device.isNormal()) { + deviceType = "browser"; + } else if (device.isMobile()) { + deviceType = "mobile"; + } else if (device.isTablet()) { + deviceType = "tablet"; + } + + platform = device.getDevicePlatform().name(); + + if (platform.equalsIgnoreCase("UNKNOWN")) { + platform = "browser"; + } + + LOGGER.info("Client Device Type: " + deviceType +", Platform: " + platform); + + + return "index"; + } + +} diff --git a/spring-mobile/src/main/resources/application.properties b/spring-mobile/src/main/resources/application.properties new file mode 100644 index 0000000000..c0bc91f9ac --- /dev/null +++ b/spring-mobile/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.mobile.devicedelegatingviewresolver.enabled: true \ No newline at end of file diff --git a/spring-mobile/src/main/resources/templates/index.ftl b/spring-mobile/src/main/resources/templates/index.ftl new file mode 100644 index 0000000000..e4c28a8c9f --- /dev/null +++ b/spring-mobile/src/main/resources/templates/index.ftl @@ -0,0 +1,10 @@ + + + + + spring-web + + +

You are into browser version

+ + \ No newline at end of file diff --git a/spring-mobile/src/main/resources/templates/mobile/index.ftl b/spring-mobile/src/main/resources/templates/mobile/index.ftl new file mode 100644 index 0000000000..9f8fb1800b --- /dev/null +++ b/spring-mobile/src/main/resources/templates/mobile/index.ftl @@ -0,0 +1,10 @@ + + + + + spring-web + + +

You are into mobile version

+ + \ No newline at end of file diff --git a/spring-mobile/src/main/resources/templates/tablet/index.ftl b/spring-mobile/src/main/resources/templates/tablet/index.ftl new file mode 100644 index 0000000000..6bf51fcb69 --- /dev/null +++ b/spring-mobile/src/main/resources/templates/tablet/index.ftl @@ -0,0 +1,10 @@ + + + + + spring-web + + +

You are into tablet version

+ + \ No newline at end of file