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

网站建设有什么要求如何提高网站响应速度

网站建设有什么要求,如何提高网站响应速度,网站模块标准版,最近免费高清观看mvjava spr显然#xff0c;编写URL缩短服务是新的“ Hello#xff0c;world#xff01; ”在IoT /微服务/时代的世界中。 一切始于在45行Scala中的URL缩短服务 -整洁的Scala#xff0c;以Spray和Redis进行调味以进行存储。 紧随其后的是#xff0c; 在35行Clojure中提供了ur… java spr 显然编写URL缩短服务是新的“ Helloworld ”在IoT /微服务/时代的世界中。 一切始于在45行Scala中的URL缩短服务 -整洁的Scala以Spray和Redis进行调味以进行存储。 紧随其后的是 在35行Clojure中提供了url缩短服务 甚至在Haskell的43行中提供了URL缩短服务 。 所以我内心的反时髦人士问用Java语言要花多长时间 但是出于善意不是普通的Java。 带有Spring Data Redis的 Spring Boot是一个很好的起点。 我们需要的只是一个处理GET和POST的简单控制器 import com.google.common.hash.Hashing; import org.apache.commons.validator.routines.UrlValidator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.http.*; import org.springframework.web.bind.annotation.*;import javax.servlet.http.*; import java.nio.charset.StandardCharsets;org.springframework.boot.autoconfigure.EnableAutoConfiguration org.springframework.stereotype.Controller public class UrlShortener {public static void main(String[] args) {SpringApplication.run(UrlShortener.class, args);}Autowired private StringRedisTemplate redis;RequestMapping(value /{id}, method RequestMethod.GET)public void redirect(PathVariable String id, HttpServletResponse resp) throws Exception {final String url redis.opsForValue().get(id);if (url ! null)resp.sendRedirect(url);elseresp.sendError(HttpServletResponse.SC_NOT_FOUND);}RequestMapping(method RequestMethod.POST)public ResponseEntityString save(HttpServletRequest req) {final String queryParams (req.getQueryString() ! null) ? ? req.getQueryString() : ;final String url (req.getRequestURI() queryParams).substring(1);final UrlValidator urlValidator new UrlValidator(new String[]{http, https});if (urlValidator.isValid(url)) {final String id Hashing.murmur3_32().hashString(url, StandardCharsets.UTF_8).toString();redis.opsForValue().set(id, url);return new ResponseEntity(http://mydomain.com/ id, HttpStatus.OK);} elsereturn new ResponseEntity(HttpStatus.BAD_REQUEST);} } 该代码很好地自我描述并且在功能上等同于Scala中的版本。 我没有尝试过太多的压缩以使行数尽可能的短上面的代码很典型只有很少的细节 我通常不使用通配符导入 我不使用完全限定的类名我承认我想保存一个import行 我用if括号包围if else用括号括起来 我几乎从不使用场注入这是控制家族反转中最丑陋的兄弟。 相反我会去让构造函数允许使用模拟的Redis进行测试 Autowired private final StringRedisTemplate redis;public UrlShortener(StringRedisTemplate redis) {this.redis redis; } 我最苦恼的事情是……获取原始的完整URL。 基本上我需要.com或port之后的所有内容。 没有流血的方式既没有servlet也没有Spring MVC因此笨拙的getQueryString()摆弄着。 您可以按以下方式使用该服务-创建较短的URL $ curl -vX POST localhost:8080/https://www.google.pl/search?qtomasznurkiewicz POST /https://www.google.pl/search?qtomasznurkiewicz HTTP/1.1User-Agent: curl/7.30.0Host: localhost:8080Accept: */*HTTP/1.1 200 OKServer: Apache-Coyote/1.1Content-Type: text/plain;charsetISO-8859-1Content-Length: 28Date: Sat, 23 Aug 2014 20:47:40 GMThttp://mydomain.com/50784f51 通过较短的URL重定向 $ curl -v localhost:8080/50784f51 GET /50784f51 HTTP/1.1User-Agent: curl/7.30.0Host: localhost:8080Accept: */*HTTP/1.1 302 FoundServer: Apache-Coyote/1.1Location: https://www.google.pl/search?qtomasznurkiewiczContent-Length: 0Date: Sat, 23 Aug 2014 20:48:00 GMT为了完整起见这是Gradle中的一个构建文件maven也可以使用在所有以前的解决方案中都跳过了 buildscript {repositories {mavenLocal()maven { url http://repo.spring.io/libs-snapshot }mavenCentral()}dependencies {classpath org.springframework.boot:spring-boot-gradle-plugin:1.1.5.RELEASE} }apply plugin: java apply plugin: spring-bootsourceCompatibility 1.8repositories {mavenLocal()maven { url http://repository.codehaus.org }maven { url http://repo.spring.io/milestone }mavenCentral() }dependencies {compile org.springframework.boot:spring-boot-starter-web:1.1.5.RELEASEcompile org.springframework.boot:spring-boot-starter-redis:1.1.5.RELEASEcompile com.google.guava:guava:17.0compile org.apache.commons:commons-lang3:3.3.2compile commons-validator:commons-validator:1.4.0compile org.apache.tomcat.embed:tomcat-embed-el:8.0.9compile org.aspectj:aspectjrt:1.8.1runtime cglib:cglib-nodep:3.1 }tasks.withType(GroovyCompile) {groovyOptions.optimizationOptions.indy true }task wrapper(type: Wrapper) {gradleVersion 2.0 } 实际上也是42行...这就是整个应用程序没有XML没有描述符没有安装。 对于最短最模糊的工作代码我不认为此练习只是一个虚拟的代码。 带有Redis后端的URL缩短器Web服务是给定语言和生态系统的语法和功能的有趣展示。 有趣的是还有很多算法问题例如Rosetta代码中发现的问题。 这也是编写REST服务的一个很好的最低限度模板。 原始Scala实现的一个重要功能包括该实现在所有实现中都以某种方式被默默地忘记了它是非阻塞的。 HTTP和Redis的访问是事件驱动的 React 没事我说所以我想它可以同时处理客户数以万计。 阻止由Tomcat支持的控制器无法实现这一点。 但是您仍然必须承认这种用Java编写的服务甚至不是Java 8简明扼要易于遵循和简单明了-其他解决方案都不是可读的这当然是主观的。 等待别人 翻译自: https://www.javacodegeeks.com/2014/08/url-shortener-service-in-42-lines-of-code-in-java-spring-boot-redis.htmljava spr
http://www.sadfv.cn/news/139784/

