Google App Engine上的Spring MVC和REST

前段時間,我寫了一篇關于如何使用Spring MVC實現Restful Web API的文章 。 閱讀我以前的文章以了解它。

在那篇文章中,開發了一個簡單的Rest示例。 為了測試該應用程序,將文件復制到Web服務器(例如Tomcat )中,然后返回對字符1的http:// localhost:8080 / RestServer / characters / 1信息的訪問。

在當前文章中,我將解釋如何將應用程序轉換為Google App Engine并使用Maven部署到Google的基礎架構中。 當然,在這種情況下,我們將部署Rest Spring MVC應用程序,但是可以使用相同的方法將Spring MVC Web應用程序(或使用其他Web框架開發的任何其他應用程序)遷移到GAE。

首先,顯然,您應該創建一個Google帳戶并注冊一個新的應用程序 (記住名稱,因為它將在下一步中使用)。 之后,您可以開始遷移。

需要進行三個更改,創建定義應用程序名稱的appengine-web.xml ; 使用Google帳戶信息將服務器標記添加到settings.xml,并修改pom.xml以添加GAE插件及其依賴項。

讓我們從appengine-web.xml開始。 GAE使用此文件來配置應用程序,并將其創建到WEB-INF目錄(與web.xml處于同一級別)。

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://appengine.google.com/ns/1.0 http://googleappengine.googlecode.com/svn/branches/1.2.1/java/docs/appengine-web.xsd"><application>alexsotoblog</application><version>1</version><system-properties><property name="java.util.logging.config.file" value="WEB-INF/classes/logging.properties"/></system-properties><precompilation-enabled>false</precompilation-enabled><sessions-enabled>true</sessions-enabled>
</appengine-web-app>

最重要的字段是應用程序標簽。 此標記包含我們應用程序的名稱(在您注冊新的Google應用程序時定義)。

其他標簽包括版本,系統屬性和環境變量以及其他配置,例如您是否希望預編譯以提高性能或應用程序需要會話。

而且您的項目不再需要修改,現在僅會觸摸Maven文件。

settings.xml中 ,應該添加帳戶信息:

<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd"><localRepository>/media/share/maven_repo</localRepository><servers><server><id>appengine.google.com</id><username>my_account@gmail.com</username><password>my_password</password></server></servers></settings>

看到這和在Maven中注冊任何其他服務器一樣容易。

最后是最繁瑣的部分,修改pom.xml

首先要添加新屬性:

<gae.home>/media/share/maven_repo/com/google/appengine/appengine-java-sdk/1.5.5/appengine-java-sdk-1.5.5</gae.home>
<gaeApplicationName>alexsotoblog</gaeApplicationName>
<gaePluginVersion>0.9.0</gaePluginVersion>
<gae.version>1.5.5</gae.version><!-- Upload to http://test.latest.<applicationName>.appspot.com by default -->
<gae.application.version>test</gae.application.version>

在第一行中,我們定義了Appengine Java SDK的位置。 如果已經安裝,則在此標記中插入位置,如果沒有,則復制此pom的相同位置,然后將maven存儲庫目錄(在我的情況下為/ media / share / maven_repo)更改為您的目錄。 通常,您的Maven存儲庫位置為/home/user/.m2/repositoriesMaven將在部署時為您下載SDK

下一步是添加Maven GAE存儲庫。

<repositories><repository><id>maven-gae-plugin-repo</id><url>http://maven-gae-plugin.googlecode.com/svn/repository</url><name>maven-gae-plugin repository</name></repository>
</repositories><pluginRepositories><pluginRepository><id>maven-gae-plugin-repo</id><name>Maven Google App Engine Repository</name><url>http://maven-gae-plugin.googlecode.com/svn/repository/</url></pluginRepository>
</pluginRepositories>

因為我們的項目是虛擬項目, 所以不使用Datanucleus 。 對于更復雜的項目,需要使用例如JDO進行數據庫訪問,應添加下一個依賴項:

