spring-mobile

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 配置 html

<dependencies>     <dependency>         <groupId>org.springframework.mobile</groupId>         <artifactId>spring-mobile-device</artifactId>         <version>1.1.3.RELEASE</version>     </dependency> </dependencies>

使用方式 java

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

}
相关文章
相关标签/搜索