1.1 首先创建一个Maven工程

File --> New --> Other,然后选择Maven目录下的Maven Project,如下图:

然后在弹出的面板中选择配置后,下一步即可,如图:

Create a simple project (skip archetype selection) :此选项表示跳过后续的配置选项框。

Use default Workspace location:表示将项目放置到默认的工作区域下。

配置好后,Next下一步,再进行如下图的配置:

点击Finish后,便完成了Maven工程的创建。

此时在你开发工具的Workspace工作区的树桩菜单中出现了SpringRedisStudy这个项目工程.如图:

这时,工程会报错,是因为一开始创建Maven工程时,选择的是 Create a simple project 属性,所以在webapp项目下可能会没有任何文件,如图:

这个时候就需要我们自己去创建它们。

首先在 webapp 下增加一个 WEB-INF 文件夹;然后在 WEB-INF 文件夹中增加一个 web.xml(部署描述符文件);

接下来我们就要在这个文件中进行一些配置工作。

 <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>SpringRedisStudy</display-name>
<!-- 设置由Sprng载入的Log4j配置文件位置 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:config/property/log4j.properties</param-value>
</context-param>
<!-- Spring刷新Log4j配置文件变动的间隔,单位为毫秒 -->
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>100000</param-value>
</context-param>
<!-- 加载其他配置文件至Spring应用上下文中 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- 指定多个Spring配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:config/xml/dispatcher-servlet.xml;
classpath:config/xml/spring-context.xml
</param-value>
</context-param>
<!-- Spring字符集过滤器 -->
<filter>
<filter-name>SpringEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SpringEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- Spring view分发器 -->
<!-- servlet-name 决定了初始化的名字:name-servlet.xml -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/conf/dispatcher-servlet.xml
</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> </web-app>

1.2 配置maven 工程文件 pom.xml

接下来我们进行详细的项目搭建,首先配置maven 工程文件 pom.xml,

因为我们要搭建Spring MVC这个工程,所以就要将相关的jar包配置到Maven工程中进行引用管理;

pom.xml文件配置如下:

 <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">