<dependency><groupId>javax.jdo</groupId><artifactId>jdo2-api</artifactId><version>2.3-eb</version><exclusions><exclusion><groupId>javax.transaction</groupId><artifactId>transaction-api</artifactId></exclusion></exclusions>
</dependency><dependency><groupId>com.google.appengine.orm</groupId><artifactId>datanucleus-appengine</artifactId><version>1.0.6.final</version>
</dependency><dependency><groupId>org.datanucleus</groupId><artifactId>datanucleus-core</artifactId><version>1.1.5</version><scope>runtime</scope><exclusions><exclusion><groupId>javax.transaction</groupId><artifactId>transaction-api</artifactId></exclusion></exclusions>
</dependency><dependency><groupId>com.google.appengine</groupId><artifactId>geronimo-jta_1.1_spec</artifactId><version>1.1.1</version><scope>runtime</scope>
</dependency><dependency><groupId>com.google.appengine</groupId><artifactId>geronimo-jpa_3.0_spec</artifactId><version>1.1.1</version><scope>runtime</scope>
</dependency>

如果您使用的是Datanucleus ,則應注冊maven-datanucleus-plugin 。 請注意根據您的項目正確配置它。

<plugin><groupId>org.datanucleus</groupId><artifactId>maven-datanucleus-plugin</artifactId><version>1.1.4</version><configuration><!--Make sure this path contains your persistentclasses!--><mappingIncludes>**/model/*.class</mappingIncludes><verbose>true</verbose><enhancerName>ASM</enhancerName><api>JDO</api></configuration><executions><execution><phase>compile</phase><goals><goal>enhance</goal></goals></execution></executions><dependencies><dependency><groupId>org.datanucleus</groupId><artifactId>datanucleus-core</artifactId><version>1.1.5</version><exclusions><exclusion><groupId>javax.transaction</groupId><artifactId>transaction-api</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.datanucleus</groupId><artifactId>datanucleus-rdbms</artifactId><version>1.1.5</version></dependency><dependency><groupId>org.datanucleus</groupId><artifactId>datanucleus-enhancer</artifactId><version>1.1.5</version></dependency></dependencies>
</plugin>

現在,添加了Google App Engine依賴項。

<dependency><groupId>com.google.appengine</groupId><artifactId>appengine-api-1.0-sdk</artifactId><version>${gae.version}</version>
</dependency><dependency><groupId>com.google.appengine</groupId><artifactId>appengine-tools-api</artifactId><version>1.3.7</version>
</dependency>

然后,如果您想測試GAE 功能 (在我們的虛擬項目中未使用),則添加下一個GAE庫:

<dependency><groupId>com.google.appengine</groupId><artifactId>appengine-api-labs</artifactId><version>${gae.version}</version><scope>test</scope>
</dependency><dependency><groupId>com.google.appengine</groupId><artifactId>appengine-api-stubs</artifactId><version>${gae.version}</version><scope>test</scope>
</dependency><dependency><groupId>com.google.appengine</groupId><artifactId>appengine-testing</artifactId><version>${gae.version}</version><scope>test</scope>
</dependency>

接下來的更改是對maven-war-plugin的修改,其中將appengine-web.xml包含到生成的包中:

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><configuration><webResources><resource><directory>src/main/webapp</directory><filtering>true</filtering><includes><include>**/appengine-web.xml</include></includes></resource></webResources></configuration>
</plugin>

最后添加maven-gae-plugin并將其配置為將應用程序上傳到appspot

<plugin><groupId>net.kindleit</groupId><artifactId>maven-gae-plugin</artifactId><version>${gaePluginVersion}</version><configuration><serverId>appengine.google.com</serverId></configuration><dependencies><dependency><groupId>net.kindleit</groupId><artifactId>gae-runtime</artifactId><version>${gae.version}</version><type>pom</type></dependency></dependencies>
</plugin>

看到<serviceId>標記包含先前在settings.xml文件中定義的服務器名稱。

另外,如果您使用的是maven-release-plugin ,則可以在release:perform目標期間將應用程序自動上傳到appspot

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-release-plugin</artifactId><version>2.2.1</version><configuration><goals>gae:deploy</goals></configuration>
</plugin>

