概述:

我们建立两个web项目,一个是service负责提供服务,另一个是web项目负责调用服务。

两个项目都是 maven Project 项目

生产者项目:

项目中主要就是:

pom文件,引入相关的jar包,加载tomcat启动插件

pom.xml

  1. <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">
  2. <modelVersion>4.0.0</modelVersion>
  3. <groupId>com.ithema.demo</groupId>
  4. <artifactId>dubboxdemo-service</artifactId>
  5. <version>0.0.1-SNAPSHOT</version>
  6. <packaging>war</packaging>
  7.  
  8. <properties>
  9. <spring.version>4.2.4.RELEASE</spring.version>
  10. </properties>
  11.  
  12. <dependencies>
  13. <!-- Spring -->
  14. <dependency>
  15. <groupId>org.springframework</groupId>
  16. <artifactId>spring-context</artifactId>
  17. <version>${spring.version}</version>
  18. </dependency>
  19. <dependency>
  20. <groupId>org.springframework</groupId>
  21. <artifactId>spring-beans</artifactId>
  22. <version>${spring.version}</version>
  23. </dependency>
  24. <dependency>
  25. <groupId>org.springframework</groupId>
  26. <artifactId>spring-webmvc</artifactId>
  27. <version>${spring.version}</version>
  28. </dependency>
  29. <dependency>
  30. <groupId>org.springframework</groupId>
  31. <artifactId>spring-jdbc</artifactId>
  32. <version>${spring.version}</version>
  33. </dependency>
  34. <dependency>
  35. <groupId>org.springframework</groupId>
  36. <artifactId>spring-aspects</artifactId>
  37. <version>${spring.version}</version>
  38. </dependency>
  39. <dependency>
  40. <groupId>org.springframework</groupId>
  41. <artifactId>spring-jms</artifactId>
  42. <version>${spring.version}</version>
  43. </dependency>
  44. <dependency>
  45. <groupId>org.springframework</groupId>
  46. <artifactId>spring-context-support</artifactId>
  47. <version>${spring.version}</version>
  48. </dependency>
  49.  
  50. <!-- dubbo相关 -->
  51. <dependency>
  52. <groupId>com.alibaba</groupId>
  53. <artifactId>dubbo</artifactId>
  54. <version>2.8.4</version>
  55. </dependency>
  56.  
  57.     <!--也可以换成Apache的最新dubbo
        <dependency>
    <groupId>org.apache.dubbo</groupId>
    <artifactId>dubbo</artifactId>
    <version>2.7.2</version>
    </dependency>-->
  58. <dependency>
  59. <groupId>org.apache.zookeeper</groupId>
  60. <artifactId>zookeeper</artifactId>
  61. <version>3.4.6</version>
  62. </dependency>
  63. <dependency>
  64. <groupId>com.github.sgroschupf</groupId>
  65. <artifactId>zkclient</artifactId>
  66. <version>0.1</version>
  67. </dependency>
  68.  
  69. <dependency>
  70. <groupId>javassist</groupId>
  71. <artifactId>javassist</artifactId>
  72. <version>3.11.0.GA</version>
  73. </dependency>
         
        <dependency>
                <groupId>org.apache.curator</groupId>
                <artifactId>curator-framework</artifactId>
                <version>2.8.0</version>
            </dependency>
            <dependency>
                <groupId>org.apache.curator</groupId>
                <artifactId>curator-recipes</artifactId>
                <version>2.8.0</version>
            </dependency>
  74.  
  75. </dependencies>
  76. <!--<build>
  77. <plugins>
  78. <plugin>
  79. <groupId>org.apache.maven.plugins</groupId>
  80. <artifactId>maven-compiler-plugin</artifactId>
  81. <version>2.3.2</version>
  82. <configuration>
  83. <source>1.7</source>
  84. <target>1.7</target>
  85. </configuration>
  86. </plugin>
  87. <plugin>
  88. <groupId>org.apache.tomcat.maven</groupId>
  89. <artifactId>tomcat7-maven-plugin</artifactId>
  90. <configuration>
  91. <!-- 指定端口 -->
  92. <port>8081</port>
  93. <!-- 请求路径 -->
  94. <path>/</path>
  95. </configuration>
  96. </plugin>
  97. </plugins>
  98. </build> -->
      
  99.  
  100. <!-- 下面的配置是为了能在Eclipse中像普通web项目一样用tomccat部署启动maven项目,如果无效,配置完后重启Eclipse即可 -->
  101. <build>
            <finalName>dubboxdemo-service</finalName>
            <resources>
                <resource>
                    <directory>src/main/java</directory>
                    <includes>
                        <include>**/*.xml</include>
                    </includes>
                </resource>
                <resource>
                    <directory>src/main/resources</directory>
                    <includes>
                        <include>**/*.*</include>
                    </includes>
                </resource>
            </resources>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <encoding>UTF-8</encoding>
                        <compilerArguments>
                            <extdirs>src\main\webapp\WEB-INF\lib</extdirs>
                        </compilerArguments>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.10</version>
                    <executions>
                        <execution>
                            <id>copy-dependencies</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
                                <overWriteReleases>false</overWriteReleases>
                                <overWriteSnapshots>false</overWriteSnapshots>
                                <overWriteIfNewer>true</overWriteIfNewer>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
  102. </project>

