摘要:相隔很久,我又回來了,獻(xiàn)上一篇整合的教程給新手看一下吧,技術(shù)點(diǎn)不怎么有,最簡單的配置,入手即用,那下面開始本章在我的上一篇文章為基礎(chǔ)繼續(xù)整合的,不知道的可以見我的整合整合下面開始引入依賴整合文件根據(jù)自己配置添加信息代碼,用戶
相隔很久,我又回來了,獻(xiàn)上一篇整合redis 的教程給新手看一下吧,技術(shù)點(diǎn)不怎么有,最簡單的配置,入手即用,那下面開始
本章在我的上一篇文章為基礎(chǔ)繼續(xù)整合的,不知道的可以見我的整合tkmapper
springboot整合tkmapper
1、下面開始引入pom依賴
org.springframework.boot spring-boot-starter-data-redis
2、yml文件根據(jù)自己配置添加redis信息
spring: redis: host: 127.0.0.1 database: 0 password: redis port: 6379 timeout: 60000
3、HelloController代碼,用戶訪問接口測試redis
package com.cxt.demo.controller; import com.cxt.demo.service.HelloService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * @author liBai * @Classname HelloController * @Description TODO * @Date 2019-06-02 10:49 */ @RestController @RequestMapping("/test") public class HelloController { @Autowired private HelloService helloService; @RequestMapping("/hello") public String hello(){ return helloService.sayHello(); } @RequestMapping("/get") public String getRedisInfo(){ return helloService.getRedisInfo(); } }
4、HelloService代碼
package com.cxt.demo.service; /** * @author liBai * @Classname HelloService * @Description TODO * @Date 2019-06-02 10:49 */ public interface HelloService { String sayHello(); String getRedisInfo(); }
impl
package com.cxt.demo.service.impl; import com.cxt.demo.bean.TestSys; import com.cxt.demo.dao.TestSysMapper; import com.cxt.demo.service.HelloService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import java.util.concurrent.TimeUnit; /** * @author liBai * @Classname HelloServiceImpl * @Description TODO * @Date 2019-06-02 10:50 */ @Service @Slf4j public class HelloServiceImpl implements HelloService { @Autowired private TestSysMapper testSysMapper; @Autowired private StringRedisTemplate redisTemplate; @Override public String sayHello() { TestSys testSys = testSysMapper.selectByPrimaryKey("1"); redisTemplate.opsForValue().set("testSys",testSys.toString(),10,TimeUnit.MINUTES); log.info("redis set value =" +testSys.toString()); return "redis set value success ,userName = "+testSys.getName(); } @Override public String getRedisInfo() { log.debug("redis get info {}",redisTemplate.opsForValue().get("testSys")); return redisTemplate.opsForValue().get("testSys"); } }
5、到這初級版本整合就可以使用了,正常項(xiàng)目中不可能這么簡單使用redis,畢竟redis的用處還是很強(qiáng)大的,例如單機(jī),集群,哨兵等,具體的配置就自己挖掘吧,或者繼續(xù)關(guān)注我后續(xù)的文章,下面就來演示一下這節(jié)的成果吧
瀏覽器訪問
http://localhost:8081/test/hello
上面已經(jīng)看到redis放入字符串已經(jīng)放進(jìn)去了,下面就拿出來試試吧
訪問
http://localhost:8081/test/get
到了這基本也就結(jié)束了, 有問題歡迎留言討論,如有錯誤請指出一起交流,謝謝!
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/77788.html
摘要:一在文件中引入二配置地址等配置數(shù)據(jù)庫索引默認(rèn)為服務(wù)器地址服務(wù)器連接端口服務(wù)器連接密碼默認(rèn)為空連接池最大連接數(shù)使用負(fù)值表示沒有限制連接池最大阻塞等待時間使用負(fù)值表示沒有限制連接池中的最大空閑連接連接池中的最小空閑連接連接超時時 一、在pom文件中引入redis org.springframework.boot spring-boot-starter-redis ...
摘要:引入了新的環(huán)境和概要信息,是一種更揭秘與實(shí)戰(zhàn)六消息隊(duì)列篇掘金本文,講解如何集成,實(shí)現(xiàn)消息隊(duì)列。博客地址揭秘與實(shí)戰(zhàn)二數(shù)據(jù)緩存篇掘金本文,講解如何集成,實(shí)現(xiàn)緩存。 Spring Boot 揭秘與實(shí)戰(zhàn)(九) 應(yīng)用監(jiān)控篇 - HTTP 健康監(jiān)控 - 掘金Health 信息是從 ApplicationContext 中所有的 HealthIndicator 的 Bean 中收集的, Spring...
閱讀 2054·2019-08-29 16:27
閱讀 1408·2019-08-29 16:14
閱讀 3415·2019-08-29 14:18
閱讀 3502·2019-08-29 13:56
閱讀 1294·2019-08-29 11:13
閱讀 2176·2019-08-28 18:19
閱讀 3490·2019-08-27 10:57
閱讀 2331·2019-08-26 11:39