做电商要不要公司网站图片网站源码asp
- 作者: 多梦笔记
- 时间: 2026年02月16日 16:05
当前位置: 首页 > news >正文
做电商要不要公司网站,图片网站源码asp,传奇霸业网页版,html好看的个人主页1.什么是Spring Mobile#xff1f; Spring Mobile是一个基于Spring Web MVC框架扩展的一个针对不同移动终端的应用开发框架。通过它我们在适配不同终端方面#xff0c;就不用费劲心思了。 Spring Mobile的主要功能 自动设备检测: Spring Mobile在 server端内置了一个设备解…1.什么是Spring Mobile Spring Mobile是一个基于Spring Web MVC框架扩展的一个针对不同移动终端的应用开发框架。通过它我们在适配不同终端方面就不用费劲心思了。 Spring Mobile的主要功能 自动设备检测: Spring Mobile在 server端内置了一个设备解析器的抽象层。它会分析所有过来的请求然后侦测到设备信息比如设备的类型操作系统等等。网站偏好管理使用网站偏好管理Spring Mobile允许用户选择移动/平板电脑/网站的视图。 这是比较不赞成的技术因为通过使用DeviceDelegatingViewresolver我们可以根据设备类型跳转到对应的视图层而不需要来自用户端的任何输入。站点切换器站点切换器能够根据用户的设备类型比如手机平板浏览器等等将用户自动切换到最合适的视图。设备感知视图管理器通常根据设备类型我们将用户请求转发到特定站点以处理特定设备。 Spring Mobile的View Manager使开发人员能够灵活地将所有视图以预定义的格式显示出来Spring Mobile将根据设备类型自动管理不同的视图。 2.代码工程 实验目的 实验客户端类型识别 pom.xml ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdparentartifactIdspringboot-demo/artifactIdgroupIdcom.et/groupIdversion1.0-SNAPSHOT/version/parentmodelVersion4.0.0/modelVersionartifactIdSpringMobile/artifactIdpropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.targetspring-mobile-device.version1.1.5.RELEASE/spring-mobile-device.version/propertiesdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-autoconfigure/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependencydependencygroupIdorg.springframework.mobile/groupIdartifactIdspring-mobile-device/artifactIdversion${spring-mobile-device.version}/version/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-freemarker/artifactId/dependency/dependencies /project controller 判断客户端来源 package com.et.springmobile.controller;import java.util.logging.Logger;import org.springframework.mobile.device.Device; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;RestController 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;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();if (platform.equalsIgnoreCase(UNKNOWN)) {platform browser;}LOGGER.info(Client Device Type: deviceType , Platform: platform);return viewName;}} config Spring Boot自动注入了3个类DeviceResolverHandlerInterceptorSitePreferenceHandlerInterceptor和SitePreferenceMethodArgumentResolver。DeviceResolverHandlerInterceptor是HandlerInterceptor的一个实现从名字来看它拦截到应用的请求判断发送请求设备的类型。当设备解决以后SitePreferenceMethodArgumentResolver允许SpringMVC在Controller中使用SitePreference实体。在内部DeviceResolverHandlerInterceptor判断请求头中的User-Agent基于请求头中的值判断请求是否来自浏览器桌面、手机、还是Pad。 SitePreferenceHandlerInterceptor利用探测到的设备判断用户的初始站点偏好。如果用户喜欢另一个站点则选择该站点并在随后的请求中使用以覆盖已解析的设备值。站点偏好是通过请求中特殊的查询字符串设置的。一旦接收到偏好将被持久化到cookie中以供将来参考。站点偏好功能在Spring Boot中默认是打开的可以通过上面的设置关闭它。 package com.et.springmobile;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 {Beanpublic DeviceResolverHandlerInterceptor deviceResolverHandlerInterceptor() {return new DeviceResolverHandlerInterceptor();}Beanpublic DeviceHandlerMethodArgumentResolver deviceHandlerMethodArgumentResolver() {return new DeviceHandlerMethodArgumentResolver();}Overridepublic void addInterceptors(InterceptorRegistry registry) {registry.addInterceptor(deviceResolverHandlerInterceptor());}Overridepublic void addArgumentResolvers(ListHandlerMethodArgumentResolver argumentResolvers) {argumentResolvers.add(deviceHandlerMethodArgumentResolver());}} DemoApplication.java package com.et.springmobile;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;SpringBootApplication public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);} } application.properties spring.mobile.devicedelegatingviewresolver.enabled: true spring.freemarker.template-loader-path: classpath:/templates spring.freemarker.suffix: .ftl 以上只是一些关键代码所有代码请参见下面代码仓库 代码仓库 GitHub - Harries/springboot-demo: a simple springboot demo with some components for example: redis,solr,rockmq and so on. 3.测试 启动Spring Boot应用 测试来源 访问http://127.0.0.1:8080/使用chrome 模拟不同的客户端console日志输出如下 21:47:42.341 [http-nio-8080-exec-1] INFO o.s.web.servlet.DispatcherServlet - Completed initialization in 40 ms 21:47:42.430 [http-nio-8080-exec-1] INFO c.e.s.controller.IndexController - Client Device Type: browser, Platform: browser 21:49:10.378 [http-nio-8080-exec-5] INFO c.e.s.controller.IndexController - Client Device Type: mobile, Platform: ANDROID 21:49:21.414 [http-nio-8080-exec-6] INFO c.e.s.controller.IndexController - Client Device Type: mobile, Platform: ANDROID 21:49:35.192 [http-nio-8080-exec-7] INFO c.e.s.controller.IndexController - Client Device Type: mobile, Platform: IOS 21:49:51.647 [http-nio-8080-exec-8] INFO c.e.s.controller.IndexController - Client Device Type: mobile, Platform: IOS 4.引用 Spring Mobile Reference DocumentationSpring Boot集成Spring Mobile快速入门Demo | Harries Blog™
相关文章
-
做电商网站用什么软件wordpress 当前分类链接
做电商网站用什么软件wordpress 当前分类链接
- 站长
- 2026年02月16日
-
做电商网站需要注意哪些网站和域名有关系吗
做电商网站需要注意哪些网站和域名有关系吗
- 站长
- 2026年02月16日
-
做电商网站需要会些什么问题大学生网页设计作业教程
做电商网站需要会些什么问题大学生网页设计作业教程
- 站长
- 2026年02月16日
-
做电商要注册网站吗北京建设质量协会网站
做电商要注册网站吗北京建设质量协会网站
- 站长
- 2026年02月16日
-
做电商一件代发的网站单位网站建设 管理制度
做电商一件代发的网站单位网站建设 管理制度
- 站长
- 2026年02月16日
-
做电商有哪些网站昆山app网站制作
做电商有哪些网站昆山app网站制作
- 站长
- 2026年02月16日