spring配置文件: 因为我们用的是spring集成dubbox,所以需要在配置文件中配置dubbox相关信息

applicationContext-service.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  7. http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
  8. http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
  9. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
  10.  
  11. <!-- 提供服务的名称,可以写生产者项目的工程名 -->
  12. <dubbo:application name="dubboxdemo-service"/>
  13. <!-- zookeeper注册中心的地址和端口 -->
  14. <dubbo:registry address="zookeeper://192.168.25.128:2181"/>
  15. <!-- 需要暴露的接口所在的包的全限定名 @service 即 com.alibaba.dubbo.config.annotation.Service 注解所在的包名(好去扫描它)-->
  16. <dubbo:annotation package="com.ithema.demo.service.impl" />
  17.  
  18. </beans>

注意:这里  <dubbo:annotation package=    配置的是 @Service 注解所在的包的全名,注意是 包,而不是 类

web.xml中加载spring的配置文件即可:

web.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns="http://java.sun.com/xml/ns/javaee"
  4. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  5. version="2.5">
  6.  
  7. <!-- 加载spring容器 -->
  8. <context-param>
  9. <param-name>contextConfigLocation</param-name>
  10. <param-value>classpath:applicationContext*.xml</param-value>
  11. </context-param>
  12. <listener>
  13. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  14. </listener>
  15.  
  16. </web-app>

然后就是代码,代码很简单,只需要定义一个 接口 和 一个实现类,接口就是要暴露出去的服务接口

接口 UserService

  1. package com.ithema.demo.service;
  2.  
  3. public interface UserService {
  4. String getName();
  5. }

接口代码中不用做任何特殊配置,纯java代码。 但是要注意,接口所在的包的全名 就是 配置在 xml 文件中的 <dubbo:annotation package="com.ithema.demo.service" />  【其实我觉得主要是要在配置文件中配置好 实现类所在的包,因为需要根据配置的包来扫描其内部的 dubbox相关的注解以实现dubbox功能】

然后是实现类:

UserServiceImpl

  1. package com.ithema.demo.service.impl;
  2. import com.alibaba.dubbo.config.annotation.Service;
  3. import com.ithema.demo.service.UserService;
  4. @Service
  5. public class UserServiceImpl implements UserService {
  6. public String getName() {
  7. return "ithema";
  8. }
  9. }

实现类中要注意的就是 需要加上 注解 Service,注意,这个注解不是springMvc中的   service注解,而是 dubbox包中的注解:

  1. import com.alibaba.dubbo.config.annotation.Service;

不要导错包,加上这个注解,才会把这个服务注册到 zookeeper的注册中心中去。

==================

下面开始配置消费者项目

这个项目里的 pom文件和生产者项目是一样的,区别只需要设置不同的tomcat启动插件端口

