当前位置: 首页 > 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://wiki.neutronadmin.com/news/139784/

相关文章:

  • 平面设计专业网站潍坊网站排名公司
  • 建设工程材料网站三水建设局网站
  • 张家港市住房城乡建设局网站蓝色企业网站模板
  • 网站开发分析网页制作网站建设
  • 网站模板文件扫描如何对网站进行管理
  • 微信网站如何做哪里有app项目开发
  • 建立手机个人网站python基础教程编程题
  • 广州建网站的网络公司企业网络推广外包
  • 网站建设 三乐大港建站公司
  • 建站如何赚钱如何通过网站自己做网站
  • dw建立网站之后怎么做wordpress 插件 证书
  • 常用的seo查询工具贵州企业seo
  • 成都网站制作哪家好托里县城乡建设局网站
  • 公司网站制作都需要图片设计师互动平台
  • 聊城网站备案登录器显的窗口网站怎么做
  • 怎么封闭网站佛山新网站建设服务
  • 高端网站建设专业公司微信网站制作公司哪家好
  • 怎么创建免费的个人网站国内免费产品发布网站
  • 投资集团网站建设方案中小学生教育网站建设方案
  • 杭州教育培训网站建设湖南做网站360o
  • wordpress主机高端的网站优化公司
  • 网站开发的相关语言有哪些互联网品牌有哪些
  • win7怎么做网站wordpress ie8不兼容
  • 容易被百度收录的网站网络游戏制作软件
  • 随州网站建设安徽平台网站建设公司
  • 怎么用dw做带登陆的网站html解析wordpress
  • 企业网站推广方法有哪些?网页编程入门
  • 宁波网站建设企业网站制作保定建站服务
  • 查询网站是否备案青州网站设计
  • 档案信息网站建设工作经验2018年公司网站建设费分录