当前位置: 首页 > 编程日记 > 正文

Spring Boot 整合Redis 实现缓存

本文提纲
一、缓存的应用场景
二、更新缓存的策略
三、运行 springboot-mybatis-redis 工程案例
四、springboot-mybatis-redis 工程代码配置详解
运行环境
Mac OS 10.12.x
JDK 8 +
Redis 3.2.8
Spring Boot 1.5.1.RELEASE

一、缓存的应用场景

什么是缓存?
在互联网场景下,尤其 2C 端大流量场景下,需要将一些经常展现和不会频繁变更的数据,存放在存取速率更快的地方。缓存就是一个存储器,在技术选型中,常用 Redis 作为缓存数据库。缓存主要是在获取资源方便性能优化的关键方面。
Redis 是一个高性能的 key-value 数据库。GitHub 地址:https://github.com/antirez/redis 。Github 是这么描述的:
Redis is an in-memory database that persists on disk. The data model is key-value, but many different kind of values are supported: Strings, Lists, Sets, Sorted Sets, Hashes, HyperLogLogs, Bitmaps.
缓存的应用场景有哪些呢?
比如常见的电商场景,根据商品 ID 获取商品信息时,店铺信息和商品详情信息就可以缓存在 Redis,直接从 Redis 获取。减少了去数据库查询的次数。但会出现新的问题,就是如何对缓存进行更新?这就是下面要讲的。

二、更新缓存的策略

参考《缓存更新的套路》http://coolshell.cn/articles/17416.html,缓存更新的模式有四种:Cache aside, Read through, Write through, Write behind caching。
这里我们使用的是 Cache Aside 策略,从三个维度:(摘自 耗子叔叔博客)
失效:应用程序先从cache取数据,没有得到,则从数据库中取数据,成功后,放到缓存中。
命中:应用程序从cache中取数据,取到后返回。
更新:先把数据存到数据库中,成功后,再让缓存失效。
大致流程如下:
获取商品详情举例
a. 从商品 Cache 中获取商品详情,如果存在,则返回获取 Cache 数据返回。
b. 如果不存在,则从商品 DB 中获取。获取成功后,将数据存到 Cache 中。则下次获取商品详情,就可以从 Cache 就可以得到商品详情数据。
c. 从商品 DB 中更新或者删除商品详情成功后,则从缓存中删除对应商品的详情缓存

三、运行 springboot-mybatis-redis 工程案例

git clone 下载工程 springboot-learning-example ,项目地址见 GitHub – https://github.com/JeffLi1993/springboot-learning-example。
下面开始运行工程步骤(Quick Start):
1.数据库和 Redis 准备
a.创建数据库 springbootdb:
1
CREATE DATABASE springbootdb;
b.创建表 city :(因为我喜欢徒步)
1
2
3
4
5
6
7
8
DROP TABLE IF EXISTS  `city`;
CREATE TABLE `city` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '城市编号',
  `province_id` int(10) unsigned  NOT NULL COMMENT '省份编号',
  `city_name` varchar(25) DEFAULT NULL COMMENT '城市名称',
  `description` varchar(25) DEFAULT NULL COMMENT '描述',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