<modelVersion>4.0.0</modelVersion>
<groupId>SpringRedisStudy</groupId>
<artifactId>SpringRedisStudy</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<!-- spring版本号 -->
<org.springframework.version>3.0.7.RELEASE</org.springframework.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<slf4j.version>1.7.5</slf4j.version>
<log4j.version>1.2.17</log4j.version>
</properties> <dependencies> <!-- config junit jar -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency> <!-- config redis data and client jar -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.6.4.RELEASE</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.4.2</version>
</dependency> <!-- config need jar -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency> <dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>
<version>1.0</version>
</dependency> <!-- cofig spring jar -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${org.springframework.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${org.springframework.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${org.springframework.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${org.springframework.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${org.springframework.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc-portlet</artifactId>
<version>${org.springframework.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework.version}</version>
<scope>test</scope>
</dependency>
<!-- log start -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!-- log end -->
</dependencies> <build>
<resources>
<resource>
<directory>/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<version>2.5</version>
</configuration>
</plugin>
</plugins>
</build>
</project>

1.3 集成spring配置文件

Maven配置好后,我们就需要在项目中进行spring配置了;

在src/main/resources目录中增加一个 config.xml包,并新建文件spring-context.xml;

这个文件的作用是配置Spring的,内容如下:

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd"> <!-- 激活@Controller模式 -->
<mvc:annotation-driven />
<context:annotation-config />
<!-- 对包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 需要更改 -->
<context:component-scan base-package="com.test.*" /> <!-- 引入同文件夹下的redis属性配置文件 -->
<import resource="redis-context.xml"/>
<!-- 测试用的userDao依赖注入 -->
<bean id="userDao" class="com.test.dao.impl.UserDao" />
</beans>

在该包config.xml下同时新建redis-context.xml文件,内容如下:

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!-- 引入redis.properties配置文件 -->
<context:property-placeholder
location="classpath:/config/property/redis.properties" />
<!-- redis 相关配置 -->
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig"
p:maxTotal="${redis.maxTotal}"
p:maxIdle="${redis.maxIdle}"
p:testOnBorrow="${redis.testOnBorrow}" /> <bean id="connectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:hostName="${redis.host}"
p:port="${redis.port}"
p:password="${redis.password}"
p:database="${redis.database}"
p:pool-config-ref="poolConfig" />
<!-- redis template definition -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"
p:connectionFactory-ref="connectionFactory"
p:keySerializer-ref="redisTemplateKeySerializer"
p:valueSerializer-ref="redisTemplateValueSerializer"
p:hashKeySerializer-ref="redisTemplateHashKeySerializer"
p:hashValueSerializer-ref="redisTemplateHashValueSerializer"/>
<bean id="redisTemplateKeySerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer" />
<bean id="redisTemplateValueSerializer" class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
<bean id="redisTemplateHashKeySerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer" />
<bean id="redisTemplateHashValueSerializer" class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
</beans>

在src/main/resources目录中增加一个config.property包,并新建文件redis.properties,这个文件是redis的属性配置文件,内容如下:

# Redis settings
# server IP
redis.host=127.0.0.1
# server port
redis.port=6379
redis.password=myredis
redis.maxTotal=600
#redis.maxActive=600 此属性在新版本中不可用
# use dbIndex
redis.database=0
# 控制一个pool最多有多少个状态为idle(空闲的)的jedis实例
redis.maxIdle=300
# 表示当borrow(引入)一个jedis实例时,最大的等待时间,如果超过等待时间(毫秒),则直接抛出JedisConnectionException;
#redis.maxWait=3000 此属性在新版本中不可用
# 在borrow一个jedis实例时,是否提前进行validate操作;如果为true,则得到的jedis实例均是可用的
redis.testOnBorrow=true

在src/main/resources目录下新建log4j.properties文件,作为log4j的属性配置文件,内容如下:

#All level less than INFO will be logged
log4j.rootLogger=info,console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.ImmediateFlush=true
log4j.appender.console.Target=System.out
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss} %m%n

在项目工程未上线前暂时放在该目录,方便测试,上线后可以移动到config.property目录,此时需要在web.xml文件的<listener>节点前加入如下内容:

 ……
<display-name>SpringRedisStudy</display-name>
<!-- 设置由Sprng载入的Log4j配置文件位置 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:config/property/log4j.properties</param-value>
</context-param>
<!-- Spring刷新Log4j配置文件变动的间隔,单位为毫秒 -->
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>100000</param-value>
</context-param>
<!-- 加载其他配置文件至Spring应用上下文中 -->
<listener>
……

1.4 编写java类

在SpringRedisStudy工程的src/main/java目录下新建com.test.entity包,并新建User.java类,内容如下:

package com.test.entity;

import java.io.Serializable;

public class User implements Serializable{
private static final long serialVersionUID = 8634600086311962551L;
private String id;
private String name;
public User() {
super();
}
public User(String id, String name) {
super();
this.id = id;
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

在SpringRedisStudy工程的src/main/java目录下新建com.test.dao包并在该包下新建抽象类AbstractBaseRedisDao.java和接口IUserDao.java文件,内容如下:

package com.test.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer; public abstract class AbstractBaseRedisDao <K, V> { @Autowired
protected RedisTemplate<K, V> redisTemplate; /**
* 设置redisTemplate
* @param redisTemplate 给属性redisTemplate赋值
*/
public void setRedisTemplate(RedisTemplate<K, V> redisTemplate) {
this.redisTemplate = redisTemplate;
} /**
* 获取 RedisSerializer
*/
protected RedisSerializer<String> getRedisSerializer() {
return redisTemplate.getStringSerializer();
}
}
package com.test.dao;

import java.util.List;
import com.test.entity.User; public interface IUserDao { /**
* 新增
* @param User对象
* @return 是否新增成功
*/
boolean add(User user); /**
* 批量新增 使用pipeline方式
* @param list
* @return 是否新增成功
*/
boolean add(List<User> list); /**
* 删除
* @param key
*/
void delete(String key); /**
* 删除多个
* @param keys
*/
void delete(List<String> keys); /**
* 修改
* @param user对象
* @return 是否修改成功
*/
boolean update(User user); /**
* 通过key获取User对象
* @param keyId
* @return User对象
*/
User get(String keyId);
}

在SpringRedisStudy工程的src/main/java目录下新建com.test.dao.impl包并在该包下新建接口的实现类UserDao.java文件,内容如下:

package com.test.dao.impl;

import java.util.ArrayList;
import java.util.List;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.util.Assert;
import com.test.dao.AbstractBaseRedisDao;
import com.test.dao.IUserDao;
import com.test.entity.User; public class UserDao extends AbstractBaseRedisDao <String, User> implements IUserDao {
/**
* 新增
* @param User对象
* @return 是否新增成功
*/
public boolean add(final User user) {
boolean result = redisTemplate.execute(new RedisCallback<Boolean>() {
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
RedisSerializer<String> serializer = getRedisSerializer();
byte[] key = serializer.serialize(user.getId());
byte[] name = serializer.serialize(user.getName());
return connection.setNX(key, name);
}
});
return result;
}
/**
* 批量新增 使用pipeline方式
* @param list
* @return 是否新增成功
*/
public boolean add(final List<User> list) {
Assert.notEmpty(list);
boolean result = redisTemplate.execute(new RedisCallback<Boolean>() {
public Boolean doInRedis(RedisConnection connection)
throws DataAccessException {
RedisSerializer<String> serializer = getRedisSerializer();
for (User user : list) {
byte[] key = serializer.serialize(user.getId());
byte[] name = serializer.serialize(user.getName());
connection.setNX(key, name);
}
return true;
}
}, false, true);
return result;
}
/**
* 删除
* @param key
*/
public void delete(String key) {
if (key ==null || key.length() == 0) {
return;
}
List<String> list = new ArrayList<String>();
list.add(key);
delete(list);
}
/**
* 删除多个
* @param keys
*/
public void delete(List<String> keys) {
redisTemplate.delete(keys);
}
/**
* 修改
* @param user
* @return result 是否修改成功
*/
public boolean update(final User user) {
String key = user.getId();
if (get(key) == null) {
throw new NullPointerException("数据行不存在, key = " + key);
}
boolean result = redisTemplate.execute(new RedisCallback<Boolean>() {
public Boolean doInRedis(RedisConnection connection)
throws DataAccessException {
RedisSerializer<String> serializer = getRedisSerializer();
byte[] key = serializer.serialize(user.getId());
byte[] name = serializer.serialize(user.getName());
connection.set(key, name);
return true;
}
});
return result;
}
/**
* 通过key获取User对象
* @param keyId
* @return User对象
*/
public User get(final String keyId) {
User result = redisTemplate.execute(new RedisCallback<User>() {
public User doInRedis(RedisConnection connection)
throws DataAccessException {
RedisSerializer<String> serializer = getRedisSerializer();
byte[] key = serializer.serialize(keyId);
byte[] value = connection.get(key);
if (value == null) {
return null;
}
String name = serializer.deserialize(value);
return new User(keyId, name);
}
});
return result;
} }

在SpringRedisStudy工程的src/test/java目录的默认default包下新建测试类RedisTest.java文件,内容如下:

import java.util.ArrayList;
import java.util.List;
import junit.framework.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import com.test.dao.IUserDao;
import com.test.entity.User; /**
* 测试
*/
@ContextConfiguration(locations = {"classpath:config/xml/spring-context.xml"})
public class RedisTest extends AbstractJUnit4SpringContextTests { @Autowired
private IUserDao userDao; /**
* 新增
*/
@Test
public void testAddUser() {
User user = new User();
user.setId("user1");
user.setName("java2000_wl1");
boolean result = userDao.add(user);
Assert.assertTrue(result);
} /**
* 批量新增 普通方式
*/
@Test
public void testAddUsers1() {
List<User> list = new ArrayList<User>();
for (int i = 10; i < 50000; i++) {
User user = new User();
user.setId("user" + i);
user.setName("java2000_wl" + i);
list.add(user);
}
long begin = System.currentTimeMillis();
for (User user : list) {
userDao.add(user);
}
System.out.println(System.currentTimeMillis() - begin);
} /**
* 批量新增 pipeline方式
*/
@Test
public void testAddUsers2() {
List<User> list = new ArrayList<User>();
for (int i = 50000; i < 100000; i++) {
User user = new User();
user.setId("user" + i);
user.setName("java2000_wl" + i);
list.add(user);
}
long begin = System.currentTimeMillis();
boolean result = userDao.add(list);
System.out.println(System.currentTimeMillis() - begin);
Assert.assertTrue(result);
} /**
* 修改
*/
@Test
public void testUpdate() {
User user = new User();
user.setId("user1");
user.setName("new_password");
boolean result = userDao.update(user);
Assert.assertTrue(result);
}
/**
* 获取
*/
@Test
public void testGetUser() {
String id = "user1";
User user = userDao.get(id);
Assert.assertNotNull(user);
Assert.assertEquals(user.getName(), "java2000_wl1");
}
/**
* 通过key删除单个
*/
@Test
public void testDelete() {
String key = "user1";
userDao.delete(key);
} /**
* 批量删除
*/
@Test
public void testDeletes() {
List<String> list = new ArrayList<String>();
for (int i = 0; i < 100000; i++) {
list.add("user" + i);
}
userDao.delete(list);
} /**
* 设置userDao
* @param userDao the userDao to set
*/
public void setUserDao(IUserDao userDao) {
this.userDao = userDao;
}
}

1.5 测试

在RedisTest.java文件上右键run as --->Run Configurations,开始测试:

测试结果:

Spring和redis简单测试demo的更多相关文章

  1. spring与redis简单整合

    项目结构 整合需要的依赖 <dependencies> <dependency> <groupId>org.springframework</groupId& ...

  2. java代理课程测试 spring AOP代理简单测试

    jjava加强课程测试代码 反射. 代理 .泛型.beanUtils等 项目源码下载:http://download.csdn.net/detail/liangrui1988/6568169 热身运动 ...

  3. Spring整合MyBatis(简单登录Demo)

    SpringMvc简单整合(登录模块) 1.1 整合思路 1.SqlSessionFactory对象应该放到spring容器中作为单例存在. 2.传统dao的开发方式中,应该从spring容器中获得s ...

  4. django celery redis简单测试

    希望在下一版中,能用这个小芹菜,来实现异步的多任务并行哈. 安装REDIS之类的不表,只说在DJANGO当中要注意配置的事项. 0,安装插件 yum install redis-server pip ...

  5. 简单测试Demo:如何用Java压缩文件夹和文件

    一.直接贴出测试代码 package com.jason.zip; import java.io.File; import java.io.FileInputStream; import java.i ...

  6. springMVC 缓存(入门 spring+mybaties+redis一)

    使用redis之前需要咋电脑上安装redis: 使用spring+mybaties+redis的本质是扩展类   org.apache.ibatis.cache.Cache:在我们自己扩展的Cache ...

  7. Spring Boot超简单的测试类demo

    1 概述 Spring Boot结合Junit的简单测试类demo,流程是先引入依赖,接着编写测试类测试运行即可. 2 依赖 <dependency> <groupId>org ...

  8. Spring Data Redis简介以及项目Demo,RedisTemplate和 Serializer详解

    一.概念简介: Redis: Redis是一款开源的Key-Value数据库,运行在内存中,由ANSI C编写,详细的信息在Redis官网上面有,因为我自己通过google等各种渠道去学习Redis, ...

  9. SpringBoot学习笔记(13)----使用Spring Session+redis实现一个简单的集群

    session集群的解决方案: 1.扩展指定server 利用Servlet容器提供的插件功能,自定义HttpSession的创建和管理策略,并通过配置的方式替换掉默认的策略.缺点:耦合Tomcat/ ...

随机推荐

  1. DIV在另一个DIV里面垂直居中,水平居中

    HTML: <div class="parent"> <div class="children"> <div class=&quo ...

  2. Array - Container With Most Water

    /** * 此为暴力解法 * Find two lines, which together with x-axis forms a container, such that the container ...

  3. cpp代码调试,调试扑克牌的代码

    #include <iostream> #include <vector> #include <algorithm> using namespace std; cl ...

  4. Java中的后台线程和join方法

    /*守护线程(后台线程):在一个进程中如果只剩下 了守护线程,那么守护线程也会死亡. 需求: 模拟QQ下载更新包. 一个线程默认都不是守护线程. */ public class Demo extend ...

  5. shell脚本,awk在需要的行上打打印空行。

    注解: 判断每行中是否包含字母a,包含了,就将$1的值赋值给变量a,然后判断变量a是否存在,存在打印一个空行,在将变量的值使用空变量b赋值,最后在打印输出. 结果就是在包含有字符a的行上打印一个空行.

  6. OC中的宏定义

    我们都知道,宏定义是编译期常量.而OC是一种动态语言. 1.iOS系统版本判断的两个宏定义 __IPHONE_OS_VERSION_MAX_ALLOWED // iOS系统版本最大允许 __IPHON ...

  7. PCA检测人脸的简单示例_matlab实现

    PCA检测人脸的简单示例,matlab R2009b上实现训练:训练用的20副人脸: %训练%Lx=X'*Xclear;clc;train_path='..\Data\TrainingSet\';ph ...

  8. dev gridview columns代码管理

    进入run designer界面.我们将在代码中设置columns的属性. 类: ViewTriAtt : DevExpress.XtraEditors.XtraUserControl 在类里面设置g ...

  9. $GLOBALS['HTTP_RAW_POST_DATA']与$_POST的区别

    $HTTP_RAW_POST_DATA   The RAW / uninterpreted HTTP POst information can be accessed with:   $GLOBALS ...

  10. 2018 Python开发者大调查:Python和JavaScript最配?

    在2018年秋季,Python软件基金会与JetBrains发起了年度Python开发者调查. 报告的目的是寻找Python领域的新趋势,帮助开发者深入了解2018年Python开发者的现状. 该报告 ...