pom文件:

  1. <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">
  2. <modelVersion>4.0.0</modelVersion>
  3. <groupId>com.itheima.demo</groupId>
  4. <artifactId>dubboxdemo-web</artifactId>
  5. <version>0.0.1-SNAPSHOT</version>
  6. <packaging>war</packaging>
  7.  
  8. <properties>
  9. <spring.version>4.2.4.RELEASE</spring.version>
  10. </properties>
  11.  
  12. <dependencies>
  13. <!-- Spring -->
  14. <dependency>
  15. <groupId>org.springframework</groupId>
  16. <artifactId>spring-context</artifactId>
  17. <version>${spring.version}</version>
  18. </dependency>
  19. <dependency>
  20. <groupId>org.springframework</groupId>
  21. <artifactId>spring-beans</artifactId>
  22. <version>${spring.version}</version>
  23. </dependency>
  24. <dependency>
  25. <groupId>org.springframework</groupId>
  26. <artifactId>spring-webmvc</artifactId>
  27. <version>${spring.version}</version>
  28. </dependency>
  29. <dependency>
  30. <groupId>org.springframework</groupId>
  31. <artifactId>spring-jdbc</artifactId>
  32. <version>${spring.version}</version>
  33. </dependency>
  34. <dependency>
  35. <groupId>org.springframework</groupId>
  36. <artifactId>spring-aspects</artifactId>
  37. <version>${spring.version}</version>
  38. </dependency>
  39. <dependency>
  40. <groupId>org.springframework</groupId>
  41. <artifactId>spring-jms</artifactId>
  42. <version>${spring.version}</version>
  43. </dependency>
  44. <dependency>
  45. <groupId>org.springframework</groupId>
  46. <artifactId>spring-context-support</artifactId>
  47. <version>${spring.version}</version>
  48. </dependency>
  49.  
  50. <!-- dubbo相关 -->
  51. <dependency>
  52. <groupId>com.alibaba</groupId>
  53. <artifactId>dubbo</artifactId>
  54. <version>2.8.4</version>
  55. </dependency>
  56. <dependency>
  57. <groupId>org.apache.zookeeper</groupId>
  58. <artifactId>zookeeper</artifactId>
  59. <version>3.4.6</version>
  60. </dependency>
  61. <dependency>
  62. <groupId>com.github.sgroschupf</groupId>
  63. <artifactId>zkclient</artifactId>
  64. <version>0.1</version>
  65. </dependency>
  66.  
  67. <dependency>
  68. <groupId>javassist</groupId>
  69. <artifactId>javassist</artifactId>
  70. <version>3.11.0.GA</version>
  71. </dependency>
      
         <dependency>
                <groupId>org.apache.curator</groupId>
                <artifactId>curator-framework</artifactId>
                <version>2.8.0</version>
            </dependency>
            <dependency>
                <groupId>org.apache.curator</groupId>
                <artifactId>curator-recipes</artifactId>
                <version>2.8.0</version>
            </dependency>
  72.  
  73. </dependencies>

  74.   <!-- 下面的配置是为了能在Eclipse中像普通web项目一样用tomccat部署启动maven项目,如果无效,配置完后重启Eclipse即可 -->
  75. <build>
            <finalName>dubboxdemo-web</finalName>
            <resources>
                <resource>
                    <directory>src/main/java</directory>
                    <includes>
                        <include>**/*.xml</include>
                    </includes>
                </resource>
                <resource>
                    <directory>src/main/resources</directory>
                    <includes>
                        <include>**/*.*</include>
                    </includes>
                </resource>
            </resources>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <encoding>UTF-8</encoding>
                        <compilerArguments>
                            <extdirs>src\main\webapp\WEB-INF\lib</extdirs>
                        </compilerArguments>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.10</version>
                    <executions>
                        <execution>
                            <id>copy-dependencies</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
                                <overWriteReleases>false</overWriteReleases>
                                <overWriteSnapshots>false</overWriteSnapshots>
                                <overWriteIfNewer>true</overWriteIfNewer>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
  76. </project>

然后是 spring配置文件,因为这个是个负责响请求的web项目,所以,将 dubbox 的配置写到 spirngMVC配置文件中即可:

springMVC.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  7. http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
  8. http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
  9. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
  10.  
  11. <mvc:annotation-driven >
  12. <mvc:message-converters register-defaults="false">
  13. <bean class="org.springframework.http.converter.StringHttpMessageConverter">
  14. <constructor-arg value="UTF-8" />
  15. </bean>
  16. </mvc:message-converters>
  17. </mvc:annotation-driven>
       
      <!-- 处理静态资源 如html,css,js,images可以访问-->
        <mvc:default-servlet-handler/>
      
      <!--注解驱动,以使得访问路径与方法的匹配可以通过注解配置-->
        <mvc:annotation-driven />
        <!-- 配置包扫描器,扫描@Controller注解的类所在的包 -->
        <context:component-scan base-package="com.test.controller"/>
  18.  
  19.   <!--或者这样配置:扫描Controller,并将其生命周期纳入Spring管理
      <context:annotation-config/>
        <context:component-scan base-package="com.how2java.controller">
          <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
      </context:component-scan>-->
  20.  
  21. <!-- 消费者的名称,可以用消费者项目名 -->
  22. <dubbo:application name="dubboxdemo-web"/>
  23. <!-- zookeeper注册中心地址端口 -->
  24. <dubbo:registry address="zookeeper://192.168.25.128:2181"/>
  25. <!-- @Reference 注解所在的包,根据下面配置的路径去扫描dubbox的相关注解 -->
  26. <dubbo:annotation package="com.ithema.demo.controller" />
  27.  
  28. </beans>