c.插入数据
1
INSERT city VALUES (1 ,1,'温岭市','BYSocket 的家在温岭。');
d.本地安装 Redis
详见写过的文章《 Redis 安装 》http://www.bysocket.com/?p=917
2. springboot-mybatis-redis 工程项目结构介绍
1
2
3
4
5
6
7
springboot-mybatis-redis 工程项目结构如下图所示:
org.spring.springboot.controller - Controller 层
org.spring.springboot.dao - 数据操作层 DAO
org.spring.springboot.domain - 实体类
org.spring.springboot.service - 业务逻辑层
Application - 应用启动类
application.properties - 应用配置文件,应用启动会自动读取配置
3.改数据库配置
打开 application.properties 文件, 修改相应的数据源配置,比如数据源地址、账号、密码等。
(如果不是用 MySQL,自行添加连接驱动 pom,然后修改驱动名配置。)
4.编译工程
在项目根目录 springboot-learning-example,运行 maven 指令:
1
mvn clean install
5.运行工程
右键运行 springboot-mybatis-redis 工程 Application 应用启动类的 main 函数。
项目运行成功后,这是个 HTTP OVER JSON 服务项目。所以用 postman 工具可以如下操作
根据 ID,获取城市信息
GET http://127.0.0.1:8080/api/city/1
再请求一次,获取城市信息会发现数据获取的耗时快了很多。服务端 Console 输出的日志:
1
2
2017-04-13 18:29:00.273  INFO 13038 --- [nio-8080-exec-1] o.s.s.service.impl.CityServiceImpl       : CityServiceImpl.findCityById() : 城市插入缓存 >> City{id=12, provinceId=3, cityName='三亚', description='水好,天蓝'}
2017-04-13 18:29:03.145  INFO 13038 --- [nio-8080-exec-2] o.s.s.service.impl.CityServiceImpl       : CityServiceImpl.findCityById() : 从缓存中获取了城市 >> City{id=12, provinceId=3, cityName='三亚', description='水好,天蓝'}
可见,第一次是从数据库 DB 获取数据,并插入缓存,第二次直接从缓存中取。
更新城市信息
PUT http://127.0.0.1:8080/api/city
删除城市信息
DELETE http://127.0.0.1:8080/api/city/2
这两种操作中,如果缓存有对应的数据,则删除缓存。服务端 Console 输出的日志:
1
2017-04-13 18:29:52.248  INFO 13038 --- [nio-8080-exec-9] o.s.s.service.impl.CityServiceImpl       : CityServiceImpl.deleteCity() : 从缓存中删除城市 ID >> 12

四、springboot-mybatis-redis 工程代码配置详解

这里,我强烈推荐 注解 的方式实现对象的缓存。但是这里为了更好说明缓存更新策略。下面讲讲工程代码的实现。
pom.xml 依赖配置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>springboot</groupId>
    <artifactId>springboot-mybatis-redis</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>springboot-mybatis-redis :: 整合 Mybatis 并使用 Redis 作为缓存</name>
    <!-- Spring Boot 启动父依赖 -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.1.RELEASE</version>
    </parent>
    <properties>
        <mybatis-spring-boot>1.2.0</mybatis-spring-boot>
        <mysql-connector>5.1.39</mysql-connector>
        <spring-boot-starter-redis-version>1.3.2.RELEASE</spring-boot-starter-redis-version>
    </properties>
    <dependencies>
        <!-- Spring Boot Reids 依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-redis</artifactId>
            <version>${spring-boot-starter-redis-version}</version>
        </dependency>
        <!-- Spring Boot Web 依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- Spring Boot Test 依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- Spring Boot Mybatis 依赖 -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>${mybatis-spring-boot}</version>
        </dependency>
        <!-- MySQL 连接驱动依赖 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql-connector}</version>
        </dependency>
        <!-- Junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
    </dependencies>
</project>
包括了 Spring Boot Reids 依赖、 MySQL 依赖和 Mybatis 依赖。
在 application.properties 应用配置文件,增加 Redis 相关配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
## 数据源配置
spring.datasource.url=jdbc:mysql://localhost:3306/springbootdb?useUnicode=true&characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
## Mybatis 配置
mybatis.typeAliasesPackage=org.spring.springboot.domain
mybatis.mapperLocations=classpath:mapper/*.xml
## Redis 配置
## Redis数据库索引(默认为0)
spring.redis.database=0
## Redis服务器地址
spring.redis.host=127.0.0.1
## Redis服务器连接端口
spring.redis.port=6379
## Redis服务器连接密码(默认为空)
spring.redis.password=
## 连接池最大连接数(使用负值表示没有限制)
spring.redis.pool.max-active=8
## 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.pool.max-wait=-1
## 连接池中的最大空闲连接
spring.redis.pool.max-idle=8
## 连接池中的最小空闲连接
spring.redis.pool.min-idle=0
## 连接超时时间(毫秒)
spring.redis.timeout=0
详细解释可以参考注释。对应的配置类:org.springframework.boot.autoconfigure.data.redis.RedisProperties
CityRestController 控制层依旧是 Restful 风格的,详情可以参考《Springboot 实现 Restful 服务,基于 HTTP / JSON 传输》。 http://www.bysocket.com/?p=1627 domain 对象 City 必须实现序列化,因为需要将对象序列化后存储到 Redis。如果没实现 Serializable ,控制台会爆出以下异常:
1
2
Serializable
java.lang.IllegalArgumentException: DefaultSerializer requires a Serializable payload but received an object of type
City.java 城市对象:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package org.spring.springboot.domain;
import java.io.Serializable;
/**
 * 城市实体类
 *
 * Created by bysocket on 07/02/2017.
 */