相关文章:

  • 海外购物网站建设百度2022最新版本
  • 郑州网站建设找汉狮网站托管主要干点什么
  • 外包网站建设哪家好面包网站seo
  • 国企网站开发做网站用哪个笔记本
  • 辽宁工程新希望官网上海优化外包公司排名
  • 顺德佛山做app网站手机网站开发需求 百度云盘
  • 佛山网站建站推广网站关键词几个合适
  • 佛山专业网站建设网站建设教程在线观看
  • 宣传网站制作方案深圳知名设计公司有哪些
  • 乌海学校网站建设外贸网站国际化怎么做
  • 新宁县建设局网站深圳宝安美容医院网站建设
  • 公司网站被百度收录免费的舆情网站不用下载直接打开
  • 大学生网站建设实训报告广州做网站哪里有
  • 群晖nas建设网站网站建设开发设计营销公司山东
  • 建设银行的网站用户名是什么问题青岛网站设计公司
  • 建设一个企业网站怎么给网站做 360快照
  • 网站的开发工具微信商城开发商华网天下优秀
  • wordpress时间南宁关键词优化软件
  • 国外做网站卖东西要什么条件国家企业信息系统官方
  • 广州专业做网站建设有做挂名法人和股东的网站吗
  • 域名备案网站建设书模板游戏介绍网站模板下载
  • 崇卅市网站建设博客网站开发环境
  • 创意礼品做的比较好的网站网站系统怎么用
  • 免费个人网站建设大全四川建设厅网站打不开
  • 公司网站备案怎么做广东省优质高职院校建设网站
  • 电脑课做网站所需的软件福建泉州网站建设公司哪家好
  • 辽宁高速公路建设局网站镇海seo专业优化平台
  • 免费室内设计网站都有哪些绵阳最有实力的公司网站建设
  • 凡科网站产品导航怎么做会员发布网站建设
  • 网站开发模板代码设计师的个人网站