parent
1e74f9dbe8
commit
d4c1ce44b6
1
pom.xml
1
pom.xml
|
@ -185,6 +185,7 @@
|
|||
<module>xstream</module>
|
||||
|
||||
<module>struts2</module>
|
||||
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -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>
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
spring.mobile.devicedelegatingviewresolver.enabled: true
|
|
@ -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>
|
|
@ -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>
|
|
@ -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>
|
Loading…
Reference in New Issue