public class City implements Serializable {
    private static final long serialVersionUID = -1L;
    /**
     * 城市编号
     */
    private Long id;
    /**
     * 省份编号
     */
    private Long provinceId;
    /**
     * 城市名称
     */
    private String cityName;
    /**
     * 描述
     */
    private String description;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public Long getProvinceId() {
        return provinceId;
    }
    public void setProvinceId(Long provinceId) {
        this.provinceId = provinceId;
    }
    public String getCityName() {
        return cityName;
    }
    public void setCityName(String cityName) {
        this.cityName = cityName;
    }
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    @Override
    public String toString() {
        return "City{" +
                "id=" + id +
                ", provinceId=" + provinceId +
                ", cityName='" + cityName + '\'' +
                ", description='" + description + '\'' +
                '}';
    }
}
如果需要自定义序列化实现,只要实现 RedisSerializer 接口去实现即可,然后在使用 RedisTemplate.setValueSerializer 方法去设置你实现的序列化实现。
主要还是城市业务逻辑实现类 CityServiceImpl.java:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package org.spring.springboot.service.impl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spring.springboot.dao.CityDao;
import org.spring.springboot.domain.City;
import org.spring.springboot.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
 * 城市业务逻辑实现类
 * <p>
 * Created by bysocket on 07/02/2017.
 */
@Service
public class CityServiceImpl implements CityService {
    private static final Logger LOGGER = LoggerFactory.getLogger(CityServiceImpl.class);
    @Autowired
    private CityDao cityDao;
    @Autowired
    private RedisTemplate redisTemplate;
    /**
     * 获取城市逻辑:
     * 如果缓存存在,从缓存中获取城市信息
     * 如果缓存不存在,从 DB 中获取城市信息,然后插入缓存
     */
    public City findCityById(Long id) {
        // 从缓存中获取城市信息
        String key = "city_" + id;
        ValueOperations<String, City> operations = redisTemplate.opsForValue();
        // 缓存存在
        boolean hasKey = redisTemplate.hasKey(key);
        if (hasKey) {
            City city = operations.get(key);
            LOGGER.info("CityServiceImpl.findCityById() : 从缓存中获取了城市 >> " + city.toString());
            return city;
        }
        // 从 DB 中获取城市信息
        City city = cityDao.findById(id);
        // 插入缓存
        operations.set(key, city, 10, TimeUnit.SECONDS);
        LOGGER.info("CityServiceImpl.findCityById() : 城市插入缓存 >> " + city.toString());
        return city;
    }
    @Override
    public Long saveCity(City city) {
        return cityDao.saveCity(city);
    }
    /**
     * 更新城市逻辑:
     * 如果缓存存在,删除
     * 如果缓存不存在,不操作
     */
    @Override
    public Long updateCity(City city) {
        Long ret = cityDao.updateCity(city);
        // 缓存存在,删除缓存
        String key = "city_" + city.getId();
        boolean hasKey = redisTemplate.hasKey(key);
        if (hasKey) {
            redisTemplate.delete(key);
            LOGGER.info("CityServiceImpl.updateCity() : 从缓存中删除城市 >> " + city.toString());
        }
        return ret;
    }
    @Override
    public Long deleteCity(Long id) {
        Long ret = cityDao.deleteCity(id);
        // 缓存存在,删除缓存
        String key = "city_" + id;
        boolean hasKey = redisTemplate.hasKey(key);
        if (hasKey) {
            redisTemplate.delete(key);
            LOGGER.info("CityServiceImpl.deleteCity() : 从缓存中删除城市 ID >> " + id);
        }
        return ret;
    }
}
首先这里注入了 RedisTemplate 对象。联想到 Spring 的 JdbcTemplate ,RedisTemplate 封装了 RedisConnection,具有连接管理,序列化和 Redis 操作等功能。还有针对 String 的支持对象 StringRedisTemplate。
Redis 操作视图接口类用的是 ValueOperations,对应的是 Redis String/Value 操作。还有其他的操作视图,ListOperations、SetOperations、ZSetOperations 和 HashOperations 。ValueOperations 插入缓存是可以设置失效时间,这里设置的失效时间是 10 s。
回到更新缓存的逻辑
a. findCityById 获取城市逻辑:
如果缓存存在,从缓存中获取城市信息
如果缓存不存在,从 DB 中获取城市信息,然后插入缓存
b. deleteCity 删除 / updateCity 更新城市逻辑:
如果缓存存在,删除
如果缓存不存在,不操作
其他不明白的,可以 git clone 下载工程 springboot-learning-example ,工程代码注解很详细。 https://github.com/JeffLi1993/springboot-learning-example。