現在運行gae:deploy目標。 如果您已經安裝了Appengine Java SDK ,那么您的應用程序將被上傳到您的GAE網站。 但是,如果這是您第一次運行該插件,則會收到錯誤消息。 不要驚慌,發生此錯誤是因為Maven插件未在您在<gae.home>標記中指定的目錄中找到Appengine SDK 。 但是,如果您已將gae.home位置配置到本地Maven存儲庫中,只需運行gae:unpack目標,即可正確安裝SDK ,因此當您重新運行gae:deploy時,您的應用程序將上傳到Google基礎架構中。

在后例子中,你可以去http://alexsotoblog.appspot.com/characters/1http://alexsotoblog.appspot.com/characters/1和JSON格式字符信息顯示到瀏覽器中。

正如我在文章開頭提到的那樣,相同的過程可以用于任何Web應用程序,而不僅僅是Spring Rest MVC

由于教學目的,對應用程序pom進行了所有修改。 我的建議是,您要使用GAE相關標簽創建父pom ,因此必須上傳到Google App Engine的每個項目都來自同一pom文件。

我希望您發現這篇文章有用。

本周,我在devoxx ,在那與我見面;)我將在17日(星期四)13:00發表有關通過聚合和最小化加速Javascript和CSS下載時間的演講 。

完整的pom文件:

<?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/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.springframework</groupId><artifactId>rest</artifactId><name>Rest</name><packaging>war</packaging><version>1.0.0-BUILD-SNAPSHOT</version><properties><java-version>1.6</java-version><org.springframework-version>3.0.4.RELEASE</org.springframework-version><org.aspectj-version>1.6.9</org.aspectj-version><org.slf4j-version>1.5.10</org.slf4j-version><!-- Specify AppEngine version for your project. It should match SDK version pointed to by ${gae.home} property (Typically, one used by your Eclipse plug-in) --><gae.home>/home/alex/.m2/repository/com/google/appengine/appengine-java-sdk/1.5.5/appengine-java-sdk-1.5.5</gae.home><gaeApplicationName>alexsotoblog</gaeApplicationName><gaePluginVersion>0.9.0</gaePluginVersion><gae.version>1.5.5</gae.version><!-- Upload to http://test.latest.<applicationName>.appspot.com by default --><gae.application.version>test</gae.application.version></properties><dependencies><!-- Rest --><dependency><groupId>com.sun.xml.bind</groupId><artifactId>jaxb-impl</artifactId><version>2.2.4-1</version></dependency><dependency><groupId>org.codehaus.jackson</groupId><artifactId>jackson-core-lgpl</artifactId><version>1.8.5</version></dependency><dependency><groupId>org.codehaus.jackson</groupId><artifactId>jackson-mapper-lgpl</artifactId><version>1.8.5</version></dependency><!-- GAE libraries for local testing as described here: http://code.google.com/appengine/docs/java/howto/unittesting.html --><dependency><groupId>com.google.appengine</groupId><artifactId>appengine-api-labs</artifactId><version>${gae.version}</version><scope>test</scope></dependency><dependency><groupId>com.google.appengine</groupId><artifactId>appengine-api-stubs</artifactId><version>${gae.version}</version><scope>test</scope></dependency><dependency><groupId>com.google.appengine</groupId><artifactId>appengine-testing</artifactId><version>${gae.version}</version><scope>test</scope></dependency><dependency><groupId>com.google.appengine</groupId><artifactId>appengine-api-1.0-sdk</artifactId><version>${gae.version}</version></dependency><dependency><groupId>com.google.appengine</groupId><artifactId>appengine-tools-api</artifactId><version>1.3.7</version></dependency><!-- Spring --><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>${org.springframework-version}</version><exclusions><!-- Exclude Commons Logging in favor of SLF4j --><exclusion><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>${org.springframework-version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-oxm</artifactId><version>${org.springframework-version}</version></dependency><!-- AspectJ --><dependency><groupId>org.aspectj</groupId><artifactId>aspectjrt</artifactId><version>${org.aspectj-version}</version></dependency><!-- Logging --><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>${org.slf4j-version}</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>jcl-over-slf4j</artifactId><version>${org.slf4j-version}</version><scope>runtime</scope></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>${org.slf4j-version}</version><scope>runtime</scope></dependency><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.15</version><exclusions><exclusion><groupId>javax.mail</groupId><artifactId>mail</artifactId></exclusion><exclusion><groupId>javax.jms</groupId><artifactId>jms</artifactId></exclusion><exclusion><groupId>com.sun.jdmk</groupId><artifactId>jmxtools</artifactId></exclusion><exclusion><groupId>com.sun.jmx</groupId><artifactId>jmxri</artifactId></exclusion></exclusions><scope>runtime</scope></dependency><!-- @Inject --><dependency><groupId>javax.inject</groupId><artifactId>javax.inject</artifactId><version>1</version></dependency><!-- Servlet --><dependency><groupId>javax.servlet</groupId><artifactId>servlet-api</artifactId><version>2.5</version><scope>provided</scope></dependency><dependency><groupId>javax.servlet.jsp</groupId><artifactId>jsp-api</artifactId><version>2.1</version><scope>provided</scope></dependency><dependency><groupId>javax.servlet</groupId><artifactId>jstl</artifactId><version>1.2</version></dependency><!-- Test --><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.7</version><scope>test</scope></dependency></dependencies><repositories><!-- For testing against latest Spring snapshots --><repository><id>org.springframework.maven.snapshot</id><name>Spring Maven Snapshot Repository</name><url>http://maven.springframework.org/snapshot</url><releases><enabled>false</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository><!-- For developing against latest Spring milestones --><repository><id>org.springframework.maven.milestone</id><name>Spring Maven Milestone Repository</name><url>http://maven.springframework.org/milestone</url><snapshots><enabled>false</enabled></snapshots></repository><!-- GAE repositories --><repository><id>maven-gae-plugin-repo</id><url>http://maven-gae-plugin.googlecode.com/svn/repository</url><name>maven-gae-plugin repository</name></repository></repositories><pluginRepositories><pluginRepository><id>maven-gae-plugin-repo</id><name>Maven Google App Engine Repository</name><url>http://maven-gae-plugin.googlecode.com/svn/repository/</url></pluginRepository></pluginRepositories><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>${java-version}</source><target>${java-version}</target></configuration></plugin><!-- Adding appengine-web into war --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><configuration><webResources><resource><directory>src/main/webapp</directory><filtering>true</filtering><includes><include>**/appengine-web.xml</include></includes></resource></webResources><warName>abc</warName></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-dependency-plugin</artifactId><executions><execution><id>install</id><phase>install</phase><goals><goal>sources</goal></goals></execution></executions></plugin><plugin><groupId>org.codehaus.mojo</groupId><artifactId>aspectj-maven-plugin</artifactId><!-- Have to use version 1.2 since version 1.3 does not appear to work with ITDs --><version>1.2</version><dependencies><!-- You must use Maven 2.0.9 or above or these are ignored (see MNG-2972) --><dependency><groupId>org.aspectj</groupId><artifactId>aspectjrt</artifactId><version>${org.aspectj-version}</version></dependency><dependency><groupId>org.aspectj</groupId><artifactId>aspectjtools</artifactId><version>${org.aspectj-version}</version></dependency></dependencies><executions><execution><goals><goal>compile</goal><goal>test-compile</goal></goals></execution></executions><configuration><outxml>true</outxml><source>${java-version}</source><target>${java-version}</target></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><configuration><junitArtifactName>junit:junit</junitArtifactName></configuration></plugin><plugin><groupId>org.codehaus.mojo</groupId><artifactId>tomcat-maven-plugin</artifactId><version>1.0-beta-1</version></plugin><!-- The actual maven-gae-plugin. Type "mvn gae:run" to run project, "mvn gae:deploy" to upload to GAE. --><plugin><groupId>net.kindleit</groupId><artifactId>maven-gae-plugin</artifactId><version>${gaePluginVersion}</version><configuration><serverId>appengine.google.com</serverId></configuration><dependencies><dependency><groupId>net.kindleit</groupId><artifactId>gae-runtime</artifactId><version>${gae.version}</version><type>pom</type></dependency></dependencies></plugin></plugins></build>
</project>

下載代碼。
音樂: http : //www.youtube.com/watch?v = Nba3Tr_GLZU

參考:來自JCG合作伙伴 Alex Soto 在Google App Engine上的Spring MVC和REST,來自One Jar To Rule All All博客。