在这里,关于 dubbox 配置的写法标签都是一样的,但是 这个扫描包 要配置成 Controller所在的包,因为要 扫描 Controller类中注入 接口上的 @Reference 注解

注意:这里 <dubbo:annotation package=     配置的 是 @Reference 注解所在的包的全名,注意是 包,而不是类。

代码:

首先是 service,这个service其实就是 把 生产者项目中的 那个 接口UserService 连同其所在包 原封不动的 拿过来的,就是为了符合 spring的注入要求。

Controller代码:

  1. package com.ithema.demo.controller;
  2.  
  3. import org.springframework.stereotype.Controller;
  4. import org.springframework.web.bind.annotation.RequestMapping;
  5. import org.springframework.web.bind.annotation.ResponseBody;
  6.  
  7. import com.alibaba.dubbo.config.annotation.Reference;
  8. import com.ithema.demo.service.UserService;
  9.  
  10. @Controller
  11. @RequestMapping("/user")
  12. public class UserController {
  13.  
  14. @Reference
  15. private UserService userService;
  16.  
  17. @RequestMapping("/showName")
  18. @ResponseBody
  19. public String showName(){
  20. String name = userService.getName();
  21. return name;
  22. }
  23. }

主要是要在 service上加入 @Reference 注解,说明这个是调用远程的 接口 注入。