五、小结

本文涉及到 Spring Boot 在使用 Redis 缓存时,一个是缓存对象需要序列化,二个是缓存更新策略是如何的。

转载于:https://www.cnblogs.com/Soy-technology/p/11025089.html

相关文章:

Sqlite3支持的数据类型 日期函数 Sqlite3 函数

Sqlite3支持的数据类型 NULL INTEGER REAL TEXT BLOB 但实际上&#xff0c;sqlite3也接受如下的数据类型&#xff1a; smallint 16 位元的整数。 interger 32 位元的整数。 decimal(p,s) p 精确值和 s 大小的十进位整数&#xff0c;精确值p是指全部有几个数(digits)大小值&…

Element el-switch 组件样式修改 将文字显示到组件内

Element el-switch 现在的样式无法将文字显示到组件内 &#xff0c;需要自己修改样式。具体如下 <el-switch:disabled"sitem.select.length-1"class"switch"v-model"sitem.or"active-color"#13ce66"inactive-color"#409EFF&qu…

jquery中输入验证中一个不错的效果

在表单的输入验证中&#xff0c;经常要当用户没能正确输入后&#xff0c;要提示“XXXX输入错误”这一类的信息&#xff0c;如何能搞到动态一点呢&#xff0c;今天发现jquery中的一个不错的效果&#xff0c;笔记之。 1 包含jquery <script src"images/jquery-1.2.6.min…

【2018.2.25】c++预习练习

学了一学期c语言之后预习c&#xff0c;一些最基础的东西做起来还是得心应手的&#xff0c;先练练手感?C primer plus 和教材同步学习&#xff0c;大概会比上学期抓瞎学习要好得多吧。 1 #include<iostream>2 int main()3 {4 using namespace std;5 cout <<…

在做项目中遇到的JS问题

name和value&#xff1a; 例如: <input type"text" name"txt"/> name用于定义这个input收到的值的变量名&#xff0c;在上面的input输入“hello",那么就有txt"hello";用于dom操作取值 在用js改变某个div属性进行传值操作时&#xff0…

用Duplex实现消息广播

http://blog.csdn.net/fangxinggood/archive/2011/01/15/6142861.aspx WCF中定义3种消息交换模式&#xff1a; 1. Request/Reply; 2. One-Way; 3. Duplex。 Request/Reply 是缺省模式&#xff0c;即同步调用。在调用服务方法后需要等待服务的消息返回&#xff0c;即便该方法返…

mongoose手动生成ObjectId

如果需要手动生成使用mongoose.Types.ObjectId()方法。 var mongoose require(mongoose); var id mongoose.Types.ObjectId();

Coolpad F61刷机解锁成功

这几天是高校开学的日子,各大运营商纷纷进驻校园,打出种种优惠,抢新鲜用户。 我一直觉得我现在的移动号码收费太贵,每个月不知不觉就是100多块,对我这个以公司为家(公司电话就是我的电话)的宅人而言,是有点夸张了。特别是和国外的运营商相比&#xff0c;如果你有朋友在国外&…

Django 数据库

