国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

Springboot整合Redis最簡(jiǎn)單例子分享

瀏覽:2日期:2023-04-19 09:38:19

1. 編寫目的

最簡(jiǎn)單的例子,Springboot整合Redis。

2. 詳細(xì)過程

pom 文件添加依賴

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-redis --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>

配置redis

編輯application.yml文件。

spring:redis:port: 6379host: 39.106.198.74### 如果有密碼需要添加password

編寫一個(gè)controller類

package cn.smileyan.shirodemo.controller;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.data.redis.core.StringRedisTemplate;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class RedisController { @Autowired private StringRedisTemplate stringRedisTemplate; @RequestMapping('/') private String hello() { stringRedisTemplate.opsForValue().set('hello','world'); return 'SUCCESS'; }}

測(cè)試

運(yùn)行項(xiàng)目,然后用瀏覽器打開localhost:8080/這個(gè)地址。

看到瀏覽器輸出SUCCESS后,使用Redis Desktop查看是否set成功。

Springboot整合Redis最簡(jiǎn)單例子分享

3. 總結(jié)

非常簡(jiǎn)單的例子,但還是記錄一下,在這個(gè)基礎(chǔ)上可以做很多事情,但是對(duì)于剛剛接觸的人來說,可能還是有用的。

以上這篇Springboot整合Redis最簡(jiǎn)單例子分享就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 永修县| 罗甸县| 繁峙县| 五大连池市| 萍乡市| 玉田县| 依安县| 上林县| 甘孜县| 齐齐哈尔市| 高青县| 保定市| 方山县| 石河子市| 雅安市| 鹿泉市| 龙游县| 钟山县| 昌平区| 巴彦县| 得荣县| 秭归县| 合川市| 武定县| 安西县| 武功县| 德庆县| 巴青县| 东莞市| 绍兴县| 海盐县| 高要市| 永嘉县| 图木舒克市| 景宁| 安吉县| 开封市| 青海省| 泽州县| 三明市| 吉安县|