消费者的 web.xml :

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns="http://java.sun.com/xml/ns/javaee"
  4. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  5. version="2.5">
  6.  
  7. <welcome-file-list>
  8. <welcome-file>index.jsp</welcome-file>
  9. </welcome-file-list>
  10. <!-- 解决post乱码 -->
  11. <filter>
  12. <filter-name>CharacterEncodingFilter</filter-name>
  13. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  14. <init-param>
  15. <param-name>encoding</param-name>
  16. <param-value>utf-8</param-value>
  17. </init-param>
  18. <init-param>
  19. <param-name>forceEncoding</param-name>
  20. <param-value>true</param-value>
  21. </init-param>
  22. </filter>
  23. <filter-mapping>
  24. <filter-name>CharacterEncodingFilter</filter-name>
  25. <url-pattern>/*</url-pattern>
  26. </filter-mapping>
  27.  
  28. <servlet>
  29. <servlet-name>springmvc</servlet-name>
  30. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  31. <!-- 指定加载的配置文件 ,通过参数contextConfigLocation加载-->
  32. <init-param>
  33. <param-name>contextConfigLocation</param-name>
  34. <param-value>classpath:springmvc.xml</param-value>
  35. </init-param>
  36. </servlet>
  37.  
  38. <servlet-mapping>
  39. <servlet-name>springmvc</servlet-name>
  40. <url-pattern>*.do</url-pattern>
  41. </servlet-mapping>
  42.  
  43. </web-app>

=======

测试:

先启动service项目,然后再启动 web项目,然后在浏览器中访问:

说明远程接口调用实现了。

  1. <!-- 下面的配置是为了能在Eclipse中像普通web项目一样用tomccat部署启动maven项目,如果无效,配置完后重启Eclipse即可 -->
  2. <build>
            <finalName>dubboxdemo-web</finalName>
            <resources>
                <resource>
                    <directory>src/main/java</directory>
                    <includes>
                        <include>**/*.xml</include>
                    </includes>
                </resource>
                <resource>
                    <directory>src/main/resources</directory>
                    <includes>
                        <include>**/*.*</include>
                    </includes>
                </resource>
            </resources>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <encoding>UTF-8</encoding>
                        <compilerArguments>
                            <extdirs>src\main\webapp\WEB-INF\lib</extdirs>
                        </compilerArguments>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.10</version>
                    <executions>
                        <execution>
                            <id>copy-dependencies</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
                                <overWriteReleases>false</overWriteReleases>
                                <overWriteSnapshots>false</overWriteSnapshots>
                                <overWriteIfNewer>true</overWriteIfNewer>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>

dubbox小demo的更多相关文章

  1. dubbox 入门demo

    1.Dubbox简介 Dubbox 是一个分布式服务架构,其前身是阿里巴巴开源项目 Dubbo,被国内电商及互联网项目使用,后期阿里巴巴停止了该项目的维护,当当网便在 Dubbo 基础上进行优化,并继 ...

  2. 新手 gulp+ seajs 小demo

    首先,不说废话,它的介绍和作者就不在多说了,网上一百度一大堆: 我在这里只是来写写我这2天抽空对seajs的了解并爬过的坑,和实现的一个小demo(纯属为了实现,高手请绕道); 一.环境工具及安装 1 ...

  3. Nancy之基于Nancy.Hosting.Self的小Demo

    继昨天的Nancy之基于Nancy.Hosting.Aspnet的小Demo后, 今天来做个基于Nancy.Hosting.Self的小Demo. 关于Self Hosting Nancy,官方文档的 ...

  4. Nancy之基于Nancy.Owin的小Demo

    前面做了基于Nancy.Hosting.Aspnet和Nancy.Hosting.Self的小Demo 今天我们来做个基于Nancy.Owin的小Demo 开始之前我们来说说什么是Owin和Katan ...

  5. Nancy之基于Self Hosting的补充小Demo

    前面把Hosting Nancy with ASP.NET.Self Hosting Nancy和Hosting Nancy with OWIN 以demo的形式简单描述了一下. 这篇是为Self H ...

  6. [Unity3D]做个小Demo学习Input.touches

    [Unity3D]做个小Demo学习Input.touches 学不如做,下面用一个简单的Demo展示的Input.touches各项字段,有图有真相. 本项目已发布到Github,地址在(https ...

  7. Android -- 自定义View小Demo,动态画圆(一)

    1,转载:(http://blog.csdn.NET/lmj623565791/article/details/24500107),现在如下图的效果: 由上面的效果图可以看到其实是一个在一个圆上换不同 ...

  8. Win10 FaceAPI小demo开发问题汇总

    Win10 FaceAPI小demo开发问题汇总 最近使用微软牛津计划做一个小demo,使用FaceAPI做一个小应用,实现刷脸的功能.开发的过程中用到几个问题,具体如下: Stream 与IRand ...

  9. 模仿京东顶部搜索条效果制作的一个小demo

    最近模仿京东顶部搜索条效果制作的一个小demo,特贴到这里,今后如果有用到可以参考一下,代码如下 #define kScreenWidth [UIScreen mainScreen].bounds.s ...

随机推荐

  1. lintcode112 删除排序链表中的重复元素

    删除排序链表中的重复元素   给定一个排序链表,删除所有重复的元素每个元素只留下一个. 您在真实的面试中是否遇到过这个题? Yes 样例 给出 1->1->2->null,返回 1- ...

  2. lintcode166 链表倒数第n个节点

    链表倒数第n个节点 找到单链表倒数第n个节点,保证链表中节点的最少数量为n. 思路:设置两个指针first,second指向head,first指针先向前走n,然后两个指针一起走,first指针走到末 ...

  3. 栈和队列ADT -数据结构(C语言实现)

    数据结构与算法分析 栈模型 限制插入和删除只能在表的末端的表 表的末端叫做栈顶(top) 支持Push进栈和Pop入栈操作 //LIFO后进先出表 栈的实现 链表实现 类型声明 struct Node ...

  4. [Clr via C#读书笔记]Cp1CLR执行模型

    Cp1CLR执行模型 本章的概念点 CLR=Common Language Runtime 内存管理,程序集加载,安全性,异常处理和线程同步.CLR是基础,支持着面向它的各种语言.各种语言会被对应的编 ...

  5. matconv-GPU 编译问题

    如出现以下错误: 1 error detected in the compilation of "C:/Users/Justin/AppData/Local/Temp/tmpxft_0000 ...

  6. Multi-task Correlation Particle Filter for Robust Object Tracking--论文随笔

    摘要:在这篇论文中,作者提出一种鲁棒视觉跟踪的多任务相关粒子滤波琪跟踪算法(MCPF).作者首先向我们展示了多任务相关滤波器,该滤波器在训练滤波器模板的时候可以学习不同特征之间的联系.本文提出的MCP ...

  7. Python 学习笔记之——用 sklearn 对数据进行预处理

    1. 标准化 标准化是为了让数据服从一个零均值和单位方差的标准正态分布.也即针对一个均值为 \(mean\) 标准差为 \(std\) 的向量 \(X\) 中的每个值 \(x\),有 \(x_{sca ...

  8. Alpha发布——视频展示

    一.视频链接 http://v.youku.com/v_show/id_XMzEyODQzNzQ2MA==.html 二.视频文案说明 你是不是还在为软工作业奋笔疾书? 你是不是无法及时查看最新博客信 ...

  9. Java中I/O流之缓冲流

    Java 中的缓冲流: 1. 缓冲流要“套接”在相应的节点流之上,对读写的数据提供了缓冲的功能,提高了读写的效率,同时增加了一些新的方法(带缓冲区的,显著减少对 IO 的读写次数,保护硬盘). 2. ...

  10. 如何将PDF的背景色设置为保护眼睛的苹果绿色

      福昕阅读器请戳这里.   Adobe Acrobat请戳这里.