一、操作数据库 Django配置连接数据库&#xff1a; 在操作数据库之前&#xff0c;首先先要连接数据库。这里我们以配置MySQL为例来讲解。Django连接数据库&#xff0c;不需要单独的创建一个连接对象。只需要在settings.py文件中做好数据库相关的配置就可以了。示例代码如下&…

MapReduce 中 UDF、UDAF、UDTF

UDF UDF只能实现一进一出的操作&#xff0c;如果需要实现多进一出&#xff0c;则需要实现UDAFUDF函数可以直接应用于select语句&#xff0c;对查询结构做格式化处理后&#xff0c;再输出内容 UDAF UDFA是用户自定义的聚类函数&#xff0c;是基于表的所有记录进行的计算操作 …

计算机网络面试知识总结1

1.TCP报头格式 TCP协议头至少20个字节 &#xff08;1&#xff09;源端口 16位&#xff0c;主要用于标志报文的返回地址&#xff0c;其中包含初始化通信的端口 &#xff08;2&#xff09;目的端口 16位&#xff0c;指明了要把数据传送到哪 &#xff08;3&#xff09;序列号 32位…

C# 导出到Excel (使用NPOI 1.2.4)

最近研究下用C#导出Excel。最后选择要用NPOI来导出。在网上看到了好多的教程啊。于是我兴奋的模仿起来了。先创建个空的excel试试吧。结果&#xff1a;提示无法将类型“NPOI.SS.UserModel.Sheet”隐式转换为“NPOI.HSSF.UserModel.HSSFSheet”。存在一个显式转换(是否缺少强制转…

Putty 工具 保存配置的 小技巧

用Putty 已经很长时间了&#xff0c;但一直被一个问题困扰&#xff0c;有时候是懒得去弄&#xff0c;反正也不怎么碍事&#xff0c;今天小研究了下&#xff0c;把这个问题解决了&#xff0c;心里也舒服了。 Putty是一个免费小巧的Win32平台下的telnet,rlogin和ssh客户端。 它的…

PyODPS 学习 实现查询数据 并更新数据

PyODPS是MaxCompute的Python版本的SDK&#xff0c;提供简单方便的Python编程接口。PyODPS支持类似Pandas的快速、灵活和富有表现力的数据结构。您可以通过PyODPS提供的DataFrame API使用Pandas的数据结果处理功能。本文用于帮助您快速开始使用PyODPS&#xff0c;并且能够用于实…

跟面向对象卯上了,看看ES6的“类”

上回我们说到ES5的面向对象&#xff0c;以及被大家公认的最佳的寄生组合式继承。时代在进步&#xff0c;在ES6中对于面向对象这个大boss理所应当地进行了一次大改&#xff0c;从原先那种比较长的写法转变为“小清新”写法。我们一起来看一下。 在ES6中是有类这个概念&#xff0…

JS数组去重精简版

看了很多人写的好几个去重方法&#xff0c;我在这里精简组合下&#xff0c;适用于已排序与未排序的数组。 废话不多说&#xff0c;上代码。 <!DOCTYPE html> <html><head><meta charset"utf-8"><title>数组去重</title></hea…

[Buzz.Today]2011.05.25

>> VMWare的Open Source Pass - CloudFoundry VMWare推出了开源Pass&#xff1a;CloudFoundary&#xff0c;但是现在只是支持少数几种语言与环境&#xff1a;Java Spring, ROR and Node.JS。。 Source Code on GitHub: https://github.com/cloudfoundry 随便瞄了两眼&…

NeHe OpenGL第三十九课:物理模拟

NeHe OpenGL第三十九课&#xff1a;物理模拟 物理模拟简介: 还记得高中的物理吧&#xff0c;直线运动&#xff0c;自由落体运动&#xff0c;弹簧。在这一课里&#xff0c;我们将创造这一切。 物理模拟介绍 如果你很熟悉物理规律&#xff0c;并且想实现它&#xff0c;这篇文章…

max(min)-device-width和max(min)-width的区别

max-device-width和max-width的区别表现在如下几个方面&#xff1a; 1. max-device-width是设备整个显示区域的宽度&#xff0c;例如&#xff0c;真实的设备屏幕宽度。 2. max-width是目标显示区域的宽度&#xff0c;例如&#xff0c;浏览器宽度。 3. 如果使用max-device-width…

