PR for spring-mobile (#1062)

* rest with spark java

* 4
This commit is contained in:
Abhinab Kanrar 2017-01-29 21:02:38 +05:30 committed by maibin
parent 1e74f9dbe8
commit d4c1ce44b6
8 changed files with 153 additions and 0 deletions

View File

@ -185,6 +185,7 @@
<module>xstream</module> <module>xstream</module>
<module>struts2</module> <module>struts2</module>
</modules> </modules>
</project> </project>

68
spring-mobile/pom.xml Normal file
View File

@ -0,0 +1,68 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId>
<artifactId>spring-mobile</artifactId>
<version>1.0-SNAPSHOT</version>
<name>spring-mobile</name>
<packaging>war</packaging>
<url>http://maven.apache.org</url>
<properties>
<java.version>1.8</java.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.mobile</groupId>
<artifactId>spring-mobile-device</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-releases</id>
<name>Spring Milestone Repository</name>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<name>Spring Milestone Repository</name>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
</project>

View File

@ -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);
}
}

View File

@ -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";
}
}

View File

@ -0,0 +1 @@
spring.mobile.devicedelegatingviewresolver.enabled: true

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>spring-web</title>
</head>
<body>
<h1>You are into browser version</h1>
</body>
</html>

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>spring-web</title>
</head>
<body>
<h1>You are into mobile version</h1>
</body>
</html>

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>spring-web</title>
</head>
<body>
<h1>You are into tablet version</h1>
</body>
</html>