JAVA-943: Migrate spring-mobile to parent-boot-2
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package com.baeldung;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.mobile.device.DeviceHandlerMethodArgumentResolver;
|
||||
import org.springframework.mobile.device.DeviceResolverHandlerInterceptor;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class AppConfig implements WebMvcConfigurer {
|
||||
|
||||
@Bean
|
||||
public DeviceResolverHandlerInterceptor deviceResolverHandlerInterceptor() {
|
||||
return new DeviceResolverHandlerInterceptor();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DeviceHandlerMethodArgumentResolver deviceHandlerMethodArgumentResolver() {
|
||||
return new DeviceHandlerMethodArgumentResolver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(deviceResolverHandlerInterceptor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
|
||||
argumentResolvers.add(deviceHandlerMethodArgumentResolver());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,13 +16,16 @@ public class IndexController {
|
||||
|
||||
String deviceType = "browser";
|
||||
String platform = "browser";
|
||||
String viewName = "index";
|
||||
|
||||
if (device.isNormal()) {
|
||||
deviceType = "browser";
|
||||
} else if (device.isMobile()) {
|
||||
deviceType = "mobile";
|
||||
viewName = "mobile/index";
|
||||
} else if (device.isTablet()) {
|
||||
deviceType = "tablet";
|
||||
viewName = "tablet/index";
|
||||
}
|
||||
|
||||
platform = device.getDevicePlatform().name();
|
||||
@@ -33,7 +36,7 @@ public class IndexController {
|
||||
|
||||
LOGGER.info("Client Device Type: " + deviceType + ", Platform: " + platform);
|
||||
|
||||
return "index";
|
||||
return viewName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user