首页>代码>Spring Boot整合Spring Mobile框架实现根据不同终端设备返回不同页面的实例>/device-resolution/src/main/java/com/memorynotfound/mobile/GreetingController.java
package com.memorynotfound.mobile; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.mobile.device.Device; import org.springframework.mobile.device.DeviceUtils; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import javax.servlet.http.HttpServletRequest; @Controller public class GreetingController { private static final Logger log = LoggerFactory.getLogger(GreetingController.class); @RequestMapping("/") public String greeting(Device device, HttpServletRequest request) { Device deviceFromRequest = DeviceUtils.getCurrentDevice(request); if (device.isMobile()) { log.info("Hello mobile user!"); } else if (device.isTablet()) { log.info("Hello tablet user!"); } else { log.info("Hello desktop user!"); } log.info("device: " + device); log.info("device form request: " + deviceFromRequest); log.info("device platform: " + device.getDevicePlatform()); return "greeting"; } }

ChenZheMeng LV3
2024年3月20日
graceful
2023年10月18日
暂无贡献等级
漫步的海星 LV4
2023年9月21日
aaronchan_chn LV6
2023年7月26日
1257592068 LV6
2023年6月13日
1515465193 LV9
2023年5月10日
yohohero LV1
2023年1月14日
xsxtxbb LV8
2022年10月10日
哎呀马吖 LV6
2022年8月25日
wy4525 LV6
2022年8月11日