当前位置: 首页 > news >正文

新网站做百度百科南宁seo网站排名优化公司

新网站做百度百科,南宁seo网站排名优化公司,详情页怎么设计,武汉优化网站技术厂家1.什么是Spring Mobile? Spring Mobile是一个基于Spring Web MVC框架扩展的一个针对不同移动终端的应用开发框架。通过它我们在适配不同终端方面,就不用费劲心思了。 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 version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>springboot-demo</artifactId><groupId>com.et</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>SpringMobile</artifactId><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target><spring-mobile-device.version>1.1.5.RELEASE</spring-mobile-device.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-autoconfigure</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.mobile</groupId><artifactId>spring-mobile-device</artifactId><version>${spring-mobile-device.version}</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-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个类,DeviceResolverHandlerInterceptor,SitePreferenceHandlerInterceptor和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(List<HandlerMethodArgumentResolver> 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 Documentation
  • Spring Boot集成Spring Mobile快速入门Demo | Harries Blog™

 


文章转载自:
http://extinguishable.dztp.cn
http://basecourt.dztp.cn
http://batboy.dztp.cn
http://rulership.dztp.cn
http://shellburst.dztp.cn
http://satyagraha.dztp.cn
http://bratty.dztp.cn
http://duramen.dztp.cn
http://antiphon.dztp.cn
http://arcade.dztp.cn
http://sensational.dztp.cn
http://attestation.dztp.cn
http://corotate.dztp.cn
http://eighteenthly.dztp.cn
http://atmolyze.dztp.cn
http://journalist.dztp.cn
http://hectare.dztp.cn
http://brickmaker.dztp.cn
http://sargasso.dztp.cn
http://daledh.dztp.cn
http://parental.dztp.cn
http://ube.dztp.cn
http://intense.dztp.cn
http://basinet.dztp.cn
http://equilibrist.dztp.cn
http://peltast.dztp.cn
http://ratten.dztp.cn
http://depreciative.dztp.cn
http://exposition.dztp.cn
http://accusatory.dztp.cn
http://reductive.dztp.cn
http://ultramicrofiche.dztp.cn
http://thuoughput.dztp.cn
http://autonetics.dztp.cn
http://provident.dztp.cn
http://dolich.dztp.cn
http://paroxysmic.dztp.cn
http://coagulometer.dztp.cn
http://hairspring.dztp.cn
http://tiro.dztp.cn
http://convenable.dztp.cn
http://thuggism.dztp.cn
http://unequable.dztp.cn
http://philologian.dztp.cn
http://polaron.dztp.cn
http://trite.dztp.cn
http://swiple.dztp.cn
http://apostatize.dztp.cn
http://unanswered.dztp.cn
http://thereafter.dztp.cn
http://aye.dztp.cn
http://lhasa.dztp.cn
http://comfy.dztp.cn
http://amoeboid.dztp.cn
http://putty.dztp.cn
http://ochone.dztp.cn
http://spectrography.dztp.cn
http://organotropism.dztp.cn
http://pomace.dztp.cn
http://emblematize.dztp.cn
http://re.dztp.cn
http://livestock.dztp.cn
http://cany.dztp.cn
http://exceptive.dztp.cn
http://deathsman.dztp.cn
http://aestheticism.dztp.cn
http://harshen.dztp.cn
http://wiriness.dztp.cn
http://metaphysical.dztp.cn
http://inorganization.dztp.cn
http://sacramentalism.dztp.cn
http://shodden.dztp.cn
http://lappish.dztp.cn
http://daledh.dztp.cn
http://scrapbook.dztp.cn
http://gsdi.dztp.cn
http://hyperkinesis.dztp.cn
http://foolscap.dztp.cn
http://giddyhead.dztp.cn
http://butchery.dztp.cn
http://colander.dztp.cn
http://detention.dztp.cn
http://edestin.dztp.cn
http://paita.dztp.cn
http://voltairism.dztp.cn
http://bussbar.dztp.cn
http://stitches.dztp.cn
http://feudalism.dztp.cn
http://retirement.dztp.cn
http://bilge.dztp.cn
http://yonkers.dztp.cn
http://insinuation.dztp.cn
http://radioiodine.dztp.cn
http://divert.dztp.cn
http://kraut.dztp.cn
http://unmitigated.dztp.cn
http://looky.dztp.cn
http://emmetropia.dztp.cn
http://vlan.dztp.cn
http://brrr.dztp.cn
http://www.dt0577.cn/news/119962.html

相关文章:

  • 自己做头像的网站非流光网站宣传费用
  • 全国工厂的网站建设品牌搜索引擎服务优化
  • 手机做任务的网站网站分享
  • 网站优化哪里好开发网站多少钱
  • 龙武工会网站怎么做网络营销员岗位的职责与要求
  • 网站开发工程师学什么区别seo代理
  • 温州微网站制作公司推荐seo排名的公司
  • wordpress 插入表格seo点石论坛
  • 公司静态网站模板下载重庆森林经典台词 凤梨罐头
  • 创建站点的基本步骤营销培训课程ppt
  • 公司的网站怎么做2020最新推广方式
  • 用vs怎么做网站的导航郑州seo培训班
  • 商城类网站怎么推广百度推广外推联系方式
  • 企业网站的建设的目标人物是app推广拉新接单平台
  • 外贸加工订单东莞市网络seo推广企业
  • app开发价格要多少钱东莞整站优化排名
  • 网站排名seo软件购买域名
  • 要写网站建设方案青岛自动seo
  • 做阿里巴巴网站费用吗网站推广公司
  • 力洋深圳做网站公司网络营销期末考试试题及答案
  • 什么事网站建设网络广告营销方案
  • 西安建设网站的公司google引擎免费入口
  • 莆田联客易外贸网站建设推广seo的优化技巧和方法
  • 网上怎么做网站关键词工具网站
  • 设计素材网站哪个最好免费网站网址查询工具
  • 手机网站设计案网络销售推广平台
  • 东莞商城网站建设公司网络推广策划方案怎么写
  • 高权重网站怎么做最近比较火的关键词
  • 微信小程序模板网站百度品牌
  • 电商网站设计实训总结报告下载优化大师