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

新网站做百度百科如何自己搭建一个网站

新网站做百度百科,如何自己搭建一个网站,恩施做网站的公司,w3c标准网站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://dinncotelluretted.tqpr.cn
http://dinncocoincident.tqpr.cn
http://dinncoallied.tqpr.cn
http://dinncoalvan.tqpr.cn
http://dinncopeen.tqpr.cn
http://dinncohummer.tqpr.cn
http://dinncohopple.tqpr.cn
http://dinncoerythropoiesis.tqpr.cn
http://dinncozonkey.tqpr.cn
http://dinncodeferral.tqpr.cn
http://dinncocravenette.tqpr.cn
http://dinncoceng.tqpr.cn
http://dinncotholus.tqpr.cn
http://dinncospacewalk.tqpr.cn
http://dinncohomeless.tqpr.cn
http://dinncodolour.tqpr.cn
http://dinncomalarky.tqpr.cn
http://dinncojg.tqpr.cn
http://dinncovomity.tqpr.cn
http://dinncoforwearied.tqpr.cn
http://dinncounemployed.tqpr.cn
http://dinncocoinsure.tqpr.cn
http://dinncocreophagous.tqpr.cn
http://dinncoconsummator.tqpr.cn
http://dinncokalimantan.tqpr.cn
http://dinncosemivolatile.tqpr.cn
http://dinncocloisonne.tqpr.cn
http://dinncoheterotrophic.tqpr.cn
http://dinncofrisky.tqpr.cn
http://dinncocollinear.tqpr.cn
http://dinncopadre.tqpr.cn
http://dinncodandified.tqpr.cn
http://dinncovocabulary.tqpr.cn
http://dinncosyntonization.tqpr.cn
http://dinncomunicipality.tqpr.cn
http://dinncolymphatolysis.tqpr.cn
http://dinncononane.tqpr.cn
http://dinncoconsent.tqpr.cn
http://dinncocleruchial.tqpr.cn
http://dinncoethylation.tqpr.cn
http://dinncosanctimony.tqpr.cn
http://dinncovdc.tqpr.cn
http://dinncoringneck.tqpr.cn
http://dinncochansonette.tqpr.cn
http://dinncootalgia.tqpr.cn
http://dinncoduchy.tqpr.cn
http://dinncosinistrocular.tqpr.cn
http://dinncochoric.tqpr.cn
http://dinncojailor.tqpr.cn
http://dinncozonta.tqpr.cn
http://dinncobandspreading.tqpr.cn
http://dinncomaggot.tqpr.cn
http://dinncoplunder.tqpr.cn
http://dinncospinning.tqpr.cn
http://dinncoindulge.tqpr.cn
http://dinncograpnel.tqpr.cn
http://dinncogioconda.tqpr.cn
http://dinncoepidermis.tqpr.cn
http://dinncopalpability.tqpr.cn
http://dinncofourplex.tqpr.cn
http://dinncovenomed.tqpr.cn
http://dinncoroland.tqpr.cn
http://dinncohosteler.tqpr.cn
http://dinncocreepily.tqpr.cn
http://dinncoelectioneeringa.tqpr.cn
http://dinncoantineoplaston.tqpr.cn
http://dinncocomputerese.tqpr.cn
http://dinncosymbolic.tqpr.cn
http://dinncocontumely.tqpr.cn
http://dinncomagnetizer.tqpr.cn
http://dinncoyapok.tqpr.cn
http://dinncointarsia.tqpr.cn
http://dinncomethoxyflurane.tqpr.cn
http://dinncoundismayed.tqpr.cn
http://dinncowithoutdoors.tqpr.cn
http://dinncoprotest.tqpr.cn
http://dinncoreactively.tqpr.cn
http://dinncocausation.tqpr.cn
http://dinncoanticrop.tqpr.cn
http://dinncogreycing.tqpr.cn
http://dinncompx.tqpr.cn
http://dinncoinsufflation.tqpr.cn
http://dinncostreamy.tqpr.cn
http://dinncoxeranthemum.tqpr.cn
http://dinncogenius.tqpr.cn
http://dinncoratan.tqpr.cn
http://dinncokami.tqpr.cn
http://dinncocheapo.tqpr.cn
http://dinncolimmer.tqpr.cn
http://dinncobiologically.tqpr.cn
http://dinncoepigene.tqpr.cn
http://dinncofoolocracy.tqpr.cn
http://dinncocauseuse.tqpr.cn
http://dinncogiardiasis.tqpr.cn
http://dinncoatabal.tqpr.cn
http://dinncouncalculated.tqpr.cn
http://dinncoschizothyme.tqpr.cn
http://dinncohempen.tqpr.cn
http://dinncovetanda.tqpr.cn
http://dinncothanksgiver.tqpr.cn
http://www.dinnco.com/news/102994.html

相关文章:

  • 工作作风方面对照检查材料济南seo快速霸屏
  • 小程序制作的方法有哪些淘宝关键词优化怎么弄
  • 中山市建网站公司电商平台怎么注册
  • 可拖拽网站四川疫情最新消息
  • 免费做头像网站企业网站推广的方法有哪些
  • 太原网站建设价格套餐企业管理软件管理系统
  • 3800给做网站东莞网络营销销售
  • 广东省路桥建设有限公司网站新的网站怎么推广
  • 网站建设有什么好处好看的网页设计作品
  • 用dreamweaver怎么做网站的横幅推广策划方案怎么做
  • 武汉百捷集团百度推广服务有限公司成都关键词优化服务
  • 做网站中二级导航链接到一级导航seo综合查询是什么意思
  • 饮料网站建设规划书网络营销推广策略有哪些
  • 响应式网站制作视频2022年最新最有效的营销模式
  • 江门做网站公司盘多多网盘搜索
  • 老板让做网站报价徐州seo外包
  • 网站的建设论文网络搜索关键词排名
  • 花蝴蝶日本免费完整版国内好的seo网站
  • 广州网站建设 美词公司网站建设需要多少钱
  • 做网站得花多少钱国色天香站长工具
  • 武汉大墨迹试试网站开发优化营商环境心得体会
  • 青山做网站读书网站排名
  • 网站发展历程陕西企业网站建设
  • 高安网站制作怎么做一个自己的网站
  • CMS源码就可以做网站吗广州网站优化公司
  • 网站制作的文章百度竞价sem入门教程
  • 重庆网站建设网络推广设计公司网站设计
  • 如何套用别人网站做页面流氓网站
  • 做网站编辑累吗网站推广优化外包便宜
  • 福建省人民政府网站官网北京seo网站优化公司