相關文章 :

  • 使用Spring MVC開發Restful Web服務
  • Spring MVC開發–快速教程
  • jqGrid,REST,AJAX和Spring MVC集成
  • 使用Spring 3.1和基于Java的配置構建RESTful Web服務,第2部分
  • Spring MVC3 Hibernate CRUD示例應用程序
  • Google AppEngine(GAE)中的多租戶

翻譯自: https://www.javacodegeeks.com/2011/12/spring-mvc-and-rest-at-google-app.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/374061.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/374061.shtml
英文地址,請注明出處:http://en.pswp.cn/news/374061.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

SALT+HASH撒鹽加密

#region 撒鹽加密string salt Guid.NewGuid().ToString();byte[] passwordAndSaltBytes System.Text.Encoding.UTF8.GetBytes(model.Password salt);byte[] hashBytes new System.Security.Cryptography.SHA256Managed().ComputeHash(passwordAndSaltBytes);string hashStr…

python 子串是否在字符串中_python七種方法判斷字符串是否包含子串

1. 使用 in 和 not inin 和 not in 在 Python 中是很常用的關鍵字&#xff0c;我們將它們歸類為 成員運算符。使用這兩個成員運算符&#xff0c;可以很讓我們很直觀清晰的判斷一個對象是否在另一個對象中&#xff0c;示例如下&#xff1a;>>> "llo" in &quo…

NYOJ 8 一種排序

一種排序 時間限制&#xff1a;3000 ms | 內存限制&#xff1a;65535 KB難度&#xff1a;3描述現在有很多長方形&#xff0c;每一個長方形都有一個編號&#xff0c;這個編號可以重復&#xff1b;還知道這個長方形的寬和長&#xff0c;編號、長、寬都是整數&#xff1b;現在要…

css3中的background

對background的兩種運用&#xff1a;一是background中的線性漸變&#xff0c;background: linear-gradient(to bottom,#0e7bef,#0d73da);這個是對背景顏色從上到下的一種線性漸變&#xff08;linear-gradient&#xff09;&#xff0c;兩個顏色參數是從第一個顏色參數漸變到第二…

Oracle JRockit Mission Control 4.1發布

Oracle發布了以前的僅JRockit專用工具Mission Control Suite&#xff08;JRMC&#xff09;的新版本。 4.1版本是次要版本升級&#xff0c;直接遵循4.0.1&#xff08;該版本發布于2010年中期&#xff09;。 但是&#xff0c;即使版本號表明是次要的升級&#xff0c;您仍然可以在…

pe安裝usb3.0驅動_電腦店U盤啟動盤制作工具下載安裝須知

電腦店U盤啟動盤制作工具集成最全面的硬件驅動&#xff0c;精心挑選的系統維護工具&#xff0c;加上獨有人性化的設計&#xff0c;具備較強的兼容性、穩定性和安全性。能夠完美兼容臺式機、品牌機及筆記本等新老機型&#xff0c;且安全無毒&#xff0c;電腦店一鍵U盤啟動盤制作…

Webwork【02】前端OGNL試練

1.OGNL 出現的意義 在mvc中&#xff0c;數據是在各個層次之間進行流轉是一個不爭的事實。而這種流轉&#xff0c;也就會面臨一些困境&#xff0c;這些困境&#xff0c;是由于數據在不同世界中的表現形式不同而造成的&#xff1a; a. 數據在頁面上是一個扁平的&#xff0c;不帶數…

python ATM購物程序

需求&#xff1a; 模擬實現一個ATM 購物商城程序 額度 15000或自定義實現購物商城&#xff0c;買東西加入 購物車&#xff0c;調用信用卡接口結賬可以提現&#xff0c;手續費5%每月22號出賬單&#xff0c;每月10號為還款日&#xff0c;過期未還&#xff0c;按欠款總額 萬分之5…

NYOJ 10 skiing

skiing 時間限制&#xff1a;3000 ms | 內存限制&#xff1a;65535 KB難度&#xff1a;5描述Michael喜歡滑雪百這并不奇怪&#xff0c; 因為滑雪的確很刺激。可是為了獲得速度&#xff0c;滑的區域必須向下傾斜&#xff0c;而且當你滑到坡底&#xff0c;你不得不再次走上坡或…

Spring的REST服務發現性,第5部分

