Spring Mobile is an extension to the popular Spring Web MVC web framework that aims to simplify the development of mobile web applications.
Spring Mobile 提供了对 Spring MVC 的扩展,用于帮助开发跨平台的移动Web应用。
文档地址 : http://docs.spring.io/spring-mobile/docs/current/reference/htmlsingle/
spring-mobile功能
--客户端设备识别:识别结果只有3种类型:NORMAL(非手机设备)、MOBILE(手机设备)、TABLET(平板电脑)。在系统里可以通过以下代码获取设备识别结果:
Device currentDevice = DeviceUtils.getCurrentDevice(servletRequest);
--网站偏好设置:Spring 通过设备识别的结果来设置当前网站是NORMAL还是MOBILE。
最后 Spring Mobile会将信息同时放入cookie和request attribute里面。
-- 网站自动切换:可根据不同的访问设备切换到对应的页面
maven 配置
org.springframework.mobile
spring-mobile-device
1.1.3.RELEASE
使用方式
@Controller
public class HomeController {
private static final Logger logger =
LoggerFactory.getLogger(HomeController.class);
@RequestMapping("/")
public void home(Device device) {
if (device.isMobile()) {
logger.info("Hello mobile user!");
} else if (device.isTablet()) {
logger.info("Hello tablet user!");
} else {
logger.info("Hello desktop user!");
}
}
}