一篇文看懂Hadoop

我们很荣幸能够见证Hadoop十年从无到有&#xff0c;再到称王。感动于技术的日新月异时&#xff0c;希望通过这篇内容深入解读Hadoop的昨天、今天和明天&#xff0c;憧憬下一个十年。 本文分为技术篇、产业篇、应用篇、展望篇四部分 技术篇 2006年项目成立的一开始&#xff0c;“…

MaxCompute动态更新表中某个(多个)字段的数据

功能 MaxCompute支持了delete、update功能&#xff0c;但当您需要使用多个insert、update、delete对目标表进行批量操作时&#xff0c;需要编写多条SQL语句&#xff0c;然后进行多次全表扫描才能完成操作。MaxCompute提供的merge into功能&#xff0c;只需要进行一次全表扫描操…

字符串数组的赋值

例如:main(){chars[30]; strcpy(s,"Good News!"); /*给数组赋字符串*/ }上面程序在编译时,遇到chars[30]这条语句时,编译程序会在内存的某处留出连续30个字节的区域, 并将第一个字节的地址赋给s。当遇到strcpy( strcpy 为TurboC2.0的函数)时, 首先在目标文件的某处建…

NetBeans使用介绍(五)

第9章 Swing菜单 Swing菜单是我们经常用到的一种控件&#xff0c;NetBeans对菜单进行了很好的封装&#xff0c;是我们应用起来非常方便。下面&#xff0c;我们就来简单的了解一下Swing菜单。 菜单&#xff1a;Jmenu 菜单项&#xff1a;JmenuItem 复选菜单项&#xff1a;JcheckB…

Pycharm中如何安装python库

1首先打开pycharm工具&#xff0c;选择File中的Setting选项&#xff0c;如下图所示 2在打开的setting界面中我们点击python的解释器&#xff0c;你会看到很多导入的第三方库&#xff0c;如下图所示&#xff0c;点击最右边的加号 3在弹出的available packages界面中&#xff0c;…

LINUX下SVN命令大全

1、将文件checkout到本地目录 svn checkout path&#xff08;path是服务器上的目录&#xff09;例如&#xff1a;svn checkout svn://192.168.1.1/pro/domain简写&#xff1a;svn co2、往版本库中添加新的文件 svn addfile例如&#xff1a;svn addtest.php(添加test.php)svn ad…

MaxCompute 多行数据合并为一行数据

SELECT class, wm_concat(distinct ,, name) FROM students GROUP BY class; 参考

python学习之循环语句的九九乘法表

while 语句的九九乘法表&#xff1a; ##九九乘法表#总共有九行# 每行中的列数&#xff0c;就是当前所处的行号#乘式的第一个数代表的是列&#xff0c;第二个数代表的是行row 1#行column 1#列while row < 9: while column < row: print(%d * %d %d, %(column…

影著协公布的使用费收取标准

网络&#xff1a;距首映两年内的电影基本使用费下限为10万元/部年。 网吧&#xff1a;每天的使用费为&#xff1a;电脑总量网吧每小时收费标准7.5%。 视频点播:基本使用费为每次点击的单价33.3%终端用户数10%。 飞机和火车&#xff1a;每年每部影片使用费为2500元~5万元。 轮船…

POJ.3207.Ikki's Story IV-Panda's Trick(2-SAT)

题目链接 \(Description\) 一个圆上顺序排列0,1,...,n-1共n个点&#xff0c;给出m条线段&#xff0c;线段可以从里面连也可以从外面连&#xff0c;问是否能满足所有线段不相交 \(Solution\) 把每条线段看做一个点&#xff0c;只有在圆外和在圆内两种情况&#xff0c;于是可以把…

sqlconnection,sqlcommand,SqlDataAdapter ,ExecuteNonQuery,ExecuteScalar

sqlconnection&#xff1a;表示 SQL Server 数据库的一个打开的连接。SqlConnection 对象表示与 SQL Server 数据源的一个唯一的会话。 在客户端/服务器数据库系统中&#xff0c;它等效于一个到服务器的网络连接。 SqlConnection 与 SqlDataAdapter 和 SqlCommand 一起使用&…