這是有關使用Spring 3.1和Spring Security 3.1和基于Java的配置來建立安全的RESTful Web Service的系列文章的第五篇。 上一篇文章介紹了RESTful服務HATEOAS的可發現性的概念&#xff0c;然后介紹了一些由測試驅動的實際方案。 本文將重點介紹可發現性的實際實現以及使用Spring…

postman使用_postman如何使用集合斷言?

在postman中&#xff0c;大家都使用過斷言&#xff0c;但是我們使用的斷言都是針對每一個接口或者是每一個用例添加的&#xff0c;那么是否有可以同時對多個用例或接口添加斷言呢 &#xff1f; 答案是肯定有的。那么接下來我就帶領大家認識下Postman中的批量斷言&#xff0c;也…

紀念我的leetcode開門之旅

15.12.3在朋友的建議下開始了leetcode之旅&#xff0c;上面的題目先撿簡單的刷吧。。。轉載于:https://www.cnblogs.com/thewaytomakemiracle/p/5016825.html

NYOJ 16 矩形嵌套

矩形嵌套 時間限制&#xff1a;3000 ms | 內存限制&#xff1a;65535 KB難度&#xff1a;4描述有n個矩形&#xff0c;每個矩形可以用a,b來描述&#xff0c;表示長和寬。矩形X(a,b)可以嵌套在矩形Y(c,d)中當且僅當a<c,b<d或者b<c,a<d&#xff08;相當于旋轉X90度&…

沉思濫用:“強力使用,破壞濫用”

英國前首相本杰明迪斯雷利&#xff08;Benjamin Disraeli&#xff09;曾有一個古老的說法&#xff0c;說謊言分為三種&#xff1a;“謊言&#xff0c;該死的謊言和統計數據”。 這里的暗示是統計數據很容易彌補它們是不可靠的。 但是&#xff0c;統計學在經驗科學中得到了廣泛的…

centos和ubuntu下使用cron設置定時任務

1.啟動cron工具[ps:使用root權限] centos啟動cron兩種方式 a) /etc/init.d/crond start b) service crond start ubuntu啟動cron兩種方式 a) /etc/init.d/cron start b) service cron start(推薦) 2.添加定時任務[每個整點執行ls命令] centos crontab -e命令打開文件 添加一行:…

算法與數據結構(一)

這里的許多資源&#xff0c;有時間可用多看看&#xff0c;寫一下。 http://download.csdn.net/album/detail/3249/2 這個哥們的博客還不錯&#xff1a;http://u.cxyblog.com/2/articles-3.html轉載于:https://www.cnblogs.com/oxspirt/p/5805409.html

protected訪問權限_權限修飾符 /重寫

一 權限修飾符 private內容不能被繼承類:只有public / default 可以修飾 ,且default 默認出現protected訪問權限1.同包下的類2.不同包的子類,只能通過子父類關系訪問,只有子類中才可以使用.權限修飾符只能修飾成員,成員修飾符(成員變量|成員方法)二 重寫重寫和重載的區別:(都指…

NYOJ 26 孿生素數問題

孿生素數問題 時間限制&#xff1a;3000ms | 內存限制&#xff1a;65535KB難度&#xff1a;3描述寫一個程序&#xff0c;找出給出素數范圍內的所有孿生素數的組數。一般來說&#xff0c;孿生素數就是指兩個素數距離為2&#xff0c;近的不能再近的相鄰素數。有些童鞋一看到題就…

python importlib_importlib --- import 的實現 — Python 3.10.0a2 文檔

3.7 新版功能.這個模塊使得Python的導入系統提供了訪問*包*內的*資源*的功能。如果能夠導入一個包&#xff0c;那么就能夠訪問那個包里面的資源。資源可以以二進制或文本模式方式被打開或讀取。資源非常類似于目錄內部的文件&#xff0c;要牢記的是這僅僅是一個比喻。資源和包不…

原生js使用forEach()與jquery使用each遍歷數組,return false 的區別

原生js使用forEach()與jquery使用each()遍歷數組&#xff0c;return false 的區別&#xff1a; 1、使用each()遍歷數組a,如下&#xff1a; var a[20,21,22,23,24];$.each(a, function(index,val) {console.log(indexindex);if(index2){return false;}console.log(valval);}); …